Skip to content

Commit 0631d46

Browse files
committed
Simplify coercion logic in Fiddle::Function#call
* The issue is Fiddle structs have #to_ptr returning a CStructEntity and not a FFI::Pointer. So both Fiddle and FFI use #to_ptr and we need explicit coercion.
1 parent 418bd89 commit 0631d46

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/fiddle/jruby.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def initialize(ptr, args, return_type, abi = DEFAULT, kwargs = nil)
149149
end
150150
end
151151

152-
def call(*args, &block);
152+
def call(*args, &block)
153153
if @function.is_a?(FFI::VariadicInvoker)
154154
n_fixed_args = @args.size - 1
155155
n_fixed_args.step(args.size - 1, 2) do |i|
@@ -159,15 +159,15 @@ def call(*args, &block);
159159
args[i] = Fiddle::JRuby.__ffi_type__(args[i])
160160
end
161161
else
162-
args.size.times do |i|
163-
arg = args[i]
164-
next unless arg.respond_to?(:to_ptr)
165-
loop do
166-
arg = arg.to_ptr
167-
break if arg.is_a?(FFI::Pointer)
168-
break unless arg.respond_to?(:to_ptr)
162+
args.map! do |arg|
163+
if arg.respond_to?(:to_ptr)
164+
begin
165+
arg = arg.to_ptr
166+
end until arg.is_a?(FFI::Pointer) || !arg.respond_to?(:to_ptr)
167+
arg
168+
else
169+
arg
169170
end
170-
args[i] = arg
171171
end
172172
end
173173
result = @function.call(*args, &block)

0 commit comments

Comments
 (0)