From: Florian Ragwitz Date: Fri, 10 Jul 2009 10:31:33 +0000 (+0200) Subject: Make the toke.c functions always operate on PL_compiling, even if we call them at... X-Git-Tag: 0.005007~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2688337bafe83db36857a49ecfd39984ef08ee73;p=p5sagit%2FDevel-Declare.git Make the toke.c functions always operate on PL_compiling, even if we call them at runtime. This fixes the broken line numbers. Thanks Ash Berlin, for working this out! --- diff --git a/stolen_chunk_of_toke.c b/stolen_chunk_of_toke.c index 8f3b040..04dee1a 100644 --- a/stolen_chunk_of_toke.c +++ b/stolen_chunk_of_toke.c @@ -64,6 +64,19 @@ STATIC char* S_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t') #endif +/* + * Normally, during compile time, PL_curcop == &PL_compiling is true. However, + * Devel::Declare makes the interpreter call back to perl during compile time, + * which temporarily enters runtime. Then perl space calls various functions + * from this file, which are designed to work during compile time. They all + * happen to operate on PL_curcop, not PL_compiling. That doesn't make a + * difference in the core, but it does for Devel::Declare, which operates at + * runtime, but still wants to mangle the things that are about to be compiled. + * That's why we define our own PL_curcop and make it point to PL_compiling + * here. + */ +#define PL_curcop &PL_compiling + #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline)) #define LEX_NORMAL 10 /* normal code (ie not within "...") */ diff --git a/t/lines.t b/t/lines.t index d1d701c..8927ad2 100644 --- a/t/lines.t +++ b/t/lines.t @@ -47,9 +47,6 @@ my $line2 = __LINE__; #line 48 is(@lines, 2, "2 line numbers recorded"); is $lines[0], 100, "fun starts on line 100"; -{ - local $TODO = "line numbers aren't quite right yet, sometimes"; - is $lines[1], 101, "fun stops on line 101"; - is $line, 102, "next statement on line 102"; - is $line2, 103, "next statement on line 103"; -} +is $lines[1], 101, "fun stops on line 101"; +is $line, 102, "next statement on line 102"; +is $line2, 103, "next statement on line 103";