Skip to content

Commit 21284ea

Browse files
committed
parser.c: use rb_str_to_interned_str over rb_funcall
1 parent ac58045 commit 21284ea

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ext/json/ext/parser/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
$defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"]
55
have_func("rb_enc_interned_str", "ruby/encoding.h") # RUBY_VERSION >= 3.0
6+
have_func("rb_str_to_interned_str", "ruby.h") # RUBY_VERSION >= 3.0
67
have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2
78
have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby
89
have_func("strnlen", "string.h") # Missing on Solaris 10

ext/json/ext/parser/parser.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static int utf8_encindex;
1616

1717
#ifndef HAVE_RB_HASH_BULK_INSERT
1818
// For TruffleRuby
19-
void
19+
static void
2020
rb_hash_bulk_insert(long count, const VALUE *pairs, VALUE hash)
2121
{
2222
long index = 0;
@@ -33,6 +33,12 @@ rb_hash_bulk_insert(long count, const VALUE *pairs, VALUE hash)
3333
#define rb_hash_new_capa(n) rb_hash_new()
3434
#endif
3535

36+
#ifndef HAVE_RB_STR_TO_INTERNED_STR
37+
static VALUE rb_str_to_interned_str(VALUE str)
38+
{
39+
return rb_funcall(rb_str_freeze(str), i_uminus, 0);
40+
}
41+
#endif
3642

3743
/* name cache */
3844

@@ -703,7 +709,7 @@ static VALUE json_string_unescape(JSON_ParserState *state, const char *string, c
703709
if (symbolize) {
704710
result = rb_str_intern(result);
705711
} else if (intern) {
706-
result = rb_funcall(rb_str_freeze(result), i_uminus, 0);
712+
result = rb_str_to_interned_str(result);
707713
}
708714

709715
return result;
@@ -1310,6 +1316,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
13101316
}
13111317

13121318
raise_parse_error("unreachable: %s", state);
1319+
return Qundef;
13131320
}
13141321

13151322
static void json_ensure_eof(JSON_ParserState *state)

0 commit comments

Comments
 (0)