I have C code that returns an array of struct using pointer:
mutable struct Result
value :: Cdouble
len_sequence :: Cint # length of sequence[]
sequence :: Ptr{Cint}
end
mutable struct ResultList
len_list :: Cint # length of list[]
list :: Ptr{Result}
end
Basically, ResultList
is a vector of Result
.
After ccall()
, I have result_list :: ResultList
on hand. The following works:
# result_list :: ResultList
for i in 1:result_list.len_list
result = unsafe_load(result_list.list, i) # result :: Result
seq = unsafe_wrap(Vector{Cint}, result.sequence, result.len_sequence) # seq :: Vector{Cint}
@show seq # works as intended
end
But the following produces segfault:
unsafe_wrap(Array, result_list.list, result_list.len_list)
What am I doing wrong? Is it not possible to use unsafe_wrap()
in this case?