This question is a followup to Julia - C interface with nonfundamental types, with enough new information to be considered a different question. I use a C library that has two types like this, with three possible versions of mystruct:
struct contained {
int x;
int y;
int z;
};
struct mystruct {
int n;
//original:
// contained* arr;
//struct hack version 1:
// contained arr[1];
//struct hack version 2:
contained arr[];
};
Using the answer from the original question, I have defined the following corresponding Julia types, which work fine with the original version of mystruct, but not either version using the struct hack:
type contained
x::Cint
y::Cint
z::Cint
end
type mystruct
n::Cint
arr::Ptr{contained}
end
If I call a C function from Julia which returns a Ptr{mystruct} and save it as ms, I can put m = unsafe_load(ms) and see m.n and the pointer m.arr, but I can only check its values with unsafe_load(m.arr) in the original case. Otherwise unsafe_load(m.arr) causes a segfault. What is the right way in Julia to handle C structs containing variable length arrays defined in this fashion? I would use only the original definition of mystruct with contained *arr since it works as expected, but I need code that works for the other cases too.