diff --git a/internal/string.h b/internal/string.h index 009b6ec3be..cde81a1a25 100644 --- a/internal/string.h +++ b/internal/string.h @@ -46,7 +46,6 @@ int rb_enc_str_coderange_scan(VALUE str, rb_encoding *enc); int rb_ascii8bit_appendable_encoding_index(rb_encoding *enc, unsigned int code); VALUE rb_str_include(VALUE str, VALUE arg); VALUE rb_str_byte_substr(VALUE str, VALUE beg, VALUE len); -VALUE rb_str_valid_encoding_p(VALUE str); static inline bool STR_EMBED_P(VALUE str); static inline bool STR_SHARED_P(VALUE str); diff --git a/parse.y b/parse.y index 29dabc5c59..dee0fe15b9 100644 --- a/parse.y +++ b/parse.y @@ -13730,11 +13730,15 @@ new_defined(struct parser_params *p, NODE *expr, const YYLTYPE *loc) static NODE* str_to_sym_node(struct parser_params *p, NODE *node, const YYLTYPE *loc) { - VALUE lit = rb_node_str_string_val(node); - if (!rb_str_valid_encoding_p(lit)) { + VALUE lit; + rb_parser_string_t *str = RNODE_STR(node)->string; + if (rb_parser_enc_str_coderange(p, str) == RB_PARSER_ENC_CODERANGE_BROKEN) { yyerror1(loc, "invalid symbol"); lit = STR_NEW0(); } + else { + lit = rb_str_new_parser_string(str); + } return NEW_SYM(lit, loc); } diff --git a/ruby_parser.c b/ruby_parser.c index f74511941b..7061f2be5b 100644 --- a/ruby_parser.c +++ b/ruby_parser.c @@ -551,7 +551,6 @@ static const rb_parser_config_t rb_global_parser_config = { .id2str = rb_id2str, .id2sym = rb_id2sym, .sym2id = rb_sym2id, - .str_valid_encoding_p = rb_str_valid_encoding_p, .str_catf = rb_str_catf, .str_cat_cstr = rb_str_cat_cstr, diff --git a/rubyparser.h b/rubyparser.h index 4b2e19a2a7..ab55233d6d 100644 --- a/rubyparser.h +++ b/rubyparser.h @@ -1277,7 +1277,6 @@ typedef struct rb_parser_config_struct { VALUE (*id2str)(ID id); VALUE (*id2sym)(ID x); ID (*sym2id)(VALUE sym); - VALUE (*str_valid_encoding_p)(VALUE str); /* String */ RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3) diff --git a/string.c b/string.c index 73324fdacd..d8c2a91085 100644 --- a/string.c +++ b/string.c @@ -11030,7 +11030,7 @@ rb_str_b(VALUE str) * "\x80".force_encoding("UTF-8").valid_encoding? # => false */ -VALUE +static VALUE rb_str_valid_encoding_p(VALUE str) { int cr = rb_enc_str_coderange(str); diff --git a/universal_parser.c b/universal_parser.c index 9bf3c65936..b670d0f4e3 100644 --- a/universal_parser.c +++ b/universal_parser.c @@ -173,7 +173,6 @@ struct rb_imemo_tmpbuf_struct { #define ID2SYM p->config->id2sym #undef SYM2ID #define SYM2ID p->config->sym2id -#define rb_str_valid_encoding_p p->config->str_valid_encoding_p #define rb_str_catf p->config->str_catf #undef rb_str_cat_cstr