Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no TypeError when use FFI callback with invalid return type #3003

Open
testors opened this issue May 29, 2015 · 0 comments
Open

no TypeError when use FFI callback with invalid return type #3003

testors opened this issue May 29, 2015 · 0 comments

Comments

@testors
Copy link

testors commented May 29, 2015

test.c

typedef int (*callback)();

void test( callback v )
{
  int i = v();
}

test.rb

require 'ffi'

module MYFFI
  extend FFI::Library
  ffi_lib './libtest.so'

  callback :callback, [:int], :int

  attach_function :test, [:callback], :void
end

def callback( v )
  return "string"
end

MYFFI.test( method( :callback ) )

how to reproduce :

[testors@macpro:~]$ gcc -c -fpic test.c
[testors@macpro:~]$ gcc -shared -o libtest.so test.o
[testors@macpro:~]$ jruby test.rb
(nothing happened)
[testors@macpro:~]$ 

expected result :

[testors@macpro:~]$ ruby test.rb
test.rb:16:in `test': no implicit conversion of String into Integer (TypeError)
    from test.rb:16:in `<main>'
[testors@macpro:~]$ rbx test.rb
An exception occurred running test.rb:

can't convert String into Integer (TypeError)

Backtrace:

                 Object#__script__ at test.rb:16
  Rubinius::CodeLoader#load_script at kernel/delta/code_loader.rb:66
  Rubinius::CodeLoader.load_script at kernel/delta/code_loader.rb:152
           Rubinius::Loader#script at kernel/loader.rb:656
             Rubinius::Loader#main at kernel/loader.rb:810

environment

[testors@macpro:~/tmp]$ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
[testors@macpro:~/tmp]$ rbx -v
rubinius 2.5.5.c10 (2.1.0 a0f2fa58 2015-05-17 3.3 JI) [x86_64-darwin14.1.0]
[testors@macpro:~/tmp]$ jruby -v
jruby 9.0.0.0.pre2 (2.2.2) 2015-04-28 2755ae0 Java HotSpot(TM) 64-Bit Server VM 25.5-b02 on 1.8.0_05-b13 +jit [darwin-x86_64]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants