Skip to content

Commit

Permalink
Workaround being loaded alongside a different json_pure version
Browse files Browse the repository at this point in the history
Fix: #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.
  • Loading branch information
byroot committed Oct 25, 2024
1 parent a0cd1de commit 7fd3531
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ext/json/ext/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,4 +1507,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 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
2 changes: 1 addition & 1 deletion test/json/ractor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class JSONInRactorTest < Test::Unit::TestCase
def test_generate
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
assert_separately(%w[-rjson -Ilib -Iext], "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
begin;
$VERBOSE = nil
require "json"
Expand Down

0 comments on commit 7fd3531

Please sign in to comment.