jruby / jruby

JRuby, an implementation of Ruby on the JVM

Home Page:https://www.jruby.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

HoneyryderChuck opened this issue · comments

commented

Environment Information

Provide at least:

  • jruby-head (jruby 9.4.0.0-SNAPSHOT (3.1.0) 2022-02-08 3562498 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.

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.

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 #7182 hiding the error.

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.

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.

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.

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.

commented

awesome, thx for following up 👏

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 🙇🏻‍♀️

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

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.

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

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 #7281 wasn't merged to master, only to jruby-9.3

I ported the fix to master: 58fffdf

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

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

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

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.