Skip to content

Fiddle implementation on FFI does not properly handle type conversions #7307

@headius

Description

@headius

As part of investigating #7106 we ran into a new issue where a call to one of the registry functions in registry.rb produced the following trace:

>bin\jruby -e "require 'resolv'"
ArgumentError: cannot convert parameter to native pointer
         OpenKey at C:/Users/User/jruby/lib/ruby/stdlib/win32/registry.rb:289
            open at C:/Users/User/jruby/lib/ruby/stdlib/win32/registry.rb:431
            open at C:/Users/User/jruby/lib/ruby/stdlib/win32/registry.rb:542
   get_hosts_dir at C:/Users/User/jruby/lib/ruby/stdlib/win32/resolv.rb:142
  get_hosts_path at C:/Users/User/jruby/lib/ruby/stdlib/win32/resolv.rb:15
   <class:Hosts> at C:/Users/User/jruby/lib/ruby/stdlib/resolv.rb:176
  <class:Resolv> at C:/Users/User/jruby/lib/ruby/stdlib/resolv.rb:172
          <main> at C:/Users/User/jruby/lib/ruby/stdlib/resolv.rb:38
         require at org/jruby/RubyKernel.java:1018
         require at C:/Users/User/jruby/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85
          <main> at -e:1

The issue here appears to stem from the fact that our Fiddle implementation is just a thin shim over FFI, and while the latter requires more exact parameter types (e.g. Pointer instances for :pointer args), the former appears to either be looser about these requirements or better at making conversions.

This was not observed in the past due to registry.rb using our FFI-based win32api. When it was upgraded to use Fiddle as part of 3.0/3.1 updates in JRuby 9.4, the breakage was exposed.

This is not the first problem of its type in Fiddle, and the best fix would be to reimplement fiddle, either as a standalone library atop our Java FFI layer JNR, or as a better wrapper around Ruby FFI.

I will file a separate issue for the registry.rb issues, which keep networking from functioning properly on Windows.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions