Skip to content

Commit

Permalink
[ruby/json] Workaround being loaded alongside a different json_pure
Browse files Browse the repository at this point in the history
… version

Fix: ruby/json#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.

ruby/json@dfdd4acf36
  • Loading branch information
byroot authored and hsbt committed Oct 26, 2024
1 parent e6b4570 commit 3339adf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ext/json/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1521,4 +1521,6 @@ void Init_generator(void)
usascii_encindex = rb_usascii_encindex();
utf8_encindex = rb_utf8_encindex();
binary_encindex = rb_ascii8bit_encindex();

rb_require("json/ext/generator/state");
}
3 changes: 0 additions & 3 deletions ext/json/lib/json/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ module Ext
else
require 'json/ext/parser'
require 'json/ext/generator'
unless RUBY_ENGINE == 'jruby'
require 'json/ext/generator/state'
end
$DEBUG and warn "Using Ext extension for JSON."
JSON.parser = Parser
JSON.generator = Generator
Expand Down

0 comments on commit 3339adf

Please sign in to comment.