X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pad.c;h=209eb0a71bd2357ccc51768976615c61ca34911b;hb=8bbf3450a1ff0a3996dade29a4194cc0939d871f;hp=dff9a7f947f7e1eece49229537c315e0b3918a3c;hpb=929a0744021ffa24a9c2c65030b2f147d2412c41;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pad.c b/pad.c index dff9a7f..209eb0a 100644 --- a/pad.c +++ b/pad.c @@ -1,6 +1,6 @@ /* pad.c * - * Copyright (C) 2002,2003 by Larry Wall and others + * Copyright (C) 2002, 2003, 2004, by Larry Wall and others * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. @@ -91,6 +91,12 @@ become so if C is implemented.) Note that formats are treated as anon subs, and are cloned each time write is called (if necessary). +The flag SVf_PADSTALE is cleared on lexicals each time the my() is executed, +and set on scope exit. This allows the 'Variable $x is not available' warning +to be generated in evals, such as + + { my $x = 1; sub f { eval '$x'} } f(); + =cut */ @@ -251,17 +257,28 @@ Perl_pad_undef(pTHX_ CV* cv) CV *innercv = (CV*)curpad[ix]; namepad[ix] = Nullsv; SvREFCNT_dec(namesv); - curpad[ix] = Nullsv; - SvREFCNT_dec(innercv); + + if (SvREFCNT(comppad) < 2) { /* allow for /(?{ sub{} })/ */ + curpad[ix] = Nullsv; + SvREFCNT_dec(innercv); + } if (SvREFCNT(innercv) /* in use, not just a prototype */ && CvOUTSIDE(innercv) == cv) { assert(CvWEAKOUTSIDE(innercv)); - CvWEAKOUTSIDE_off(innercv); - CvOUTSIDE(innercv) = outercv; - CvOUTSIDE_SEQ(innercv) = seq; - SvREFCNT_inc(outercv); + /* don't relink to grandfather if he's being freed */ + if (outercv && SvREFCNT(outercv)) { + CvWEAKOUTSIDE_off(innercv); + CvOUTSIDE(innercv) = outercv; + CvOUTSIDE_SEQ(innercv) = seq; + SvREFCNT_inc(outercv); + } + else { + CvOUTSIDE(innercv) = Nullcv; + } + } + } } } @@ -558,7 +575,7 @@ Perl_pad_findmy(pTHX_ char *name) && !SvFAKE(namesv) && (SvFLAGS(namesv) & SVpad_OUR) && strEQ(SvPVX(namesv), name) - && (U32)I_32(SvNVX(namesv)) == PAD_MAX /* min */ + && U_32(SvNVX(namesv)) == PAD_MAX /* min */ ) return offset; } @@ -631,8 +648,8 @@ S_pad_findlex(pTHX_ char *name, CV* cv, U32 seq, int warn, { if (SvFAKE(namesv)) fake_offset = offset; /* in case we don't find a real one */ - else if ( seq > (U32)I_32(SvNVX(namesv)) /* min */ - && seq <= (U32)SvIVX(namesv)) /* max */ + else if ( seq > U_32(SvNVX(namesv)) /* min */ + && seq <= (U32)SvIVX(namesv)) /* max */ break; } } @@ -656,7 +673,7 @@ S_pad_findlex(pTHX_ char *name, CV* cv, U32 seq, int warn, DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad findlex cv=0x%"UVxf" matched: offset=%ld (%ld,%ld)\n", - PTR2UV(cv), (long)offset, (long)I_32(SvNVX(*out_name_sv)), + PTR2UV(cv), (long)offset, (long)U_32(SvNVX(*out_name_sv)), (long)SvIVX(*out_name_sv))); } else { /* fake match */ @@ -664,7 +681,7 @@ S_pad_findlex(pTHX_ char *name, CV* cv, U32 seq, int warn, *out_name_sv = name_svp[offset]; /* return the namesv */ *out_flags = SvIVX(*out_name_sv); DEBUG_Xv(PerlIO_printf(Perl_debug_log, - "Pad findlex cv=0x%"UVxf" matched: offset=%ld flags=0x%x index=%lu\n", + "Pad findlex cv=0x%"UVxf" matched: offset=%ld flags=0x%lx index=%lu\n", PTR2UV(cv), (long)offset, (unsigned long)*out_flags, (unsigned long)SvNVX(*out_name_sv) )); @@ -720,7 +737,7 @@ S_pad_findlex(pTHX_ char *name, CV* cv, U32 seq, int warn, CvDEPTH(cv) ? CvDEPTH(cv) : 1])[offset]; DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad findlex cv=0x%"UVxf" found lex=0x%"UVxf"\n", - PTR2UV(cv), *out_capture)); + PTR2UV(cv), PTR2UV(*out_capture))); if (SvPADSTALE(*out_capture)) { if (ckWARN(WARN_CLOSURE)) @@ -925,7 +942,7 @@ Perl_intro_my(pTHX) DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad intromy: %ld \"%s\", (%ld,%ld)\n", (long)i, SvPVX(sv), - (long)I_32(SvNVX(sv)), (long)SvIVX(sv)) + (long)U_32(SvNVX(sv)), (long)SvIVX(sv)) ); } } @@ -973,7 +990,7 @@ Perl_pad_leavemy(pTHX) DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad leavemy: %ld \"%s\", (%ld,%ld)\n", (long)off, SvPVX(sv), - (long)I_32(SvNVX(sv)), (long)SvIVX(sv)) + (long)U_32(SvNVX(sv)), (long)SvIVX(sv)) ); } } @@ -1243,7 +1260,7 @@ Perl_do_dump_pad(pTHX_ I32 level, PerlIO *file, PADLIST *padlist, int full) if (namesv) { if (SvFAKE(namesv)) Perl_dump_indent(aTHX_ level+1, file, - "%2d. 0x%"UVxf"<%lu> FAKE \"%s\" flags=0x%x index=%lu\n", + "%2d. 0x%"UVxf"<%lu> FAKE \"%s\" flags=0x%lx index=%lu\n", (int) ix, PTR2UV(ppad[ix]), (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0), @@ -1258,7 +1275,7 @@ Perl_do_dump_pad(pTHX_ I32 level, PerlIO *file, PADLIST *padlist, int full) (int) ix, PTR2UV(ppad[ix]), (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0), - (long)I_32(SvNVX(namesv)), + (long)U_32(SvNVX(namesv)), (long)SvIVX(namesv), SvPVX(namesv) );