@@ -6462,12 +6462,6 @@ lex_getline(struct parser_params *p)
6462
6462
if (NIL_P(line)) return line;
6463
6463
must_be_ascii_compatible(line);
6464
6464
if (RB_OBJ_FROZEN(line)) line = rb_str_dup(line); // needed for RubyVM::AST.of because script_lines in iseq is deep-frozen
6465
- #ifndef RIPPER
6466
- if (p->debug_lines) {
6467
- rb_enc_associate(line, p->enc);
6468
- rb_ary_push(p->debug_lines, line);
6469
- }
6470
- #endif
6471
6465
p->line_count++;
6472
6466
return line;
6473
6467
}
@@ -6614,7 +6608,7 @@ add_delayed_token(struct parser_params *p, const char *tok, const char *end)
6614
6608
#endif
6615
6609
6616
6610
static int
6617
- nextline(struct parser_params *p)
6611
+ nextline(struct parser_params *p, int set_encoding )
6618
6612
{
6619
6613
VALUE v = p->lex.nextline;
6620
6614
p->lex.nextline = 0;
@@ -6632,6 +6626,12 @@ nextline(struct parser_params *p)
6632
6626
lex_goto_eol(p);
6633
6627
return -1;
6634
6628
}
6629
+ #ifndef RIPPER
6630
+ if (p->debug_lines) {
6631
+ if (set_encoding) rb_enc_associate(v, p->enc);
6632
+ rb_ary_push(p->debug_lines, v);
6633
+ }
6634
+ #endif
6635
6635
p->cr_seen = FALSE;
6636
6636
}
6637
6637
else if (NIL_P(v)) {
@@ -6663,12 +6663,12 @@ parser_cr(struct parser_params *p, int c)
6663
6663
}
6664
6664
6665
6665
static inline int
6666
- nextc (struct parser_params *p)
6666
+ nextc0 (struct parser_params *p, int set_encoding )
6667
6667
{
6668
6668
int c;
6669
6669
6670
6670
if (UNLIKELY((p->lex.pcur == p->lex.pend) || p->eofp || RTEST(p->lex.nextline))) {
6671
- if (nextline(p)) return -1;
6671
+ if (nextline(p, set_encoding )) return -1;
6672
6672
}
6673
6673
c = (unsigned char)*p->lex.pcur++;
6674
6674
if (UNLIKELY(c == '\r')) {
@@ -6677,6 +6677,7 @@ nextc(struct parser_params *p)
6677
6677
6678
6678
return c;
6679
6679
}
6680
+ #define nextc(p) nextc0(p, TRUE)
6680
6681
6681
6682
static void
6682
6683
pushback(struct parser_params *p, int c)
@@ -8467,7 +8468,7 @@ set_file_encoding(struct parser_params *p, const char *str, const char *send)
8467
8468
static void
8468
8469
parser_prepare(struct parser_params *p)
8469
8470
{
8470
- int c = nextc(p );
8471
+ int c = nextc0(p, FALSE );
8471
8472
p->token_info_enabled = !compile_for_eval && RTEST(ruby_verbose);
8472
8473
switch (c) {
8473
8474
case '#':
@@ -8479,6 +8480,11 @@ parser_prepare(struct parser_params *p)
8479
8480
(unsigned char)p->lex.pcur[1] == 0xbf) {
8480
8481
p->enc = rb_utf8_encoding();
8481
8482
p->lex.pcur += 2;
8483
+ #ifndef RIPPER
8484
+ if (p->debug_lines) {
8485
+ rb_enc_associate(p->lex.lastline, p->enc);
8486
+ }
8487
+ #endif
8482
8488
p->lex.pbeg = p->lex.pcur;
8483
8489
return;
8484
8490
}
0 commit comments