I can't help you at all, but I would like to ask if you pass 
the cfunction() result to the C side.
I've been playing with embedding Julia and discovered I could call 
a cfunction() directly  from C, although I'm not sure that's a good 
practice.

https://github.com/cdsousa/embedding_julia/blob/master/embedding.cpp#L40

On Wednesday, September 28, 2016 at 5:22:49 PM UTC+1, Christian Rorvik 
wrote:
>
> I'm not yet a 100% sure what is happening in my application, but I'm 
> embedding Julia and using cfunction() to generate C-callable functions that 
> at a later time invoke the registered julia code. I use a fairly standard 
> pattern I think, of passing a pointer to a julia object that is retain in C 
> and later passed down to the callback created by cfunction, and from there 
> resolved to the original real Julia reference type, invoking a closure. The 
> closure itself is retained in some global state to prevent garbage 
> collection. What appears to be happening however, is the code at the 
> landing site for the cfunction returned pointer is at some point garbage 
> collection (or at least corrupted), as my program, after a while of 
> running, will segfault upon invoking the callback (after many previously 
> successful callbacks). It segfaults because it hits invalid code, and it's 
> not that some state is missing when running the code.
>
> Is this to be be expected, and what's the right way to ensure the code 
> isn't GC'd?
>

Reply via email to