diff options
author | Kenta Murata <mrkn@mrkn.jp> | 2020-12-21 15:57:42 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-12-22 13:58:03 +0900 |
commit | f1d5fb030ce758b96e13817290964d92e3516d82 (patch) | |
tree | a3f4efbdbd25f2927aa72756f969f8d5a0e083cc /ext | |
parent | ae5ef25af52b2b92d7ecf40feeca09c324c0d777 (diff) | |
download | json-f1d5fb030ce758b96e13817290964d92e3516d82.tar.gz |
[json] Make json Ractor safe
Diffstat (limited to 'ext')
-rw-r--r-- | ext/json/ext/generator/generator.c | 11 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.c | 4 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.rl | 4 |
3 files changed, 18 insertions, 1 deletions
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c index 2e802c8..407c1af 100644 --- a/ext/json/ext/generator/generator.c +++ b/ext/json/ext/generator/generator.c @@ -619,13 +619,18 @@ static size_t State_memsize(const void *ptr) return size; } +#ifndef HAVE_RB_EXT_RACTOR_SAFE +# undef RUBY_TYPED_FROZEN_SHAREABLE +# define RUBY_TYPED_FROZEN_SHAREABLE 0 +#endif + #ifdef NEW_TYPEDDATA_WRAPPER static const rb_data_type_t JSON_Generator_State_type = { "JSON/Generator/State", {NULL, State_free, State_memsize,}, #ifdef RUBY_TYPED_FREE_IMMEDIATELY 0, 0, - RUBY_TYPED_FREE_IMMEDIATELY, + RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE, #endif }; #endif @@ -1497,6 +1502,10 @@ static VALUE cState_buffer_initial_length_set(VALUE self, VALUE buffer_initial_l */ void Init_generator(void) { +#ifdef HAVE_RB_EXT_RACTOR_SAFE + rb_ext_ractor_safe(true); +#endif + #undef rb_intern rb_require("json/common"); diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index f997295..29b5674 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -2119,6 +2119,10 @@ static VALUE cParser_source(VALUE self) void Init_parser(void) { +#ifdef HAVE_RB_EXT_RACTOR_SAFE + rb_ext_ractor_safe(true); +#endif + #undef rb_intern rb_require("json/common"); mJSON = rb_define_module("JSON"); diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index 24aed60..1da70c5 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -879,6 +879,10 @@ static VALUE cParser_source(VALUE self) void Init_parser(void) { +#ifdef HAVE_RB_EXT_RACTOR_SAFE + rb_ext_ractor_safe(true); +#endif + #undef rb_intern rb_require("json/common"); mJSON = rb_define_module("JSON"); |