@@ -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);
@@ -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);
}
@@ -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,
@@ -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)
@@ -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);
@@ -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