jruby icon indicating copy to clipboard operation
jruby copied to clipboard

Fiddle::DLError: cannot find the function: RegQueryInfoKey()

Open HoneyryderChuck opened this issue 4 years ago • 15 comments

Environment Information

Provide at least:

  • jruby-head (jruby 9.4.0.0-SNAPSHOT (3.1.0) 2022-02-08 3562498c80 OpenJDK 64-Bit Server VM 25.322-b06 on 1.8.0_322-b06 +jit [mswin32-x86_64])
  • Microsoft Windows Server 2022 (10.0.20348)

This is a friendly heads-up about edge jruby on windows, which idnx tests against, and started failing, due to some missing expected API (RegQueryInfoKey()) when requiring win32ole.

HoneyryderChuck avatar Feb 18 '22 15:02 HoneyryderChuck

Ahh good old win32ole. We have not spent time maintaining that library for many years, and I'm sure there are methods missing.

Unfortunately I'm not sure when we will get around to this.

@enebo Perhaps after 9.4 we can pair up on some win32ole work.

headius avatar Mar 17 '22 07:03 headius

Also fails in https://github.com/ruby/jruby-dev-builder/runs/7060585691?check_suite_focus=true It seems to mean resolv.rb does not work on JRuby Windows, and neither net/http.

$ ruby -ropen-uri -e 'puts URI.send(:open, %{[https://rubygems.org/})](https://rubygems.org/%7D)) { |f| f.read(1024) }'
Fiddle::DLError: cannot find the function: RegQueryInfoKey()
   import_function at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/fiddle/import.rb:297
            extern at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/fiddle/import.rb:170
               API at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/registry.rb:243
              each at org/jruby/RubyArray.java:1988
      <module:API> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/registry.rb:242
  <class:Registry> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/registry.rb:226
    <module:Win32> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/registry.rb:74
            <main> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/registry.rb:4
           require at org/jruby/RubyKernel.java:1017
           require at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85
            <main> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/resolv.rb:7
           require at org/jruby/RubyKernel.java:1017
           require at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85
     <class:Hosts> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/resolv.rb:175
    <class:Resolv> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/resolv.rb:172
            <main> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/resolv.rb:38
           require at org/jruby/RubyKernel.java:1017
           require at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85
            <main> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/net/http.rb:25
           require at org/jruby/RubyKernel.java:1017
           require at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85
         open_http at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:268
       buffer_open at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:741
         open_loop at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:212
             catch at org/jruby/RubyKernel.java:1238
         open_loop at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:210
          open_uri at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:151
              open at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:721
              open at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:29
            <main> at -e:1

Was only noticed now due to https://github.com/jruby/jruby/issues/7182 hiding the error.

eregon avatar Jun 26 '22 12:06 eregon

The problem with RegQueryInfoKey seems to be that it simply does not exist. Like most of win32 APIs that deal with strings, this function is split into RegQueryInfoKeyW for wide strings and RegQueryInfoKeyA for 7-bit ASCII strings.

However... CRuby's binding of these same functions does not use the W, so something is happening there to route the bare name to the correct function.

headius avatar Aug 01 '22 15:08 headius

I found this issue in CRuby where they fixed two other functions to use W but not this one: https://bugs.ruby-lang.org/issues/10820

I have not yet figured out how CRuby locates the appropriate version of the function when it is clearly trying to import the bare name.

headius avatar Aug 01 '22 16:08 headius

My recommendation for now would be for us to add the W to the appropriate functions in registry.rb. Two are clearly supposed to be there, and the third probably should be there.

headius avatar Aug 01 '22 16:08 headius

I pushed #7281 to add W to the functions in question, and also added a comment on https://bugs.ruby-lang.org/issues/10820 asking why this change was not done for RegQueryInfoKey and also asking how CRuby manages to find a function when it is using the incorrect name.

I also pinged the Fiddle master, @tenderlove, to see if he has any information on how this function can possibly be binding.

headius avatar Aug 01 '22 16:08 headius

awesome, thx for following up 👏

HoneyryderChuck avatar Aug 01 '22 17:08 HoneyryderChuck

Just to follow up, I am very unfamiliar with the Windows side of things here. I don't have a Windows machine to test with, so any guidance from someone that knows better than me would be appreciated 🙇🏻‍♀️

tenderlove avatar Aug 03 '22 15:08 tenderlove

@HoneyryderChuck Are you able to test #7281 on Windows? I currently do not have access to a Windows machine (work machines in transition).

headius avatar Aug 03 '22 15:08 headius

I have gone ahead with merging the "W" change in #7281. This should be fixed now and will be released in 9.3.7.0.

headius avatar Aug 03 '22 16:08 headius

Thanks, that fixes it for setup-ruby on GitHub Actions.

eregon avatar Aug 06 '22 11:08 eregon

I spoke too soon, it still fails for jruby-head: https://github.com/ruby/jruby-dev-builder/runs/7697355232?check_suite_focus=true

I think it's simply because https://github.com/jruby/jruby/pull/7281 wasn't merged to master, only to jruby-9.3

eregon avatar Aug 06 '22 14:08 eregon

I ported the fix to master: 58fffdfe1dd2babf913352159c8788fb7183a7f8

eregon avatar Aug 06 '22 14:08 eregon

This still doesn't work on master, probably it needs more fixes: https://github.com/ruby/jruby-dev-builder/runs/7715080311?check_suite_focus=true

Run ruby -ropen-uri -e 'puts URI.send(:open, %{[https://rubygems.org/})](https://rubygems.org/%7D)) { |f| f.read(1024) }'
ArgumentError: cannot convert parameter to native pointer
         OpenKey at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/registry.rb:289
            open at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/registry.rb:431
            open at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/registry.rb:542
   get_hosts_dir at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/resolv.rb:142
  get_hosts_path at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/win32/resolv.rb:15
   <class:Hosts> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/resolv.rb:176
  <class:Resolv> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/resolv.rb:172
          <main> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/resolv.rb:38
         require at org/jruby/RubyKernel.java:1018
         require at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85
          <main> at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/net/http.rb:25
         require at org/jruby/RubyKernel.java:1018
         require at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85
       open_http at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:268
     buffer_open at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:741
       open_loop at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:212
           catch at org/jruby/RubyKernel.java:1239
       open_loop at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:210
        open_uri at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:151
            open at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:721
            open at D:/a/jruby-dev-builder/jruby-dev-builder/jruby-head/lib/ruby/stdlib/open-uri.rb:29
          <main> at -e:1

eregon avatar Aug 08 '22 09:08 eregon

@headius @enebo Could you take another look at this? It means jruby-head is very outdated due to this issue (failing since April 27).

eregon avatar Aug 10 '22 09:08 eregon

The new issue looks different but I'll have a look.

headius avatar Aug 12 '22 17:08 headius

I think the new issue is not directly related to this one, so I'm closing this again.

The new issue has probably always existed: our Fiddle implementation does not properly handle converting parameters to the appropriate target type on the function signature, due to it being a very thin shim over FFI. It was not observed before because our registry.rb used our FFI-based win32api, but that changed as part of updating to 3.1 and it now attempts to use Fiddle.

I will open a separate issue.

headius avatar Aug 12 '22 22:08 headius