Repository navigation
Arrays in a C struct #33
Description
Activity
Yes, that would be great!
Just one warning: we use a quite old version of the readstat lib. I've started work to get us up to speed with the latest version by using BinaryBuilder and compiling a new version, but that is not done yet. I'm not sure whether there are any changes to these types upstream, but just something to keep in mind.
I looked at the main repo and it seems that they have changed that struct quite a few times so if we really want to match it in Julia, we'd have to be careful with checking the version of the linked library. However, there are quite a few getter functions defined so it is safer and simpler to just rely on them instead of trying to match the struct in Julia.
So that maybe suggests that we don't even need to define these structs at all, but can just pass a pointer around and then use the getter functions to access things, right? That seems an all around safer approach.
@davidanthoff Yes. I think it will be safer overall to use the getter functions and not try to emulate the C structs. I am working on a PR.
Reacted by David AnthoffI was wrong about passing
readstat_value_tas an opaque pointer. It is passed by value in the C code so there must be a Julia struct likeReadStatValue, which must have the right size, as you have ensured.Well, I didn't write any of this code ;) This julia package was original created by Evan Miller, who is the creator for the ReadStat C library. He is no longer interested in maintaining the julia package, so he transferred the repo over to me because I had helped out getting it to run on Windows a while back. So really he deserves the credit for any of this here.
@davidanthoff Would you be willing to transfer ownership to the
JuliaDatagroup?I'm happy to keep maintaining it. I like the model where someone is on the hook if things don't work, and for now I'm happy to be that person ;) If I run out of time to do that, we could move it over.
I noticed in reading the code that the Julia struct
does not align with the C declaration in
readstat,hThe problem is that the fixed-size
chararrays, likenamedo not correspond toPtr{UInt8}orCstringin Julia. If you want the structs to align in memory you need to insert a Julia struct that has the correct width. TheClangpackage at one time did this by creating a Juliastructwith 256UInt8fields and inserting that as thenamefield. However, that approach is rather tedious.In this case there is no need to define the Julia struct because the memory is allocated in the C code and passed by reference. I can prepare a PR if you wish.