Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix readline-ext gem loading in non Unix-like environments #6

Merged
merged 1 commit into from Dec 16, 2023

Conversation

hogelog
Copy link
Contributor

@hogelog hogelog commented Dec 7, 2023

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 the require overridden by RubyGems, which in turn calls ruby's native require.
When ruby's native require loads "foo.so", it searches for the appropriate file for each environment, such as foo.so, foo.bundle, or foo.dll.
However, RubyGems's require 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.

source "https://rubygems.org"

gem "readline-ext"

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.

@hogelog
Copy link
Contributor Author

hogelog commented Dec 9, 2023

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.
rubygems/rubygems#7241

If the fixes rubygems/rubygems#7241 are merged, the problem may not be apparent in Ruby 3.3 without applying this PR workaround.

@hsbt
Copy link
Member

hsbt commented Dec 16, 2023

Thanks. I have not enough time to review to rubygems/rubygems#7241 for RubyGems 3.5.

I will merge this for Ruby 3.3.

@hsbt hsbt merged commit f29fbfd into ruby:master Dec 16, 2023
@hogelog hogelog deleted the require-readline-ext-gem branch December 16, 2023 06:21
@hogelog
Copy link
Contributor Author

hogelog commented Dec 16, 2023

Thanks for the review and merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants