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

Workaround rubygems $LOAD_PATH bug #648

Merged
merged 5 commits into from
Oct 25, 2024

Conversation

casperisfine
Copy link

Ref: #647
Ref: rubygems/rubygems#6490

Older rubygems are executing extconf.rb with a broken $LOAD_PATH causing the json gem native extension to be loaded with the stdlib version of the .rb files.

This fails with

json/common.rb:82:in `initialize': wrong number of arguments (given 1, expected 0) (ArgumentError)

Since this is just for extconf.rb we can probably just accept that extra argument and ignore it.

The bug was fixed in rubygems 3.4.9 / 2023-03-20

FYI: @pixeltrix

@casperisfine
Copy link
Author

The problem is that this makes #646 somewhat worse, as it changes from a boot time issue into a runtime one.

$ bundle exec ruby -W -e 'require "json"; JSON.dump({})'
/Users/byroot/.gem/ruby/3.3.4/gems/json_pure-2.6.3/lib/json/common.rb:300: warning: The json gem extension was loaded with the stdlib ruby code. You should upgrade rubygems with `gem update --system`
/Users/byroot/.gem/ruby/3.3.4/gems/json_pure-2.6.3/lib/json/common.rb:310:in `generate': undefined method `configure' for an instance of JSON::Ext::Generator::State (NoMethodError)

      state = state.configure(opts)
                   ^^^^^^^^^^
	from /Users/byroot/.gem/ruby/3.3.4/gems/json_pure-2.6.3/lib/json/common.rb:641:in `dump'
	from -e:1:in `<main>'

The same code being shipped in json and json_pure is really a problem, I think we might need to namespace them somehow? Or find a way to enforce that both versions match.

Ref: ruby#647
Ref: rubygems/rubygems#6490

Older rubygems are executing `extconf.rb` with a broken `$LOAD_PATH`
causing the `json` gem native extension to be loaded with the stdlib
version of the `.rb` files.

This fails with

```
json/common.rb:82:in `initialize': wrong number of arguments (given 1, expected 0) (ArgumentError)
```

Since this is just for `extconf.rb` we can probably just accept that
extra argument and ignore it.

The bug was fixed in rubygems 3.4.9 / 2023-03-20
Fix: ruby#646

Since both `json` and `json_pure` expose the same files, if the
versions don't match, the native extension may be loaded with Ruby
code that don't match and is incompatible.

By doing the `require json/ext/generator/state` from C we ensure
we're at least loading that.

But this is a dirty workaround for the 2.7.x branch, we should
find a better way to fully isolate the two gems.
This actually never worked, because the test was always testing
the ext version from the stdlib, never the pure version nor the
current ext version.
@casperisfine casperisfine changed the base branch from master to v2.7.x October 25, 2024 10:43
@byroot byroot merged commit 9e9b749 into ruby:v2.7.x Oct 25, 2024
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants