summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2024-10-25 12:00:21 +0200
committerHiroshi SHIBATA <[email protected]>2024-10-26 18:44:15 +0900
commit8018a3121f8a516d2849475f965a1cf6038b5543 (patch)
tree907c2cfb653c2da41263aa7b5c687dc4f3a65145
parenta5bd0c638a600a5cfb0d99ee64ba8172a9c66535 (diff)
[ruby/json] Workaround being loaded alongside a different `json_pure` version
Fix: https://github.com/ruby/json/issues/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. https://github.com/ruby/json/commit/dfdd4acf36
-rw-r--r--ext/json/generator/generator.c2
-rw-r--r--ext/json/lib/json/ext.rb3
2 files changed, 2 insertions, 3 deletions
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index 8a94e2337b..3f2d91ffa4 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -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");
}
diff --git a/ext/json/lib/json/ext.rb b/ext/json/lib/json/ext.rb
index 775e28a967..92ef61eaec 100644
--- a/ext/json/lib/json/ext.rb
+++ b/ext/json/lib/json/ext.rb
@@ -15,9 +15,6 @@ module JSON
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