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

Closures cannot accept arguments of TYPE_CONST_STRING #62

Closed
codykrieger opened this issue Dec 24, 2020 · 4 comments
Closed

Closures cannot accept arguments of TYPE_CONST_STRING #62

codykrieger opened this issue Dec 24, 2020 · 4 comments

Comments

@codykrieger
Copy link

When attempting to invoke a closure with an argument of Fiddle::TYPE_CONST_STRING, I get this error:

test.rb:43:in `call': closure args: 10 (RuntimeError)

That's coming from here:

rb_raise(rb_eRuntimeError, "closure args: %d", type);

It appears that the switch in with_gvl_callback() doesn't handle TYPE_CONST_STRING.

@kou
Copy link
Member

kou commented Dec 24, 2020

Could you show a Ruby script that reproduces this case?

@codykrieger
Copy link
Author

Sure.

test.rb:

require 'fiddle'
require 'fiddle/import'

module MyModule
  extend Fiddle::Importer

  MyType = struct [
    %q{void (*foo)(const char *value)}
  ]
end

closure = Class.new(Fiddle::Closure) {
  def call(value)
    puts "value! #{value}"
  end
}.new(Fiddle::TYPE_VOID, [Fiddle::TYPE_CONST_STRING])

my_type = MyModule::MyType.malloc
my_type.foo = closure

# ...

fn = Fiddle::Function.new my_type.foo, [Fiddle::TYPE_CONST_STRING], Fiddle::TYPE_VOID
fn.call "bar"

Then:

% ruby test.rb
Traceback (most recent call last):
        1: from test.rb:24:in `<main>'
test.rb:24:in `call': closure args: 10 (RuntimeError)

It seems like the behavior is specific to when closures are wrapped in a Function.

@kou kou closed this as completed in 284b820 Dec 24, 2020
@kou
Copy link
Member

kou commented Dec 24, 2020

Thanks.
I've implemented.

@codykrieger
Copy link
Author

Thanks @kou!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants