Subject: Re: [ruby-ffi] ruby 1.9.1 crashing when executing callback |
From: Chuck Remes |
Date: 5/12/10 7:36 PM |
To: ruby-ffi@googlegroups.com |
That fixed the crashes with 1.9.1 but I am still seeing some odd behavior. It may be a bug on my side, so I'll play with it a while longer. Many thanks... cr On May 12, 2010, at 6:29 PM, Wayne Meissner wrote:
<cremes.devlist@mac.com> wrote:Can you build ffi from github and retry it on 1.9? I added special support for callbacks from non-ruby threads (only works on 1.9 though - 1.8 is completely screwed in that situation). JRuby has no problem, because upcalls from C -> java always check & attach a JVM context, and jruby automagically adopts threads it does not know about. On 13 May 2010 05:53, Chuck Remeshttp://gist.github.com/398987 I downloaded the ruby-1.9.1 source and poked through vm_eval.c which contains the vm_call0() function. There is a big switch statement in there that falls through to calling rb_bug(). This all occurs *only* when invoking the callback. The stack trace clearly shows it is invoking a block (rb_funcall2) from the FFI library. It crashes regardless of the contents of the block (empty, puts, nil, etc.). In 1.8.7 it crashes with a LocalJumpError somewhere else. When I disable the callback, there are no crashes under either MRI. Under JRuby, everything works fine. The callback is invoked successfully. I'm wondering if this is failing because the callback may be invoked by another native thread. The library being wrapped by FFI spawns many threads that do various background tasks; one of them is likely the invocation of the cleanup callback that is causing the crash. Are there any known issues with MRI, FFI and callbacks? crI'm starting to work with callbacks and have run into a consistent crasher. Take a look at the trace here: