Skip to content

Commit 591056a

Browse files
committed
Implement write barriers for ParserConfig objects
1 parent dafaf38 commit 591056a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

ext/json/ext/parser/parser.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ static VALUE convert_encoding(VALUE source)
11841184
return rb_funcall(source, i_encode, 1, Encoding_UTF_8);
11851185
}
11861186

1187-
static int configure_parser_i(VALUE key, VALUE val, VALUE data)
1187+
static int parser_config_init_i(VALUE key, VALUE val, VALUE data)
11881188
{
11891189
JSON_ParserConfig *config = (JSON_ParserConfig *)data;
11901190

@@ -1220,7 +1220,7 @@ static void parser_config_init(JSON_ParserConfig *config, VALUE opts)
12201220
if (RHASH_SIZE(opts) > 0) {
12211221
// We assume in most cases few keys are set so it's faster to go over
12221222
// the provided keys than to check all possible keys.
1223-
rb_hash_foreach(opts, configure_parser_i, (VALUE)config);
1223+
rb_hash_foreach(opts, parser_config_init_i, (VALUE)config);
12241224

12251225
if (config->symbolize_names && config->create_additions) {
12261226
rb_raise(rb_eArgError,
@@ -1273,6 +1273,13 @@ static VALUE cParserConfig_initialize(VALUE self, VALUE opts)
12731273
GET_PARSER_CONFIG;
12741274

12751275
parser_config_init(config, opts);
1276+
1277+
RB_OBJ_WRITTEN(self, Qundef, config->create_id);
1278+
RB_OBJ_WRITTEN(self, Qundef, config->object_class);
1279+
RB_OBJ_WRITTEN(self, Qundef, config->array_class);
1280+
RB_OBJ_WRITTEN(self, Qundef, config->decimal_class);
1281+
RB_OBJ_WRITTEN(self, Qundef, config->match_string);
1282+
12761283
return self;
12771284
}
12781285

@@ -1344,7 +1351,7 @@ static VALUE cParser_m_parse(VALUE klass, VALUE Vsource, VALUE opts)
13441351
return cParser_parse(config, Vsource);
13451352
}
13461353

1347-
static void JSON_mark(void *ptr)
1354+
static void JSON_ParserConfig_mark(void *ptr)
13481355
{
13491356
JSON_ParserConfig *config = ptr;
13501357
rb_gc_mark(config->create_id);
@@ -1354,22 +1361,26 @@ static void JSON_mark(void *ptr)
13541361
rb_gc_mark(config->match_string);
13551362
}
13561363

1357-
static void JSON_free(void *ptr)
1364+
static void JSON_ParserConfig_free(void *ptr)
13581365
{
13591366
JSON_ParserConfig *config = ptr;
13601367
ruby_xfree(config);
13611368
}
13621369

1363-
static size_t JSON_memsize(const void *ptr)
1370+
static size_t JSON_ParserConfig_memsize(const void *ptr)
13641371
{
13651372
return sizeof(JSON_ParserConfig);
13661373
}
13671374

13681375
static const rb_data_type_t JSON_ParserConfig_type = {
1369-
"JSON/ParserConfig",
1370-
{JSON_mark, JSON_free, JSON_memsize,},
1376+
"JSON::Ext::Parser/ParserConfig",
1377+
{
1378+
JSON_ParserConfig_mark,
1379+
JSON_ParserConfig_free,
1380+
JSON_ParserConfig_memsize,
1381+
},
13711382
0, 0,
1372-
RUBY_TYPED_FREE_IMMEDIATELY,
1383+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
13731384
};
13741385

13751386
static VALUE cJSON_parser_s_allocate(VALUE klass)

0 commit comments

Comments
 (0)