Closed hogelog closed 9 months ago
I think this PR would work as a workaround.
However, I thought this behavior of RubyGems' require might be a bug in RubyGems, so I suggested RubyGems to fix it as well. https://github.com/rubygems/rubygems/pull/7241
If the fixes https://github.com/rubygems/rubygems/pull/7241 are merged, the problem may not be apparent in Ruby 3.3 without applying this PR workaround.
Thanks. I have not enough time to review to https://github.com/rubygems/rubygems/pull/7241 for RubyGems 3.5.
I will merge this for Ruby 3.3.
Thanks for the review and merge!
I would like to suggest a fix because readline-ext loading is not working properly in non-Unix-like environments.
Why
The call
require "foo.so"
first calls therequire
overridden by RubyGems, which in turn calls ruby's nativerequire
. When ruby's nativerequire
loads "foo.so", it searches for the appropriate file for each environment, such as foo.so, foo.bundle, or foo.dll. However, RubyGems'srequire
tries to load "foo.so" and does not look for files like foo.bundle, foo.dll.So I have created this PR. With this change, the
require "readline"
call will load the native extension of the readline-ext gem.Behavior of existing implementation.
Environment with .so extension (e.g. Linux)
Existing implementations and this PR implementation work fine.
The call "readline.so" and the actual file name match.
Environment with bundler
If you run via Bundler in a Gemfile like the following, ruby add the path of the gem to LOAD_PATH, so even ruby native require can find the readline.{bundle,dll,...} and load it successfully.
Environment where the extention extension is not .so (e.g. macOS) with Ruby <= 3.2
Until Ruby 3.2, ext/readline was a standard library, so when you do `require "readline.so"', RubyGems's require cannot find readline.so and native require can find the readline extension (e.g. readline.bundle) of ext/readline. On the other hand, the readline extension of readline-ext is not used.
Environment where the extention extension is not .so (e.g. macOS) with Ruby 3.3
In Ruby 3.3, since ext/readline is retired, it will not find the readline native extension provided by the readline-ext gem and will fall back to loading relines.