Project

General

Profile

Actions

Bug #18472

open

rb_w32_map_errno is not found on Ruby-3.1.0

Added by joker1007 (Tomohiro Hashidate) 11 months ago. Updated 11 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt]
[ruby-dev:51132]

Description

I faced Fiddle::DLError such following.

C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/3.1.0/fiddle/import.rb:297:in `import_function': cannot find the function: rb_w32_map_errno() (Fiddle::DLError)
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/3.1.0/fiddle/import.rb:170:in `extern'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/winsock.rb:112:in `<module:RbWinSock>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/winsock.rb:97:in `<module:ServerEngine>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/winsock.rb:18:in `<top (required)>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/socket_manager_win.rb:21:in `require_relative'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/socket_manager_win.rb:21:in `<top (required)>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/socket_manager.rb:222:in `require_relative'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/socket_manager.rb:222:in `<module:SocketManager>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/socket_manager.rb:26:in `<module:ServerEngine>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/socket_manager.rb:25:in `<top (required)>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/process_manager.rb:19:in `require'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/process_manager.rb:19:in `<top (required)>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/supervisor.rb:20:in `require'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/supervisor.rb:20:in `<top (required)>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/daemon.rb:21:in `require'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine/daemon.rb:21:in `<top (required)>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine.rb:26:in `require'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine.rb:26:in `<module:ServerEngine>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/serverengine-2.2.4/lib/serverengine.rb:18:in `<top (required)>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/fluentd-1.14.4/lib/fluent/test/log.rb:17:in `require'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/fluentd-1.14.4/lib/fluent/test/log.rb:17:in `<top (required)>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/fluentd-1.14.4/lib/fluent/test.rb:19:in `require'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/fluentd-1.14.4/lib/fluent/test.rb:19:in `<top (required)>'
	from D:/a/fluent-plugin-bigquery/fluent-plugin-bigquery/test/helper.rb:6:in `require'
	from D:/a/fluent-plugin-bigquery/fluent-plugin-bigquery/test/helper.rb:6:in `<top (required)>'
	from D:/a/fluent-plugin-bigquery/fluent-plugin-bigquery/test/plugin/test_out_bigquery_base.rb:1:in `require'
	from D:/a/fluent-plugin-bigquery/fluent-plugin-bigquery/test/plugin/test_out_bigquery_base.rb:1:in `<top (required)>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in `require'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in `block in <main>'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `select'
	from C:/hostedtoolcache/windows/Ruby/3.1.0/x64/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `<main>'
rake aborted!

The cause code is here. (https://github.com/treasure-data/serverengine/blob/4d6dbd3d1b4e1af88cc2593b5b19cf0f6da7d5dd/lib/serverengine/winsock.rb#L112)

  module RbWinSock
    extend Fiddle::Importer

    dlload "kernel32"
    extern "int GetModuleFileNameA(int, char *, int)"
    extern "int CloseHandle(int)"

    ruby_bin_path_buf = Fiddle::Pointer.malloc(1000)
    GetModuleFileNameA(0, ruby_bin_path_buf, ruby_bin_path_buf.size)

    ruby_bin_path = ruby_bin_path_buf.to_s.gsub(/\\/, '/')
    ruby_dll_paths = File.dirname(ruby_bin_path) + '/*msvcr*ruby*.dll'
    ruby_dll_path = Dir.glob(ruby_dll_paths).first
    dlload ruby_dll_path

    extern "int rb_w32_map_errno(int)"

On 3.0.x, this test is passed.

Moreover, I don't find any changes about rb_w32_map_errno from 3.0.3 to 3.1.0.

It is strange behavior. It may be a bug in Ruby-3.1.0

Environment

I apologize for the lack of research, as I do not have a Windows environment.

Actions #1

Updated by joker1007 (Tomohiro Hashidate) 11 months ago

  • Subject changed from rb_w32_map_errno does not found on Ruby-3.1.0 to rb_w32_map_errno is not found on Ruby-3.1.0

Updated by kubo (Takehiro Kubo) 11 months ago

It is because of a change in rubyinstaller-3.1.0-x64.

In https://rubyinstaller.org/2021/12/31/rubyinstaller-3.1.0-1-released.html:

RubyInstaller-3.1.0-x64 has a changed C-runtime called UCRT replacing the old MSVCRT.

I guess that ruby_dll_path is nil because *msvcr*ruby*.dll doesn't exist in the bin directory.

rubyinstaller-3.1.0-x64: x64-ucrt-ruby310.dll
rubyinstaller-3.0.0-x64: x64-msvcrt-ruby300.dll
rubyinstaller-3.1.0-x86: msvcrt-ruby310.dll
rubyinstaller-3.0.0-x86: msvcrt-ruby300.dll

How about the following code?

  module RbWinSock
    extend Fiddle::Importer

    dlload "kernel32"
    extern "int CloseHandle(int)"

    require 'rbconfig'
    dlload RbConfig::CONFIG['LIBRUBY_SO']
    extern "int rb_w32_map_errno(int)"

Updated by kubo (Takehiro Kubo) 11 months ago

The error itself was fixed by https://github.com/treasure-data/serverengine/pull/116#issuecomment-1011931598.
There is another error in serverengine using ruby 3.1 but it is unrelated to this issue.

Updated by ashie (Takuro Ashie) 11 months ago

I've released a fixed version of serverengine: https://rubygems.org/gems/serverengine/versions/2.2.5
Thanks for your report!

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0