So, after a lot of work in the wrong direction, I think I found only one reference that GC moves and creates a "dangling pointer"....
If you don't want to merge the automatic C code formatting (which would help collaboration,. IMHO), you can just fix the monitor.c file so NIO_Monitor_mark isn't empty, but rather:
static void NIO_Monitor_mark(struct NIO_Monitor *monitor)
{
rb_gc_mark(monitor->self); /* prevent GC.compact from moving the memory */
}
After fixing this one line, the tests don't crash on my computer.
P.S.
I was impressed reading through the code base. The code is clean and succinct.
I probably would have coded things way more complicated since I would have avoided any Ruby objects in the C layer and would have used local memory allocators for the C layer objects (so they have a separate memory address pool from the main allocator as well as more locality)...
So, after a lot of work in the wrong direction, I think I found only one reference that GC moves and creates a "dangling pointer"....
If you don't want to merge the automatic C code formatting (which would help collaboration,. IMHO), you can just fix the
monitor.c
file soNIO_Monitor_mark
isn't empty, but rather:After fixing this one line, the tests don't crash on my computer.
P.S.
I was impressed reading through the code base. The code is clean and succinct.
I probably would have coded things way more complicated since I would have avoided any Ruby objects in the C layer and would have used local memory allocators for the C layer objects (so they have a separate memory address pool from the main allocator as well as more locality)...
Maybe it's a good thing my long work was tossed in the bean, I actually finished adding a local memory allocator for the C layer in a different branch (enabled with
ENV['NIO_MEMORY_POOL'] = "1"
) 😅