X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Declare.xs;h=54aa66852b37c0dba56b8a9e78c58c70de8cb23d;hb=c7fa6ac81cadd56e406b83997657e9640fbf3dda;hp=edfbc0df664179824140eadc9c12ec61efb4a4fa;hpb=e21e91fe39cd22441574c727fbb1c80ad6605a66;p=p5sagit%2FDevel-Declare.git diff --git a/Declare.xs b/Declare.xs index edfbc0d..54aa668 100644 --- a/Declare.xs +++ b/Declare.xs @@ -11,6 +11,11 @@ # define Newx(v,n,t) New(0,v,n,t) #endif /* !Newx */ +#define DD_DEBUGf_UPDATED_LINESTR 1 +#define DD_DEBUGf_TRACE 2 + +#define DD_DEBUG_UPDATED_LINESTR (dd_debug & DD_DEBUGf_UPDATED_LINESTR) +#define DD_DEBUG_TRACE (dd_debug & DD_DEBUGf_TRACE) static int dd_debug = 0; #define LEX_NORMAL 10 @@ -117,16 +122,28 @@ void dd_set_linestr(pTHX_ char* new_value) { unsigned int new_len = strlen(new_value); if (SvLEN(PL_linestr) < new_len) { - croak("forced to realloc PL_linestr for line %s, bailing out before we crash harder", SvPVX(PL_linestr)); + croak("PL_linestr not long enough, was Devel::Declare loaded soon enough in %s", + CopFILE(&PL_compiling) + ); } - SvGROW(PL_linestr, new_len); memcpy(SvPVX(PL_linestr), new_value, new_len+1); SvCUR_set(PL_linestr, new_len); PL_bufend = SvPVX(PL_linestr) + new_len; + + if ( DD_DEBUG_UPDATED_LINESTR && PERLDB_LINE && PL_curstash != PL_debstash) { + // Cribbed from toke.c + SV * const sv = NEWSV(85,0); + + sv_upgrade(sv, SVt_PVMG); + sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); + (void)SvIOK_on(sv); + SvIV_set(sv, 0); + av_store(CopFILEAV(&PL_compiling),(I32)CopLINE(&PL_compiling),sv); + } } char* dd_get_lex_stuff(pTHX) { @@ -217,7 +234,7 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { PERL_UNUSED_VAR(user_data); if (in_declare) { - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("Deconstructing declare\n"); printf("PL_bufptr: %s\n", PL_bufptr); printf("bufend at: %i\n", PL_bufend - PL_bufptr); @@ -235,7 +252,7 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { FREETMPS; LEAVE; - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("PL_bufptr: %s\n", PL_bufptr); printf("bufend at: %i\n", PL_bufend - PL_bufptr); printf("linestr: %s\n", SvPVX(PL_linestr)); @@ -253,7 +270,7 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { if (!DD_AM_LEXING) return o; /* not lexing? */ - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("Checking GV %s -> %s\n", HvNAME(GvSTASH(kGVOP_gv)), GvNAME(kGVOP_gv)); } @@ -262,7 +279,7 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { if (dd_flags == -1) return o; - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("dd_flags are: %i\n", dd_flags); printf("PL_tokenbuf: %s\n", PL_tokenbuf); } @@ -285,7 +302,7 @@ OP* dd_pp_entereval(pTHX) { #endif sv = POPs; if (SvPOK(sv)) { - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("mangling eval sv\n"); } if (SvREADONLY(sv)) @@ -471,6 +488,11 @@ set_in_declare(int value) in_declare = value; BOOT: - if (getenv ("DD_DEBUG")) { - dd_debug = 1; + char *endptr; + char *debug_str = getenv ("DD_DEBUG"); + if (debug_str) { + dd_debug = strtol (debug_str, &endptr, 10); + if (*endptr != '\0') { + dd_debug = 0; + } }