The following code segfaults consistently after ~2.5M allocations. I previously had not GC_PUSH macros in place and didn’t save jl_value_t pointers as stack variables. I was advised to root the values, which is a term I do not quite understand. I added the garbage collector macros and nothing changed, I still get the same segmentation fault. Te segmentation fault does not occur if the while loop is commented out
I may be wrong, but I suspect that your GC protection comes too late; the value pointed to by fn might get garbage collected while you do jl_eval_string for arg1, and so on. Try
No, that case is fine. It’s not until you call into Julia again that garbage collection may happen. The problem comes when you compute your second jl_value_t without having protected the first value.