Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/fiddle/ffi_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ def initialize(ret, args, abi = Function::DEFAULT)
end
return_type = Fiddle::FFIBackend.to_ffi_type(@ctype)
raise "#{self.class} must implement #call" unless respond_to?(:call)
callable = method(:call)
@function = FFI::Function.new(return_type, ffi_args, callable, convention: abi)
wrapper = lambda do |*args|
call(*args.map { |v| v.is_a?(FFI::Pointer) ? Pointer.new(v) : v })
end
@function = FFI::Function.new(return_type, ffi_args, wrapper, convention: abi)
@freed = false
end

Expand Down
14 changes: 14 additions & 0 deletions test/fiddle/test_closure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ def call(bool)
end
end

def test_pointer
closure_class = Class.new(Closure) do
def call(ptr)
ptr.is_a?(Pointer)
end
end
closure_class.create(:bool, [:voidp]) do |closure|
func = Function.new(closure, [:voidp], :bool)
assert do
func.call(Pointer["hello"])
end
end
end

def test_free
closure_class = Class.new(Closure) do
def call
Expand Down
Loading