I am looking for some help with segfault when passing a struct to a C-API via `@cc

I am looking for some help with segfault when passing a struct to a C-API via @ccall. I created an immutable struct inside a Ref(), and then call something like @ccall lib.somefunc(myref::Ptr{MyStruct}).... This seems to work, but then when the Julia function returns I get an EXCEPTION_ACCESS_VIOLATION at 0x2a088a9 -- jl_gc_pool_alloc.

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

Solved by @mkitti
The struct I was passing in needed a buffer. I used a Julia array directly as a field in that struct, when in fact I needed to use pointer(array).
Thanks!

2 Likes