X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pad.c;h=0c00cfff6b0c2488676fd77270871a49057edcbc;hb=02c473a9139e94d6158d1e3dd9a912f3525b3b21;hp=90d99795a546d390749c124bb950dea82b1d0a6d;hpb=2affe78f01f9cd3aae1b214beb9140e1fe830c7d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pad.c b/pad.c index 90d9979..0c00cff 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. @@ -22,6 +22,11 @@ /* =head1 Pad Data Structures +This file contains the functions that create and manipulate scratchpads, +which are array-of-array data structures attached to a CV (ie a sub) +and which store lexical variables and opcode temporary and per-thread +values. + =for apidoc m|AV *|CvPADLIST|CV *cv CV's can have CvPADLIST(cv) set to point to an AV. @@ -91,6 +96,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 +262,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; + } + } + } } } @@ -565,6 +587,19 @@ Perl_pad_findmy(pTHX_ char *name) return NOT_IN_PAD; } +/* + * Returns the offset of a lexical $_, if there is one, at run time. + * Used by the UNDERBAR XS macro. + */ + +PADOFFSET +Perl_find_rundefsvoffset(pTHX) +{ + SV *out_sv; + int out_flags; + return pad_findlex("$_", find_runcv(NULL), PL_curcop->cop_seq, 1, + Null(SV**), &out_sv, &out_flags); +} /* =for apidoc pad_findlex @@ -1243,7 +1278,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), @@ -1375,7 +1410,9 @@ Perl_cv_clone(pTHX_ CV *proto) #endif CvGV(cv) = CvGV(proto); CvSTASH(cv) = CvSTASH(proto); + OP_REFCNT_LOCK; CvROOT(cv) = OpREFCNT_inc(CvROOT(proto)); + OP_REFCNT_UNLOCK; CvSTART(cv) = CvSTART(proto); CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside); CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(proto); @@ -1506,6 +1543,9 @@ If has_args is true, give the new pad an @_ in slot zero. =cut */ +/* XXX pad_push is now always called with has_args == 1. Get rid of + * this arg at some point */ + void Perl_pad_push(pTHX_ PADLIST *padlist, int depth, int has_args) {