3 * Copyright (C) 2002, 2003, 2004, 2005 by Larry Wall and others
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
8 * "Anyway: there was this Mr Frodo left an orphan and stranded, as you
9 * might say, among those queer Bucklanders, being brought up anyhow in
10 * Brandy Hall. A regular warren, by all accounts. Old Master Gorbadoc
11 * never had fewer than a couple of hundred relations in the place. Mr
12 * Bilbo never did a kinder deed than when he brought the lad back to
13 * live among decent folk." --the Gaffer
17 * As of Sept 2002, this file is new and may be in a state of flux for
18 * a while. I've marked things I intent to come back and look at further
19 * with an 'XXX DAPM' comment.
23 =head1 Pad Data Structures
25 This file contains the functions that create and manipulate scratchpads,
26 which are array-of-array data structures attached to a CV (ie a sub)
27 and which store lexical variables and opcode temporary and per-thread
30 =for apidoc m|AV *|CvPADLIST|CV *cv
31 CV's can have CvPADLIST(cv) set to point to an AV.
33 For these purposes "forms" are a kind-of CV, eval""s are too (except they're
34 not callable at will and are always thrown away after the eval"" is done
35 executing). Require'd files are simply evals without any outer lexical
38 XSUBs don't have CvPADLIST set - dXSTARG fetches values from PL_curpad,
39 but that is really the callers pad (a slot of which is allocated by
42 The CvPADLIST AV has does not have AvREAL set, so REFCNT of component items
43 is managed "manual" (mostly in pad.c) rather than normal av.c rules.
44 The items in the AV are not SVs as for a normal AV, but other AVs:
46 0'th Entry of the CvPADLIST is an AV which represents the "names" or rather
47 the "static type information" for lexicals.
49 The CvDEPTH'th entry of CvPADLIST AV is an AV which is the stack frame at that
50 depth of recursion into the CV.
51 The 0'th slot of a frame AV is an AV which is @_.
52 other entries are storage for variables and op targets.
55 C<PL_comppad_name> is set to the names AV.
56 C<PL_comppad> is set to the frame AV for the frame CvDEPTH == 1.
57 C<PL_curpad> is set to the body of the frame AV (i.e. AvARRAY(PL_comppad)).
59 During execution, C<PL_comppad> and C<PL_curpad> refer to the live
60 frame of the currently executing sub.
62 Iterating over the names AV iterates over all possible pad
63 items. Pad slots that are SVs_PADTMP (targets/GVs/constants) end up having
64 &PL_sv_undef "names" (see pad_alloc()).
66 Only my/our variable (SVs_PADMY/SVs_PADOUR) slots get valid names.
67 The rest are op targets/GVs/constants which are statically allocated
68 or resolved at compile time. These don't have names by which they
69 can be looked up from Perl code at run time through eval"" like
70 my/our variables can be. Since they can't be looked up by "name"
71 but only by their index allocated at compile time (which is usually
72 in PL_op->op_targ), wasting a name SV for them doesn't make sense.
74 The SVs in the names AV have their PV being the name of the variable.
75 NV+1..IV inclusive is a range of cop_seq numbers for which the name is
76 valid. For typed lexicals name SV is SVt_PVMG and SvSTASH points at the
77 type. For C<our> lexicals, the type is SVt_PVGV, and GvSTASH points at the
78 stash of the associated global (so that duplicate C<our> declarations in the
79 same package can be detected). SvCUR is sometimes hijacked to
80 store the generation number during compilation.
82 If SvFAKE is set on the name SV, then that slot in the frame AV is
83 a REFCNT'ed reference to a lexical from "outside". In this case,
84 the name SV does not use NVX and IVX to store a cop_seq range, since it is
85 in scope throughout. Instead IVX stores some flags containing info about
86 the real lexical (is it declared in an anon, and is it capable of being
87 instantiated multiple times?), and for fake ANONs, NVX contains the index
88 within the parent's pad where the lexical's value is stored, to make
91 If the 'name' is '&' the corresponding entry in frame AV
92 is a CV representing a possible closure.
93 (SvFAKE and name of '&' is not a meaningful combination currently but could
94 become so if C<my sub foo {}> is implemented.)
96 Note that formats are treated as anon subs, and are cloned each time
97 write is called (if necessary).
99 The flag SVf_PADSTALE is cleared on lexicals each time the my() is executed,
100 and set on scope exit. This allows the 'Variable $x is not available' warning
101 to be generated in evals, such as
103 { my $x = 1; sub f { eval '$x'} } f();
110 #define PERL_IN_PAD_C
114 #define PAD_MAX 999999999
121 Create a new compiling padlist, saving and updating the various global
122 vars at the same time as creating the pad itself. The following flags
123 can be OR'ed together:
125 padnew_CLONE this pad is for a cloned CV
126 padnew_SAVE save old globals
127 padnew_SAVESUB also save extra stuff for start of sub
133 Perl_pad_new(pTHX_ int flags)
135 AV *padlist, *padname, *pad;
137 ASSERT_CURPAD_LEGAL("pad_new");
139 /* XXX DAPM really need a new SAVEt_PAD which restores all or most
140 * vars (based on flags) rather than storing vals + addresses for
141 * each individually. Also see pad_block_start.
142 * XXX DAPM Try to see whether all these conditionals are required
145 /* save existing state, ... */
147 if (flags & padnew_SAVE) {
149 SAVESPTR(PL_comppad_name);
150 if (! (flags & padnew_CLONE)) {
152 SAVEI32(PL_comppad_name_fill);
153 SAVEI32(PL_min_intro_pending);
154 SAVEI32(PL_max_intro_pending);
155 SAVEI32(PL_cv_has_eval);
156 if (flags & padnew_SAVESUB) {
157 SAVEI32(PL_pad_reset_pending);
161 /* XXX DAPM interestingly, PL_comppad_name_floor never seems to be
162 * saved - check at some pt that this is okay */
164 /* ... create new pad ... */
170 if (flags & padnew_CLONE) {
171 /* XXX DAPM I dont know why cv_clone needs it
172 * doing differently yet - perhaps this separate branch can be
173 * dispensed with eventually ???
176 AV * const a0 = newAV(); /* will be @_ */
178 av_store(pad, 0, (SV*)a0);
182 av_store(pad, 0, Nullsv);
186 av_store(padlist, 0, (SV*)padname);
187 av_store(padlist, 1, (SV*)pad);
189 /* ... then update state variables */
191 PL_comppad_name = (AV*)(*av_fetch(padlist, 0, FALSE));
192 PL_comppad = (AV*)(*av_fetch(padlist, 1, FALSE));
193 PL_curpad = AvARRAY(PL_comppad);
195 if (! (flags & padnew_CLONE)) {
196 PL_comppad_name_fill = 0;
197 PL_min_intro_pending = 0;
202 DEBUG_X(PerlIO_printf(Perl_debug_log,
203 "Pad 0x%"UVxf"[0x%"UVxf"] new: compcv=0x%"UVxf
204 " name=0x%"UVxf" flags=0x%"UVxf"\n",
205 PTR2UV(PL_comppad), PTR2UV(PL_curpad), PTR2UV(PL_compcv),
206 PTR2UV(padname), (UV)flags
210 return (PADLIST*)padlist;
214 =for apidoc pad_undef
216 Free the padlist associated with a CV.
217 If parts of it happen to be current, we null the relevant
218 PL_*pad* global vars so that we don't have any dangling references left.
219 We also repoint the CvOUTSIDE of any about-to-be-orphaned
220 inner subs to the outer of this cv.
222 (This function should really be called pad_free, but the name was already
229 Perl_pad_undef(pTHX_ CV* cv)
232 const PADLIST * const padlist = CvPADLIST(cv);
236 if (SvIS_FREED(padlist)) /* may be during global destruction */
239 DEBUG_X(PerlIO_printf(Perl_debug_log,
240 "Pad undef: cv=0x%"UVxf" padlist=0x%"UVxf"\n",
241 PTR2UV(cv), PTR2UV(padlist))
244 /* detach any '&' anon children in the pad; if afterwards they
245 * are still live, fix up their CvOUTSIDEs to point to our outside,
247 /* XXX DAPM for efficiency, we should only do this if we know we have
248 * children, or integrate this loop with general cleanup */
250 if (!PL_dirty) { /* don't bother during global destruction */
251 CV * const outercv = CvOUTSIDE(cv);
252 const U32 seq = CvOUTSIDE_SEQ(cv);
253 AV * const comppad_name = (AV*)AvARRAY(padlist)[0];
254 SV ** const namepad = AvARRAY(comppad_name);
255 AV * const comppad = (AV*)AvARRAY(padlist)[1];
256 SV ** const curpad = AvARRAY(comppad);
257 for (ix = AvFILLp(comppad_name); ix > 0; ix--) {
258 SV * const namesv = namepad[ix];
259 if (namesv && namesv != &PL_sv_undef
260 && *SvPVX_const(namesv) == '&')
262 CV * const innercv = (CV*)curpad[ix];
263 U32 inner_rc = SvREFCNT(innercv);
265 namepad[ix] = Nullsv;
266 SvREFCNT_dec(namesv);
268 if (SvREFCNT(comppad) < 2) { /* allow for /(?{ sub{} })/ */
270 SvREFCNT_dec(innercv);
273 if (inner_rc /* in use, not just a prototype */
274 && CvOUTSIDE(innercv) == cv)
276 assert(CvWEAKOUTSIDE(innercv));
277 /* don't relink to grandfather if he's being freed */
278 if (outercv && SvREFCNT(outercv)) {
279 CvWEAKOUTSIDE_off(innercv);
280 CvOUTSIDE(innercv) = outercv;
281 CvOUTSIDE_SEQ(innercv) = seq;
282 (void)SvREFCNT_inc(outercv);
285 CvOUTSIDE(innercv) = Nullcv;
294 ix = AvFILLp(padlist);
296 SV* const sv = AvARRAY(padlist)[ix--];
299 if (sv == (SV*)PL_comppad_name)
300 PL_comppad_name = NULL;
301 else if (sv == (SV*)PL_comppad) {
302 PL_comppad = Null(PAD*);
303 PL_curpad = Null(SV**);
307 SvREFCNT_dec((SV*)CvPADLIST(cv));
308 CvPADLIST(cv) = Null(PADLIST*);
315 =for apidoc pad_add_name
317 Create a new name and associated PADMY SV in the current pad; return the
319 If C<typestash> is valid, the name is for a typed lexical; set the
320 name's stash to that value.
321 If C<ourstash> is valid, it's an our lexical, set the name's
322 GvSTASH to that value
324 If fake, it means we're cloning an existing entry
330 Perl_pad_add_name(pTHX_ const char *name, HV* typestash, HV* ourstash, bool fake)
332 const PADOFFSET offset = pad_alloc(OP_PADSV, SVs_PADMY);
333 SV* const namesv = NEWSV(1102, 0);
335 ASSERT_CURPAD_ACTIVE("pad_add_name");
338 sv_upgrade(namesv, ourstash ? SVt_PVGV : typestash ? SVt_PVMG : SVt_PVNV);
339 sv_setpv(namesv, name);
342 SvFLAGS(namesv) |= SVpad_TYPED;
343 SvSTASH_set(namesv, (HV*)SvREFCNT_inc((SV*) typestash));
346 SvFLAGS(namesv) |= SVpad_OUR;
347 GvSTASH(namesv) = ourstash;
348 Perl_sv_add_backref(aTHX_ (SV*)ourstash, namesv);
351 av_store(PL_comppad_name, offset, namesv);
354 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
355 "Pad addname: %ld \"%s\" FAKE\n", (long)offset, name));
358 /* not yet introduced */
359 SvNV_set(namesv, (NV)PAD_MAX); /* min */
360 SvIV_set(namesv, 0); /* max */
362 if (!PL_min_intro_pending)
363 PL_min_intro_pending = offset;
364 PL_max_intro_pending = offset;
365 /* if it's not a simple scalar, replace with an AV or HV */
366 /* XXX DAPM since slot has been allocated, replace
367 * av_store with PL_curpad[offset] ? */
369 av_store(PL_comppad, offset, (SV*)newAV());
370 else if (*name == '%')
371 av_store(PL_comppad, offset, (SV*)newHV());
372 SvPADMY_on(PL_curpad[offset]);
373 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
374 "Pad addname: %ld \"%s\" new lex=0x%"UVxf"\n",
375 (long)offset, name, PTR2UV(PL_curpad[offset])));
385 =for apidoc pad_alloc
387 Allocate a new my or tmp pad entry. For a my, simply push a null SV onto
388 the end of PL_comppad, but for a tmp, scan the pad from PL_padix upwards
389 for a slot which has no name and no active value.
394 /* XXX DAPM integrate alloc(), add_name() and add_anon(),
395 * or at least rationalise ??? */
396 /* And flag whether the incoming name is UTF8 or 8 bit?
397 Could do this either with the +ve/-ve hack of the HV code, or expanding
398 the flag bits. Either way, this makes proper Unicode safe pad support.
399 Also could change the sv structure to make the NV a union with 2 U32s,
400 so that SvCUR() could stop being overloaded in pad SVs.
405 Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
410 ASSERT_CURPAD_ACTIVE("pad_alloc");
412 if (AvARRAY(PL_comppad) != PL_curpad)
413 Perl_croak(aTHX_ "panic: pad_alloc");
414 if (PL_pad_reset_pending)
416 if (tmptype & SVs_PADMY) {
417 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
418 retval = AvFILLp(PL_comppad);
421 SV * const * const names = AvARRAY(PL_comppad_name);
422 const SSize_t names_fill = AvFILLp(PL_comppad_name);
425 * "foreach" index vars temporarily become aliases to non-"my"
426 * values. Thus we must skip, not just pad values that are
427 * marked as current pad values, but also those with names.
429 /* HVDS why copy to sv here? we don't seem to use it */
430 if (++PL_padix <= names_fill &&
431 (sv = names[PL_padix]) && sv != &PL_sv_undef)
433 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
434 if (!(SvFLAGS(sv) & (SVs_PADTMP | SVs_PADMY)) &&
435 !IS_PADGV(sv) && !IS_PADCONST(sv))
440 SvFLAGS(sv) |= tmptype;
441 PL_curpad = AvARRAY(PL_comppad);
443 DEBUG_X(PerlIO_printf(Perl_debug_log,
444 "Pad 0x%"UVxf"[0x%"UVxf"] alloc: %ld for %s\n",
445 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long) retval,
446 PL_op_name[optype]));
447 #ifdef DEBUG_LEAKING_SCALARS
448 sv->sv_debug_optype = optype;
449 sv->sv_debug_inpad = 1;
451 return (PADOFFSET)retval;
455 =for apidoc pad_add_anon
457 Add an anon code entry to the current compiling pad
463 Perl_pad_add_anon(pTHX_ SV* sv, OPCODE op_type)
466 SV* const name = NEWSV(1106, 0);
467 sv_upgrade(name, SVt_PVNV);
468 sv_setpvn(name, "&", 1);
471 ix = pad_alloc(op_type, SVs_PADMY);
472 av_store(PL_comppad_name, ix, name);
473 /* XXX DAPM use PL_curpad[] ? */
474 av_store(PL_comppad, ix, sv);
477 /* to avoid ref loops, we never have parent + child referencing each
478 * other simultaneously */
479 if (CvOUTSIDE((CV*)sv)) {
480 assert(!CvWEAKOUTSIDE((CV*)sv));
481 CvWEAKOUTSIDE_on((CV*)sv);
482 SvREFCNT_dec(CvOUTSIDE((CV*)sv));
490 =for apidoc pad_check_dup
492 Check for duplicate declarations: report any of:
493 * a my in the current scope with the same name;
494 * an our (anywhere in the pad) with the same name and the same stash
496 C<is_our> indicates that the name to check is an 'our' declaration
501 /* XXX DAPM integrate this into pad_add_name ??? */
504 Perl_pad_check_dup(pTHX_ const char *name, bool is_our, const HV *ourstash)
509 ASSERT_CURPAD_ACTIVE("pad_check_dup");
510 if (AvFILLp(PL_comppad_name) < 0 || !ckWARN(WARN_MISC))
511 return; /* nothing to check */
513 svp = AvARRAY(PL_comppad_name);
514 top = AvFILLp(PL_comppad_name);
515 /* check the current scope */
516 /* XXX DAPM - why the (I32) cast - shouldn't we ensure they're the same
518 for (off = top; (I32)off > PL_comppad_name_floor; off--) {
519 SV * const sv = svp[off];
521 && sv != &PL_sv_undef
523 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
524 && strEQ(name, SvPVX_const(sv)))
526 if (is_our && (SvFLAGS(sv) & SVpad_OUR))
527 break; /* "our" masking "our" */
528 Perl_warner(aTHX_ packWARN(WARN_MISC),
529 "\"%s\" variable %s masks earlier declaration in same %s",
530 (is_our ? "our" : "my"),
532 (SvIVX(sv) == PAD_MAX ? "scope" : "statement"));
537 /* check the rest of the pad */
540 SV * const sv = svp[off];
542 && sv != &PL_sv_undef
544 && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
545 && ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash)
546 && strEQ(name, SvPVX_const(sv)))
548 Perl_warner(aTHX_ packWARN(WARN_MISC),
549 "\"our\" variable %s redeclared", name);
550 if ((I32)off <= PL_comppad_name_floor)
551 Perl_warner(aTHX_ packWARN(WARN_MISC),
552 "\t(Did you mean \"local\" instead of \"our\"?)\n");
555 } while ( off-- > 0 );
561 =for apidoc pad_findmy
563 Given a lexical name, try to find its offset, first in the current pad,
564 or failing that, in the pads of any lexically enclosing subs (including
565 the complications introduced by eval). If the name is found in an outer pad,
566 then a fake entry is added to the current pad.
567 Returns the offset in the current pad, or NOT_IN_PAD on failure.
573 Perl_pad_findmy(pTHX_ const char *name)
581 offset = pad_findlex(name, PL_compcv, PL_cop_seqmax, 1,
582 Null(SV**), &out_sv, &out_flags);
583 if (offset != NOT_IN_PAD)
586 /* look for an our that's being introduced; this allows
587 * our $foo = 0 unless defined $foo;
588 * to not give a warning. (Yes, this is a hack) */
590 nameav = (AV*)AvARRAY(CvPADLIST(PL_compcv))[0];
591 name_svp = AvARRAY(nameav);
592 for (offset = AvFILLp(nameav); offset > 0; offset--) {
593 const SV * const namesv = name_svp[offset];
594 if (namesv && namesv != &PL_sv_undef
596 && (SvFLAGS(namesv) & SVpad_OUR)
597 && strEQ(SvPVX_const(namesv), name)
598 && U_32(SvNVX(namesv)) == PAD_MAX /* min */
606 * Returns the offset of a lexical $_, if there is one, at run time.
607 * Used by the UNDERBAR XS macro.
611 Perl_find_rundefsvoffset(pTHX)
615 return pad_findlex("$_", find_runcv(NULL), PL_curcop->cop_seq, 1,
616 Null(SV**), &out_sv, &out_flags);
620 =for apidoc pad_findlex
622 Find a named lexical anywhere in a chain of nested pads. Add fake entries
623 in the inner pads if it's found in an outer one.
625 Returns the offset in the bottom pad of the lex or the fake lex.
626 cv is the CV in which to start the search, and seq is the current cop_seq
627 to match against. If warn is true, print appropriate warnings. The out_*
628 vars return values, and so are pointers to where the returned values
629 should be stored. out_capture, if non-null, requests that the innermost
630 instance of the lexical is captured; out_name_sv is set to the innermost
631 matched namesv or fake namesv; out_flags returns the flags normally
632 associated with the IVX field of a fake namesv.
634 Note that pad_findlex() is recursive; it recurses up the chain of CVs,
635 then comes back down, adding fake entries as it goes. It has to be this way
636 because fake namesvs in anon protoypes have to store in NVX the index into
642 /* Flags set in the SvIVX field of FAKE namesvs */
644 #define PAD_FAKELEX_ANON 1 /* the lex is declared in an ANON, or ... */
645 #define PAD_FAKELEX_MULTI 2 /* the lex can be instantiated multiple times */
647 /* the CV has finished being compiled. This is not a sufficient test for
648 * all CVs (eg XSUBs), but suffices for the CVs found in a lexical chain */
649 #define CvCOMPILED(cv) CvROOT(cv)
651 /* the CV does late binding of its lexicals */
652 #define CvLATE(cv) (CvANON(cv) || SvTYPE(cv) == SVt_PVFM)
656 S_pad_findlex(pTHX_ const char *name, const CV* cv, U32 seq, int warn,
657 SV** out_capture, SV** out_name_sv, int *out_flags)
659 I32 offset, new_offset;
662 const AV * const padlist = CvPADLIST(cv);
666 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
667 "Pad findlex cv=0x%"UVxf" searching \"%s\" seq=%d%s\n",
668 PTR2UV(cv), name, (int)seq, out_capture ? " capturing" : "" ));
670 /* first, search this pad */
672 if (padlist) { /* not an undef CV */
674 const AV * const nameav = (AV*)AvARRAY(padlist)[0];
675 SV * const * const name_svp = AvARRAY(nameav);
677 for (offset = AvFILLp(nameav); offset > 0; offset--) {
678 const SV * const namesv = name_svp[offset];
679 if (namesv && namesv != &PL_sv_undef
680 && strEQ(SvPVX_const(namesv), name))
683 fake_offset = offset; /* in case we don't find a real one */
684 else if ( seq > U_32(SvNVX(namesv)) /* min */
685 && seq <= (U32)SvIVX(namesv)) /* max */
690 if (offset > 0 || fake_offset > 0 ) { /* a match! */
691 if (offset > 0) { /* not fake */
693 *out_name_sv = name_svp[offset]; /* return the namesv */
695 /* set PAD_FAKELEX_MULTI if this lex can have multiple
696 * instances. For now, we just test !CvUNIQUE(cv), but
697 * ideally, we should detect my's declared within loops
698 * etc - this would allow a wider range of 'not stayed
699 * shared' warnings. We also treated alreadly-compiled
700 * lexes as not multi as viewed from evals. */
702 *out_flags = CvANON(cv) ?
704 (!CvUNIQUE(cv) && ! CvCOMPILED(cv))
705 ? PAD_FAKELEX_MULTI : 0;
707 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
708 "Pad findlex cv=0x%"UVxf" matched: offset=%ld (%ld,%ld)\n",
709 PTR2UV(cv), (long)offset, (long)U_32(SvNVX(*out_name_sv)),
710 (long)SvIVX(*out_name_sv)));
712 else { /* fake match */
713 offset = fake_offset;
714 *out_name_sv = name_svp[offset]; /* return the namesv */
715 *out_flags = SvIVX(*out_name_sv);
716 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
717 "Pad findlex cv=0x%"UVxf" matched: offset=%ld flags=0x%lx index=%lu\n",
718 PTR2UV(cv), (long)offset, (unsigned long)*out_flags,
719 (unsigned long)SvNVX(*out_name_sv)
723 /* return the lex? */
728 if ((SvFLAGS(*out_name_sv) & SVpad_OUR)) {
729 *out_capture = Nullsv;
733 /* trying to capture from an anon prototype? */
735 ? CvANON(cv) && CvCLONE(cv) && !CvCLONED(cv)
736 : *out_flags & PAD_FAKELEX_ANON)
738 if (warn && ckWARN(WARN_CLOSURE))
739 Perl_warner(aTHX_ packWARN(WARN_CLOSURE),
740 "Variable \"%s\" is not available", name);
741 *out_capture = Nullsv;
747 if (!CvCOMPILED(cv) && (*out_flags & PAD_FAKELEX_MULTI)
748 && warn && ckWARN(WARN_CLOSURE)) {
750 Perl_warner(aTHX_ packWARN(WARN_CLOSURE),
751 "Variable \"%s\" will not stay shared", name);
754 if (fake_offset && CvANON(cv)
755 && CvCLONE(cv) &&!CvCLONED(cv))
758 /* not yet caught - look further up */
759 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
760 "Pad findlex cv=0x%"UVxf" chasing lex in outer pad\n",
763 (void) pad_findlex(name, CvOUTSIDE(cv),
765 newwarn, out_capture, out_name_sv, out_flags);
770 *out_capture = AvARRAY((AV*)AvARRAY(padlist)[
771 CvDEPTH(cv) ? CvDEPTH(cv) : 1])[offset];
772 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
773 "Pad findlex cv=0x%"UVxf" found lex=0x%"UVxf"\n",
774 PTR2UV(cv), PTR2UV(*out_capture)));
776 if (SvPADSTALE(*out_capture)) {
777 if (ckWARN(WARN_CLOSURE))
778 Perl_warner(aTHX_ packWARN(WARN_CLOSURE),
779 "Variable \"%s\" is not available", name);
780 *out_capture = Nullsv;
785 *out_capture = sv_2mortal((SV*)newAV());
786 else if (*name == '%')
787 *out_capture = sv_2mortal((SV*)newHV());
789 *out_capture = sv_newmortal();
797 /* it's not in this pad - try above */
802 /* out_capture non-null means caller wants us to capture lex; in
803 * addition we capture ourselves unless it's an ANON/format */
804 new_capturep = out_capture ? out_capture :
805 CvLATE(cv) ? Null(SV**) : &new_capture;
807 offset = pad_findlex(name, CvOUTSIDE(cv), CvOUTSIDE_SEQ(cv), 1,
808 new_capturep, out_name_sv, out_flags);
809 if (offset == NOT_IN_PAD)
812 /* found in an outer CV. Add appropriate fake entry to this pad */
814 /* don't add new fake entries (via eval) to CVs that we have already
815 * finished compiling, or to undef CVs */
816 if (CvCOMPILED(cv) || !padlist)
817 return 0; /* this dummy (and invalid) value isnt used by the caller */
821 AV * const ocomppad_name = PL_comppad_name;
822 PAD * const ocomppad = PL_comppad;
823 PL_comppad_name = (AV*)AvARRAY(padlist)[0];
824 PL_comppad = (AV*)AvARRAY(padlist)[1];
825 PL_curpad = AvARRAY(PL_comppad);
827 new_offset = pad_add_name(
828 SvPVX_const(*out_name_sv),
829 (SvFLAGS(*out_name_sv) & SVpad_TYPED)
830 ? SvSTASH(*out_name_sv) : NULL,
831 (SvFLAGS(*out_name_sv) & SVpad_OUR)
832 ? GvSTASH(*out_name_sv) : NULL,
836 new_namesv = AvARRAY(PL_comppad_name)[new_offset];
837 SvIV_set(new_namesv, *out_flags);
839 SvNV_set(new_namesv, (NV)0);
840 if (SvFLAGS(new_namesv) & SVpad_OUR) {
843 else if (CvLATE(cv)) {
844 /* delayed creation - just note the offset within parent pad */
845 SvNV_set(new_namesv, (NV)offset);
849 /* immediate creation - capture outer value right now */
850 av_store(PL_comppad, new_offset, SvREFCNT_inc(*new_capturep));
851 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
852 "Pad findlex cv=0x%"UVxf" saved captured sv 0x%"UVxf" at offset %ld\n",
853 PTR2UV(cv), PTR2UV(*new_capturep), (long)new_offset));
855 *out_name_sv = new_namesv;
856 *out_flags = SvIVX(new_namesv);
858 PL_comppad_name = ocomppad_name;
859 PL_comppad = ocomppad;
860 PL_curpad = ocomppad ? AvARRAY(ocomppad) : Null(SV **);
870 Get the value at offset po in the current pad.
871 Use macro PAD_SV instead of calling this function directly.
878 Perl_pad_sv(pTHX_ PADOFFSET po)
880 ASSERT_CURPAD_ACTIVE("pad_sv");
883 Perl_croak(aTHX_ "panic: pad_sv po");
884 DEBUG_X(PerlIO_printf(Perl_debug_log,
885 "Pad 0x%"UVxf"[0x%"UVxf"] sv: %ld sv=0x%"UVxf"\n",
886 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)po, PTR2UV(PL_curpad[po]))
888 return PL_curpad[po];
893 =for apidoc pad_setsv
895 Set the entry at offset po in the current pad to sv.
896 Use the macro PAD_SETSV() rather than calling this function directly.
902 Perl_pad_setsv(pTHX_ PADOFFSET po, SV* sv)
904 ASSERT_CURPAD_ACTIVE("pad_setsv");
906 DEBUG_X(PerlIO_printf(Perl_debug_log,
907 "Pad 0x%"UVxf"[0x%"UVxf"] setsv: %ld sv=0x%"UVxf"\n",
908 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)po, PTR2UV(sv))
917 =for apidoc pad_block_start
919 Update the pad compilation state variables on entry to a new block
925 * - integrate this in general state-saving routine ???
926 * - combine with the state-saving going on in pad_new ???
927 * - introduce a new SAVE type that does all this in one go ?
931 Perl_pad_block_start(pTHX_ int full)
933 ASSERT_CURPAD_ACTIVE("pad_block_start");
934 SAVEI32(PL_comppad_name_floor);
935 PL_comppad_name_floor = AvFILLp(PL_comppad_name);
937 PL_comppad_name_fill = PL_comppad_name_floor;
938 if (PL_comppad_name_floor < 0)
939 PL_comppad_name_floor = 0;
940 SAVEI32(PL_min_intro_pending);
941 SAVEI32(PL_max_intro_pending);
942 PL_min_intro_pending = 0;
943 SAVEI32(PL_comppad_name_fill);
944 SAVEI32(PL_padix_floor);
945 PL_padix_floor = PL_padix;
946 PL_pad_reset_pending = FALSE;
953 "Introduce" my variables to visible status.
964 ASSERT_CURPAD_ACTIVE("intro_my");
965 if (! PL_min_intro_pending)
966 return PL_cop_seqmax;
968 svp = AvARRAY(PL_comppad_name);
969 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
970 SV * const sv = svp[i];
972 if (sv && sv != &PL_sv_undef && !SvFAKE(sv) && !SvIVX(sv)) {
973 SvIV_set(sv, PAD_MAX); /* Don't know scope end yet. */
974 SvNV_set(sv, (NV)PL_cop_seqmax);
975 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
976 "Pad intromy: %ld \"%s\", (%ld,%ld)\n",
977 (long)i, SvPVX_const(sv),
978 (long)U_32(SvNVX(sv)), (long)SvIVX(sv))
982 PL_min_intro_pending = 0;
983 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
984 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
985 "Pad intromy: seq -> %ld\n", (long)(PL_cop_seqmax+1)));
987 return PL_cop_seqmax++;
991 =for apidoc pad_leavemy
993 Cleanup at end of scope during compilation: set the max seq number for
994 lexicals in this scope and warn of any lexicals that never got introduced.
1000 Perl_pad_leavemy(pTHX)
1003 SV * const * const svp = AvARRAY(PL_comppad_name);
1005 PL_pad_reset_pending = FALSE;
1007 ASSERT_CURPAD_ACTIVE("pad_leavemy");
1008 if (PL_min_intro_pending && PL_comppad_name_fill < PL_min_intro_pending) {
1009 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
1010 const SV * const sv = svp[off];
1011 if (sv && sv != &PL_sv_undef
1012 && !SvFAKE(sv) && ckWARN_d(WARN_INTERNAL))
1013 Perl_warner(aTHX_ packWARN(WARN_INTERNAL),
1014 "%"SVf" never introduced", sv);
1017 /* "Deintroduce" my variables that are leaving with this scope. */
1018 for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_fill; off--) {
1019 const SV * const sv = svp[off];
1020 if (sv && sv != &PL_sv_undef && !SvFAKE(sv) && SvIVX(sv) == PAD_MAX) {
1021 SvIV_set(sv, PL_cop_seqmax);
1022 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
1023 "Pad leavemy: %ld \"%s\", (%ld,%ld)\n",
1024 (long)off, SvPVX_const(sv),
1025 (long)U_32(SvNVX(sv)), (long)SvIVX(sv))
1030 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
1031 "Pad leavemy: seq = %ld\n", (long)PL_cop_seqmax));
1036 =for apidoc pad_swipe
1038 Abandon the tmp in the current pad at offset po and replace with a
1045 Perl_pad_swipe(pTHX_ PADOFFSET po, bool refadjust)
1047 ASSERT_CURPAD_LEGAL("pad_swipe");
1050 if (AvARRAY(PL_comppad) != PL_curpad)
1051 Perl_croak(aTHX_ "panic: pad_swipe curpad");
1053 Perl_croak(aTHX_ "panic: pad_swipe po");
1055 DEBUG_X(PerlIO_printf(Perl_debug_log,
1056 "Pad 0x%"UVxf"[0x%"UVxf"] swipe: %ld\n",
1057 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)po));
1060 SvPADTMP_off(PL_curpad[po]);
1062 SvREFCNT_dec(PL_curpad[po]);
1065 /* if pad tmps aren't shared between ops, then there's no need to
1066 * create a new tmp when an existing op is freed */
1067 #ifdef USE_BROKEN_PAD_RESET
1068 PL_curpad[po] = NEWSV(1107,0);
1069 SvPADTMP_on(PL_curpad[po]);
1071 PL_curpad[po] = &PL_sv_undef;
1073 if ((I32)po < PL_padix)
1079 =for apidoc pad_reset
1081 Mark all the current temporaries for reuse
1086 /* XXX pad_reset() is currently disabled because it results in serious bugs.
1087 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
1088 * on the stack by OPs that use them, there are several ways to get an alias
1089 * to a shared TARG. Such an alias will change randomly and unpredictably.
1090 * We avoid doing this until we can think of a Better Way.
1093 Perl_pad_reset(pTHX)
1095 #ifdef USE_BROKEN_PAD_RESET
1096 if (AvARRAY(PL_comppad) != PL_curpad)
1097 Perl_croak(aTHX_ "panic: pad_reset curpad");
1099 DEBUG_X(PerlIO_printf(Perl_debug_log,
1100 "Pad 0x%"UVxf"[0x%"UVxf"] reset: padix %ld -> %ld",
1101 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
1102 (long)PL_padix, (long)PL_padix_floor
1106 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
1108 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
1109 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
1110 SvPADTMP_off(PL_curpad[po]);
1112 PL_padix = PL_padix_floor;
1115 PL_pad_reset_pending = FALSE;
1120 =for apidoc pad_tidy
1122 Tidy up a pad after we've finished compiling it:
1123 * remove most stuff from the pads of anonsub prototypes;
1125 * mark tmps as such.
1130 /* XXX DAPM surely most of this stuff should be done properly
1131 * at the right time beforehand, rather than going around afterwards
1132 * cleaning up our mistakes ???
1136 Perl_pad_tidy(pTHX_ padtidy_type type)
1140 ASSERT_CURPAD_ACTIVE("pad_tidy");
1142 /* If this CV has had any 'eval-capable' ops planted in it
1143 * (ie it contains eval '...', //ee, /$var/ or /(?{..})/), Then any
1144 * anon prototypes in the chain of CVs should be marked as cloneable,
1145 * so that for example the eval's CV in C<< sub { eval '$x' } >> gets
1146 * the right CvOUTSIDE.
1147 * If running with -d, *any* sub may potentially have an eval
1148 * excuted within it.
1151 if (PL_cv_has_eval || PL_perldb) {
1153 for (cv = PL_compcv ;cv; cv = CvOUTSIDE(cv)) {
1154 if (cv != PL_compcv && CvCOMPILED(cv))
1155 break; /* no need to mark already-compiled code */
1157 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
1158 "Pad clone on cv=0x%"UVxf"\n", PTR2UV(cv)));
1164 /* extend curpad to match namepad */
1165 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
1166 av_store(PL_comppad_name, AvFILLp(PL_comppad), Nullsv);
1168 if (type == padtidy_SUBCLONE) {
1169 SV * const * const namep = AvARRAY(PL_comppad_name);
1172 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
1175 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
1178 * The only things that a clonable function needs in its
1179 * pad are anonymous subs.
1180 * The rest are created anew during cloning.
1182 if (!((namesv = namep[ix]) != Nullsv &&
1183 namesv != &PL_sv_undef &&
1184 *SvPVX_const(namesv) == '&'))
1186 SvREFCNT_dec(PL_curpad[ix]);
1187 PL_curpad[ix] = Nullsv;
1191 else if (type == padtidy_SUB) {
1192 /* XXX DAPM this same bit of code keeps appearing !!! Rationalise? */
1193 AV * const av = newAV(); /* Will be @_ */
1195 av_store(PL_comppad, 0, (SV*)av);
1199 /* XXX DAPM rationalise these two similar branches */
1201 if (type == padtidy_SUB) {
1203 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
1204 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
1206 if (!SvPADMY(PL_curpad[ix]))
1207 SvPADTMP_on(PL_curpad[ix]);
1210 else if (type == padtidy_FORMAT) {
1212 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
1213 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
1214 SvPADTMP_on(PL_curpad[ix]);
1217 PL_curpad = AvARRAY(PL_comppad);
1222 =for apidoc pad_free
1224 Free the SV at offset po in the current pad.
1229 /* XXX DAPM integrate with pad_swipe ???? */
1231 Perl_pad_free(pTHX_ PADOFFSET po)
1233 ASSERT_CURPAD_LEGAL("pad_free");
1236 if (AvARRAY(PL_comppad) != PL_curpad)
1237 Perl_croak(aTHX_ "panic: pad_free curpad");
1239 Perl_croak(aTHX_ "panic: pad_free po");
1241 DEBUG_X(PerlIO_printf(Perl_debug_log,
1242 "Pad 0x%"UVxf"[0x%"UVxf"] free: %ld\n",
1243 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)po)
1246 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef) {
1247 SvPADTMP_off(PL_curpad[po]);
1249 /* SV could be a shared hash key (eg bugid #19022) */
1251 #ifdef PERL_OLD_COPY_ON_WRITE
1252 !SvIsCOW(PL_curpad[po])
1254 !SvFAKE(PL_curpad[po])
1257 SvREADONLY_off(PL_curpad[po]); /* could be a freed constant */
1260 if ((I32)po < PL_padix)
1267 =for apidoc do_dump_pad
1269 Dump the contents of a padlist
1275 Perl_do_dump_pad(pTHX_ I32 level, PerlIO *file, PADLIST *padlist, int full)
1286 pad_name = (AV*)*av_fetch((AV*)padlist, 0, FALSE);
1287 pad = (AV*)*av_fetch((AV*)padlist, 1, FALSE);
1288 pname = AvARRAY(pad_name);
1289 ppad = AvARRAY(pad);
1290 Perl_dump_indent(aTHX_ level, file,
1291 "PADNAME = 0x%"UVxf"(0x%"UVxf") PAD = 0x%"UVxf"(0x%"UVxf")\n",
1292 PTR2UV(pad_name), PTR2UV(pname), PTR2UV(pad), PTR2UV(ppad)
1295 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
1296 const SV *namesv = pname[ix];
1297 if (namesv && namesv == &PL_sv_undef) {
1302 Perl_dump_indent(aTHX_ level+1, file,
1303 "%2d. 0x%"UVxf"<%lu> FAKE \"%s\" flags=0x%lx index=%lu\n",
1306 (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0),
1307 SvPVX_const(namesv),
1308 (unsigned long)SvIVX(namesv),
1309 (unsigned long)SvNVX(namesv)
1313 Perl_dump_indent(aTHX_ level+1, file,
1314 "%2d. 0x%"UVxf"<%lu> (%ld,%ld) \"%s\"\n",
1317 (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0),
1318 (long)U_32(SvNVX(namesv)),
1319 (long)SvIVX(namesv),
1324 Perl_dump_indent(aTHX_ level+1, file,
1325 "%2d. 0x%"UVxf"<%lu>\n",
1328 (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0)
1339 dump the contents of a CV
1346 S_cv_dump(pTHX_ const CV *cv, const char *title)
1348 const CV * const outside = CvOUTSIDE(cv);
1349 AV* const padlist = CvPADLIST(cv);
1351 PerlIO_printf(Perl_debug_log,
1352 " %s: CV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
1355 (CvANON(cv) ? "ANON"
1356 : (SvTYPE(cv) == SVt_PVFM) ? "FORMAT"
1357 : (cv == PL_main_cv) ? "MAIN"
1358 : CvUNIQUE(cv) ? "UNIQUE"
1359 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
1362 : CvANON(outside) ? "ANON"
1363 : (outside == PL_main_cv) ? "MAIN"
1364 : CvUNIQUE(outside) ? "UNIQUE"
1365 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
1367 PerlIO_printf(Perl_debug_log,
1368 " PADLIST = 0x%"UVxf"\n", PTR2UV(padlist));
1369 do_dump_pad(1, Perl_debug_log, padlist, 1);
1371 #endif /* DEBUGGING */
1378 =for apidoc cv_clone
1380 Clone a CV: make a new CV which points to the same code etc, but which
1381 has a newly-created pad built by copying the prototype pad and capturing
1388 Perl_cv_clone(pTHX_ CV *proto)
1392 AV* const protopadlist = CvPADLIST(proto);
1393 const AV* const protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
1394 const AV* const protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
1395 SV** const pname = AvARRAY(protopad_name);
1396 SV** const ppad = AvARRAY(protopad);
1397 const I32 fname = AvFILLp(protopad_name);
1398 const I32 fpad = AvFILLp(protopad);
1404 assert(!CvUNIQUE(proto));
1406 /* Since cloneable anon subs can be nested, CvOUTSIDE may point
1407 * to a prototype; we instead want the cloned parent who called us.
1408 * Note that in general for formats, CvOUTSIDE != find_runcv */
1410 outside = CvOUTSIDE(proto);
1411 if (outside && CvCLONE(outside) && ! CvCLONED(outside))
1412 outside = find_runcv(NULL);
1413 depth = CvDEPTH(outside);
1414 assert(depth || SvTYPE(proto) == SVt_PVFM);
1417 assert(CvPADLIST(outside));
1420 SAVESPTR(PL_compcv);
1422 cv = PL_compcv = (CV*)NEWSV(1104, 0);
1423 sv_upgrade((SV *)cv, SvTYPE(proto));
1424 CvFLAGS(cv) = CvFLAGS(proto) & ~(CVf_CLONE|CVf_WEAKOUTSIDE);
1428 CvFILE(cv) = CvXSUB(proto) ? CvFILE(proto)
1429 : savepv(CvFILE(proto));
1431 CvFILE(cv) = CvFILE(proto);
1433 CvGV(cv) = CvGV(proto);
1434 CvSTASH(cv) = CvSTASH(proto);
1436 CvROOT(cv) = OpREFCNT_inc(CvROOT(proto));
1438 CvSTART(cv) = CvSTART(proto);
1439 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc(outside);
1440 CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(proto);
1443 sv_setpvn((SV*)cv, SvPVX_const(proto), SvCUR(proto));
1445 CvPADLIST(cv) = pad_new(padnew_CLONE|padnew_SAVE);
1447 av_fill(PL_comppad, fpad);
1448 for (ix = fname; ix >= 0; ix--)
1449 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
1451 PL_curpad = AvARRAY(PL_comppad);
1453 outpad = AvARRAY(AvARRAY(CvPADLIST(outside))[depth]);
1455 for (ix = fpad; ix > 0; ix--) {
1456 SV* const namesv = (ix <= fname) ? pname[ix] : Nullsv;
1458 if (namesv && namesv != &PL_sv_undef) { /* lexical */
1459 if (SvFAKE(namesv)) { /* lexical from outside? */
1460 sv = outpad[(I32)SvNVX(namesv)];
1462 /* formats may have an inactive parent */
1463 if (SvTYPE(proto) == SVt_PVFM && SvPADSTALE(sv)) {
1464 if (ckWARN(WARN_CLOSURE))
1465 Perl_warner(aTHX_ packWARN(WARN_CLOSURE),
1466 "Variable \"%s\" is not available", SvPVX_const(namesv));
1470 assert(!SvPADSTALE(sv));
1471 sv = SvREFCNT_inc(sv);
1475 const char sigil = SvPVX_const(namesv)[0];
1477 sv = SvREFCNT_inc(ppad[ix]);
1478 else if (sigil == '@')
1480 else if (sigil == '%')
1487 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
1488 sv = SvREFCNT_inc(ppad[ix]);
1498 PerlIO_printf(Perl_debug_log, "\nPad CV clone\n");
1499 cv_dump(outside, "Outside");
1500 cv_dump(proto, "Proto");
1507 /* Constant sub () { $x } closing over $x - see lib/constant.pm:
1508 * The prototype was marked as a candiate for const-ization,
1509 * so try to grab the current const value, and if successful,
1510 * turn into a const sub:
1512 SV* const const_sv = op_const_sv(CvSTART(cv), cv);
1515 cv = newCONSTSUB(CvSTASH(proto), Nullch, const_sv);
1527 =for apidoc pad_fixup_inner_anons
1529 For any anon CVs in the pad, change CvOUTSIDE of that CV from
1530 old_cv to new_cv if necessary. Needed when a newly-compiled CV has to be
1531 moved to a pre-existing CV struct.
1537 Perl_pad_fixup_inner_anons(pTHX_ PADLIST *padlist, CV *old_cv, CV *new_cv)
1540 AV * const comppad_name = (AV*)AvARRAY(padlist)[0];
1541 AV * const comppad = (AV*)AvARRAY(padlist)[1];
1542 SV ** const namepad = AvARRAY(comppad_name);
1543 SV ** const curpad = AvARRAY(comppad);
1544 for (ix = AvFILLp(comppad_name); ix > 0; ix--) {
1545 const SV * const namesv = namepad[ix];
1546 if (namesv && namesv != &PL_sv_undef
1547 && *SvPVX_const(namesv) == '&')
1549 CV * const innercv = (CV*)curpad[ix];
1550 assert(CvWEAKOUTSIDE(innercv));
1551 assert(CvOUTSIDE(innercv) == old_cv);
1552 CvOUTSIDE(innercv) = new_cv;
1559 =for apidoc pad_push
1561 Push a new pad frame onto the padlist, unless there's already a pad at
1562 this depth, in which case don't bother creating a new one. Then give
1563 the new pad an @_ in slot zero.
1569 Perl_pad_push(pTHX_ PADLIST *padlist, int depth)
1571 if (depth <= AvFILLp(padlist))
1575 SV** const svp = AvARRAY(padlist);
1576 AV* const newpad = newAV();
1577 SV** const oldpad = AvARRAY(svp[depth-1]);
1578 I32 ix = AvFILLp((AV*)svp[1]);
1579 const I32 names_fill = AvFILLp((AV*)svp[0]);
1580 SV** const names = AvARRAY(svp[0]);
1583 for ( ;ix > 0; ix--) {
1584 if (names_fill >= ix && names[ix] != &PL_sv_undef) {
1585 const char sigil = SvPVX_const(names[ix])[0];
1586 if ((SvFLAGS(names[ix]) & SVf_FAKE) || sigil == '&') {
1587 /* outer lexical or anon code */
1588 av_store(newpad, ix, SvREFCNT_inc(oldpad[ix]));
1590 else { /* our own lexical */
1594 else if (sigil == '%')
1598 av_store(newpad, ix, sv);
1602 else if (IS_PADGV(oldpad[ix]) || IS_PADCONST(oldpad[ix])) {
1603 av_store(newpad, ix, SvREFCNT_inc(oldpad[ix]));
1606 /* save temporaries on recursion? */
1607 SV * const sv = NEWSV(0, 0);
1608 av_store(newpad, ix, sv);
1614 av_store(newpad, 0, (SV*)av);
1617 av_store(padlist, depth, (SV*)newpad);
1618 AvFILLp(padlist) = depth;
1624 Perl_pad_compname_type(pTHX_ const PADOFFSET po)
1626 SV* const * const av = av_fetch(PL_comppad_name, po, FALSE);
1627 if ( SvFLAGS(*av) & SVpad_TYPED ) {
1628 return SvSTASH(*av);
1635 * c-indentation-style: bsd
1637 * indent-tabs-mode: t
1640 * ex: set ts=8 sts=4 sw=4 noet: