Skip to content

FFI crashes when callback is not the last parameter #817

Closed
lyro opened this Issue Apr 12, 2011 · 1 comment

2 participants

@lyro
lyro commented Apr 12, 2011

When passing a callback to an ffi-bound function and this callback is not the last parameter, rubinius crashs when passing the callback, even if the callback itself is never called. Example:

The C-code:

/* mytest.c */
typedef void (*callback)();
void function(callback cb, int x) { }

and the ruby-code:

# test.rb
require 'ffi'

module Lib
    extend FFI::Library
    ffi_lib "./mytest.so"

    callback :test_callback, [], :void
    attach_function :function, [:test_callback, :int], :void
end

p = Proc.new{}
Lib::function(p, 42)

And rubinius crashes:

% ruby test.rb

Rubinius Crash Report #rbxcrashreport

Error: signal SIGSEGV

[[Backtrace]]
ruby[0x818c268]
[0xffffe400]
ruby(ZN8rubinius14NativeFunction12adjust_trampEPNS_2VMEPNS_6ObjectEPS0+0x58)[0x82999c8]
ruby(_ZN8rubinius14NativeFunction4callEPNS_2VMERNS_9ArgumentsERNS_8DispatchEPNS_9CallFrameE+0xbeb)[0x829a71b]
ruby(_ZN8rubinius14NativeFunction7executeEPNS_2VMEPNS_9CallFrameERNS_8DispatchERNS_9ArgumentsE+0xa1)[0x829ae91]
...

Note that everything works fine if the second parameter int x is dropped

@dbussink
Rubinius member

This should have been fixed by @jeremyz

@dbussink dbussink closed this Apr 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.