Move PAD_FAKELEX_ANON and PAD_FAKELEX_MULTI to pad.h, export them via
[p5sagit/p5-mst-13.2.git] / pad.c
CommitLineData
dd2155a4 1/* pad.c
2 *
54ca4ee7 3 * Copyright (C) 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
dd2155a4 4 *
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.
7 *
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
14 */
15
16/* XXX DAPM
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.
20 */
21
22/*
23=head1 Pad Data Structures
24
61296642 25This file contains the functions that create and manipulate scratchpads,
166f8a29 26which are array-of-array data structures attached to a CV (ie a sub)
61296642 27and which store lexical variables and opcode temporary and per-thread
166f8a29 28values.
29
dd2155a4 30=for apidoc m|AV *|CvPADLIST|CV *cv
31CV's can have CvPADLIST(cv) set to point to an AV.
32
33For these purposes "forms" are a kind-of CV, eval""s are too (except they're
34not callable at will and are always thrown away after the eval"" is done
b5c19bd7 35executing). Require'd files are simply evals without any outer lexical
36scope.
dd2155a4 37
38XSUBs don't have CvPADLIST set - dXSTARG fetches values from PL_curpad,
39but that is really the callers pad (a slot of which is allocated by
40every entersub).
41
42The CvPADLIST AV has does not have AvREAL set, so REFCNT of component items
f3548bdc 43is managed "manual" (mostly in pad.c) rather than normal av.c rules.
dd2155a4 44The items in the AV are not SVs as for a normal AV, but other AVs:
45
460'th Entry of the CvPADLIST is an AV which represents the "names" or rather
47the "static type information" for lexicals.
48
49The CvDEPTH'th entry of CvPADLIST AV is an AV which is the stack frame at that
50depth of recursion into the CV.
51The 0'th slot of a frame AV is an AV which is @_.
52other entries are storage for variables and op targets.
53
54During compilation:
a6d05634 55C<PL_comppad_name> is set to the names AV.
56C<PL_comppad> is set to the frame AV for the frame CvDEPTH == 1.
57C<PL_curpad> is set to the body of the frame AV (i.e. AvARRAY(PL_comppad)).
dd2155a4 58
f3548bdc 59During execution, C<PL_comppad> and C<PL_curpad> refer to the live
60frame of the currently executing sub.
61
62Iterating over the names AV iterates over all possible pad
dd2155a4 63items. Pad slots that are SVs_PADTMP (targets/GVs/constants) end up having
64&PL_sv_undef "names" (see pad_alloc()).
65
66Only my/our variable (SVs_PADMY/SVs_PADOUR) slots get valid names.
67The rest are op targets/GVs/constants which are statically allocated
68or resolved at compile time. These don't have names by which they
69can be looked up from Perl code at run time through eval"" like
70my/our variables can be. Since they can't be looked up by "name"
71but only by their index allocated at compile time (which is usually
72in PL_op->op_targ), wasting a name SV for them doesn't make sense.
73
74The SVs in the names AV have their PV being the name of the variable.
3441fb63 75xlow+1..xhigh inclusive in the NV union is a range of cop_seq numbers for
76which the name is valid. For typed lexicals name SV is SVt_PVMG and SvSTASH
77points at the type. For C<our> lexicals, the type is also SVt_PVMG, with the
78OURSTASH slot pointing at the stash of the associated global (so that
79duplicate C<our> declarations in the same package can be detected). SvCUR is
80sometimes hijacked to store the generation number during compilation.
dd2155a4 81
b5c19bd7 82If SvFAKE is set on the name SV, then that slot in the frame AV is
83a REFCNT'ed reference to a lexical from "outside". In this case,
3441fb63 84the name SV does not use xlow and xhigh to store a cop_seq range, since it is
85in scope throughout. Instead xhigh stores some flags containing info about
b5c19bd7 86the real lexical (is it declared in an anon, and is it capable of being
3441fb63 87instantiated multiple times?), and for fake ANONs, xlow contains the index
b5c19bd7 88within the parent's pad where the lexical's value is stored, to make
89cloning quicker.
dd2155a4 90
a6d05634 91If the 'name' is '&' the corresponding entry in frame AV
dd2155a4 92is a CV representing a possible closure.
93(SvFAKE and name of '&' is not a meaningful combination currently but could
94become so if C<my sub foo {}> is implemented.)
95
71f882da 96Note that formats are treated as anon subs, and are cloned each time
97write is called (if necessary).
98
e6e7068b 99The flag SVf_PADSTALE is cleared on lexicals each time the my() is executed,
100and set on scope exit. This allows the 'Variable $x is not available' warning
101to be generated in evals, such as
102
103 { my $x = 1; sub f { eval '$x'} } f();
104
dd2155a4 105=cut
106*/
107
108
109#include "EXTERN.h"
110#define PERL_IN_PAD_C
111#include "perl.h"
952306ac 112#include "keywords.h"
dd2155a4 113
3441fb63 114#define COP_SEQ_RANGE_LOW_set(sv,val) \
115 STMT_START { ((XPVNV*)SvANY(sv))->xnv_u.xpad_cop_seq.xlow = (val); } STMT_END
116#define COP_SEQ_RANGE_HIGH_set(sv,val) \
117 STMT_START { ((XPVNV*)SvANY(sv))->xnv_u.xpad_cop_seq.xhigh = (val); } STMT_END
809abb02 118
3441fb63 119#define PARENT_PAD_INDEX_set(sv,val) \
120 STMT_START { ((XPVNV*)SvANY(sv))->xnv_u.xpad_cop_seq.xlow = (val); } STMT_END
121#define PARENT_FAKELEX_FLAGS_set(sv,val) \
122 STMT_START { ((XPVNV*)SvANY(sv))->xnv_u.xpad_cop_seq.xhigh = (val); } STMT_END
dd2155a4 123
fc83298a 124#define PAD_MAX IV_MAX
dd2155a4 125
1dba731d 126#ifdef PERL_MAD
127void pad_peg(const char* s) {
128 static int pegcnt;
129 pegcnt++;
130}
131#endif
dd2155a4 132
133/*
134=for apidoc pad_new
135
136Create a new compiling padlist, saving and updating the various global
137vars at the same time as creating the pad itself. The following flags
138can be OR'ed together:
139
140 padnew_CLONE this pad is for a cloned CV
141 padnew_SAVE save old globals
142 padnew_SAVESUB also save extra stuff for start of sub
143
144=cut
145*/
146
147PADLIST *
c7c737cb 148Perl_pad_new(pTHX_ int flags)
dd2155a4 149{
97aff369 150 dVAR;
e1ec3a88 151 AV *padlist, *padname, *pad;
dd2155a4 152
f3548bdc 153 ASSERT_CURPAD_LEGAL("pad_new");
154
dd2155a4 155 /* XXX DAPM really need a new SAVEt_PAD which restores all or most
156 * vars (based on flags) rather than storing vals + addresses for
157 * each individually. Also see pad_block_start.
158 * XXX DAPM Try to see whether all these conditionals are required
159 */
160
161 /* save existing state, ... */
162
163 if (flags & padnew_SAVE) {
3979c56f 164 SAVECOMPPAD();
dd2155a4 165 SAVESPTR(PL_comppad_name);
166 if (! (flags & padnew_CLONE)) {
167 SAVEI32(PL_padix);
168 SAVEI32(PL_comppad_name_fill);
169 SAVEI32(PL_min_intro_pending);
170 SAVEI32(PL_max_intro_pending);
b5c19bd7 171 SAVEI32(PL_cv_has_eval);
dd2155a4 172 if (flags & padnew_SAVESUB) {
173 SAVEI32(PL_pad_reset_pending);
174 }
175 }
176 }
177 /* XXX DAPM interestingly, PL_comppad_name_floor never seems to be
178 * saved - check at some pt that this is okay */
179
180 /* ... create new pad ... */
181
182 padlist = newAV();
183 padname = newAV();
184 pad = newAV();
185
186 if (flags & padnew_CLONE) {
187 /* XXX DAPM I dont know why cv_clone needs it
188 * doing differently yet - perhaps this separate branch can be
189 * dispensed with eventually ???
190 */
191
e1ec3a88 192 AV * const a0 = newAV(); /* will be @_ */
dd2155a4 193 av_extend(a0, 0);
194 av_store(pad, 0, (SV*)a0);
11ca45c0 195 AvREIFY_only(a0);
dd2155a4 196 }
197 else {
a0714e2c 198 av_store(pad, 0, NULL);
dd2155a4 199 }
200
201 AvREAL_off(padlist);
202 av_store(padlist, 0, (SV*)padname);
203 av_store(padlist, 1, (SV*)pad);
204
205 /* ... then update state variables */
206
207 PL_comppad_name = (AV*)(*av_fetch(padlist, 0, FALSE));
208 PL_comppad = (AV*)(*av_fetch(padlist, 1, FALSE));
209 PL_curpad = AvARRAY(PL_comppad);
210
211 if (! (flags & padnew_CLONE)) {
212 PL_comppad_name_fill = 0;
213 PL_min_intro_pending = 0;
214 PL_padix = 0;
b5c19bd7 215 PL_cv_has_eval = 0;
dd2155a4 216 }
217
218 DEBUG_X(PerlIO_printf(Perl_debug_log,
b5c19bd7 219 "Pad 0x%"UVxf"[0x%"UVxf"] new: compcv=0x%"UVxf
dd2155a4 220 " name=0x%"UVxf" flags=0x%"UVxf"\n",
b5c19bd7 221 PTR2UV(PL_comppad), PTR2UV(PL_curpad), PTR2UV(PL_compcv),
dd2155a4 222 PTR2UV(padname), (UV)flags
223 )
224 );
225
226 return (PADLIST*)padlist;
227}
228
229/*
230=for apidoc pad_undef
231
232Free the padlist associated with a CV.
233If parts of it happen to be current, we null the relevant
234PL_*pad* global vars so that we don't have any dangling references left.
235We also repoint the CvOUTSIDE of any about-to-be-orphaned
a3985cdc 236inner subs to the outer of this cv.
dd2155a4 237
7dafbf52 238(This function should really be called pad_free, but the name was already
239taken)
240
dd2155a4 241=cut
242*/
243
244void
a3985cdc 245Perl_pad_undef(pTHX_ CV* cv)
dd2155a4 246{
97aff369 247 dVAR;
dd2155a4 248 I32 ix;
b64e5050 249 const PADLIST * const padlist = CvPADLIST(cv);
dd2155a4 250
1dba731d 251 pad_peg("pad_undef");
dd2155a4 252 if (!padlist)
253 return;
0565a181 254 if (SvIS_FREED(padlist)) /* may be during global destruction */
dd2155a4 255 return;
256
257 DEBUG_X(PerlIO_printf(Perl_debug_log,
b5c19bd7 258 "Pad undef: cv=0x%"UVxf" padlist=0x%"UVxf"\n",
259 PTR2UV(cv), PTR2UV(padlist))
dd2155a4 260 );
261
7dafbf52 262 /* detach any '&' anon children in the pad; if afterwards they
263 * are still live, fix up their CvOUTSIDEs to point to our outside,
264 * bypassing us. */
265 /* XXX DAPM for efficiency, we should only do this if we know we have
266 * children, or integrate this loop with general cleanup */
dd2155a4 267
7dafbf52 268 if (!PL_dirty) { /* don't bother during global destruction */
53c1dcc0 269 CV * const outercv = CvOUTSIDE(cv);
e1ec3a88 270 const U32 seq = CvOUTSIDE_SEQ(cv);
53c1dcc0 271 AV * const comppad_name = (AV*)AvARRAY(padlist)[0];
272 SV ** const namepad = AvARRAY(comppad_name);
273 AV * const comppad = (AV*)AvARRAY(padlist)[1];
274 SV ** const curpad = AvARRAY(comppad);
dd2155a4 275 for (ix = AvFILLp(comppad_name); ix > 0; ix--) {
504618e9 276 SV * const namesv = namepad[ix];
dd2155a4 277 if (namesv && namesv != &PL_sv_undef
b15aece3 278 && *SvPVX_const(namesv) == '&')
dd2155a4 279 {
7fc63493 280 CV * const innercv = (CV*)curpad[ix];
10dc53a8 281 U32 inner_rc = SvREFCNT(innercv);
282 assert(inner_rc);
a0714e2c 283 namepad[ix] = NULL;
7dafbf52 284 SvREFCNT_dec(namesv);
01773faa 285
286 if (SvREFCNT(comppad) < 2) { /* allow for /(?{ sub{} })/ */
a0714e2c 287 curpad[ix] = NULL;
01773faa 288 SvREFCNT_dec(innercv);
10dc53a8 289 inner_rc--;
01773faa 290 }
b37c2d43 291
292 /* in use, not just a prototype */
293 if (inner_rc && (CvOUTSIDE(innercv) == cv)) {
7dafbf52 294 assert(CvWEAKOUTSIDE(innercv));
9d1ce744 295 /* don't relink to grandfather if he's being freed */
296 if (outercv && SvREFCNT(outercv)) {
297 CvWEAKOUTSIDE_off(innercv);
298 CvOUTSIDE(innercv) = outercv;
299 CvOUTSIDE_SEQ(innercv) = seq;
f84c484e 300 SvREFCNT_inc_simple_void_NN(outercv);
9d1ce744 301 }
302 else {
601f1833 303 CvOUTSIDE(innercv) = NULL;
9d1ce744 304 }
dd2155a4 305 }
306 }
307 }
308 }
7dafbf52 309
dd2155a4 310 ix = AvFILLp(padlist);
311 while (ix >= 0) {
b37c2d43 312 const SV* const sv = AvARRAY(padlist)[ix--];
313 if (sv) {
314 if (sv == (SV*)PL_comppad_name)
315 PL_comppad_name = NULL;
316 else if (sv == (SV*)PL_comppad) {
317 PL_comppad = NULL;
318 PL_curpad = NULL;
319 }
dd2155a4 320 }
321 SvREFCNT_dec(sv);
322 }
323 SvREFCNT_dec((SV*)CvPADLIST(cv));
4608196e 324 CvPADLIST(cv) = NULL;
dd2155a4 325}
326
327
328
329
330/*
331=for apidoc pad_add_name
332
b5c19bd7 333Create a new name and associated PADMY SV in the current pad; return the
334offset.
dd2155a4 335If C<typestash> is valid, the name is for a typed lexical; set the
336name's stash to that value.
337If C<ourstash> is valid, it's an our lexical, set the name's
035dab74 338OURSTASH to that value
dd2155a4 339
dd2155a4 340If fake, it means we're cloning an existing entry
341
342=cut
343*/
344
dd2155a4 345PADOFFSET
952306ac 346Perl_pad_add_name(pTHX_ const char *name, HV* typestash, HV* ourstash, bool fake, bool state)
dd2155a4 347{
97aff369 348 dVAR;
504618e9 349 const PADOFFSET offset = pad_alloc(OP_PADSV, SVs_PADMY);
561b68a9 350 SV* const namesv = newSV(0);
dd2155a4 351
f3548bdc 352 ASSERT_CURPAD_ACTIVE("pad_add_name");
353
dd2155a4 354
2892acdb 355 sv_upgrade(namesv, (ourstash || typestash) ? SVt_PVMG : SVt_PVNV);
dd2155a4 356 sv_setpv(namesv, name);
357
358 if (typestash) {
63f10712 359 assert(SvTYPE(namesv) == SVt_PVMG);
00b1698f 360 SvPAD_TYPED_on(namesv);
b37c2d43 361 SvSTASH_set(namesv, (HV*)SvREFCNT_inc_simple_NN((SV*)typestash));
dd2155a4 362 }
363 if (ourstash) {
00b1698f 364 SvPAD_OUR_on(namesv);
035dab74 365 OURSTASH_set(namesv, ourstash);
f84c484e 366 SvREFCNT_inc_simple_void_NN(ourstash);
dd2155a4 367 }
952306ac 368 else if (state) {
369 SvPAD_STATE_on(namesv);
370 }
dd2155a4 371
372 av_store(PL_comppad_name, offset, namesv);
b5c19bd7 373 if (fake) {
dd2155a4 374 SvFAKE_on(namesv);
b5c19bd7 375 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
376 "Pad addname: %ld \"%s\" FAKE\n", (long)offset, name));
377 }
dd2155a4 378 else {
ee6cee0c 379 /* not yet introduced */
809abb02 380 COP_SEQ_RANGE_LOW_set(namesv, PAD_MAX); /* min */
381 COP_SEQ_RANGE_HIGH_set(namesv, 0); /* max */
ee6cee0c 382
dd2155a4 383 if (!PL_min_intro_pending)
384 PL_min_intro_pending = offset;
385 PL_max_intro_pending = offset;
b5c19bd7 386 /* if it's not a simple scalar, replace with an AV or HV */
f3548bdc 387 /* XXX DAPM since slot has been allocated, replace
388 * av_store with PL_curpad[offset] ? */
dd2155a4 389 if (*name == '@')
390 av_store(PL_comppad, offset, (SV*)newAV());
391 else if (*name == '%')
392 av_store(PL_comppad, offset, (SV*)newHV());
393 SvPADMY_on(PL_curpad[offset]);
b5c19bd7 394 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
395 "Pad addname: %ld \"%s\" new lex=0x%"UVxf"\n",
396 (long)offset, name, PTR2UV(PL_curpad[offset])));
dd2155a4 397 }
398
399 return offset;
400}
401
402
403
404
405/*
406=for apidoc pad_alloc
407
408Allocate a new my or tmp pad entry. For a my, simply push a null SV onto
409the end of PL_comppad, but for a tmp, scan the pad from PL_padix upwards
cf525c36 410for a slot which has no name and no active value.
dd2155a4 411
412=cut
413*/
414
415/* XXX DAPM integrate alloc(), add_name() and add_anon(),
416 * or at least rationalise ??? */
6d640399 417/* And flag whether the incoming name is UTF8 or 8 bit?
418 Could do this either with the +ve/-ve hack of the HV code, or expanding
419 the flag bits. Either way, this makes proper Unicode safe pad support.
420 Also could change the sv structure to make the NV a union with 2 U32s,
421 so that SvCUR() could stop being overloaded in pad SVs.
422 NWC
423*/
dd2155a4 424
425PADOFFSET
426Perl_pad_alloc(pTHX_ I32 optype, U32 tmptype)
427{
97aff369 428 dVAR;
dd2155a4 429 SV *sv;
430 I32 retval;
431
6136c704 432 PERL_UNUSED_ARG(optype);
f3548bdc 433 ASSERT_CURPAD_ACTIVE("pad_alloc");
434
dd2155a4 435 if (AvARRAY(PL_comppad) != PL_curpad)
436 Perl_croak(aTHX_ "panic: pad_alloc");
437 if (PL_pad_reset_pending)
438 pad_reset();
439 if (tmptype & SVs_PADMY) {
235cc2e3 440 sv = *av_fetch(PL_comppad, AvFILLp(PL_comppad) + 1, TRUE);
dd2155a4 441 retval = AvFILLp(PL_comppad);
442 }
443 else {
551405c4 444 SV * const * const names = AvARRAY(PL_comppad_name);
e1ec3a88 445 const SSize_t names_fill = AvFILLp(PL_comppad_name);
dd2155a4 446 for (;;) {
447 /*
448 * "foreach" index vars temporarily become aliases to non-"my"
449 * values. Thus we must skip, not just pad values that are
450 * marked as current pad values, but also those with names.
451 */
452 /* HVDS why copy to sv here? we don't seem to use it */
453 if (++PL_padix <= names_fill &&
454 (sv = names[PL_padix]) && sv != &PL_sv_undef)
455 continue;
456 sv = *av_fetch(PL_comppad, PL_padix, TRUE);
457 if (!(SvFLAGS(sv) & (SVs_PADTMP | SVs_PADMY)) &&
458 !IS_PADGV(sv) && !IS_PADCONST(sv))
459 break;
460 }
461 retval = PL_padix;
462 }
463 SvFLAGS(sv) |= tmptype;
464 PL_curpad = AvARRAY(PL_comppad);
465
466 DEBUG_X(PerlIO_printf(Perl_debug_log,
467 "Pad 0x%"UVxf"[0x%"UVxf"] alloc: %ld for %s\n",
468 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long) retval,
469 PL_op_name[optype]));
fd0854ff 470#ifdef DEBUG_LEAKING_SCALARS
471 sv->sv_debug_optype = optype;
472 sv->sv_debug_inpad = 1;
fd0854ff 473#endif
a212c8b5 474 return (PADOFFSET)retval;
dd2155a4 475}
476
477/*
478=for apidoc pad_add_anon
479
480Add an anon code entry to the current compiling pad
481
482=cut
483*/
484
485PADOFFSET
486Perl_pad_add_anon(pTHX_ SV* sv, OPCODE op_type)
487{
97aff369 488 dVAR;
dd2155a4 489 PADOFFSET ix;
561b68a9 490 SV* const name = newSV(0);
1dba731d 491 pad_peg("add_anon");
dd2155a4 492 sv_upgrade(name, SVt_PVNV);
493 sv_setpvn(name, "&", 1);
809abb02 494 /* Are these two actually ever read? */
495 COP_SEQ_RANGE_HIGH_set(name, ~0);
496 COP_SEQ_RANGE_LOW_set(name, 1);
dd2155a4 497 ix = pad_alloc(op_type, SVs_PADMY);
498 av_store(PL_comppad_name, ix, name);
f3548bdc 499 /* XXX DAPM use PL_curpad[] ? */
dd2155a4 500 av_store(PL_comppad, ix, sv);
501 SvPADMY_on(sv);
7dafbf52 502
503 /* to avoid ref loops, we never have parent + child referencing each
504 * other simultaneously */
505 if (CvOUTSIDE((CV*)sv)) {
506 assert(!CvWEAKOUTSIDE((CV*)sv));
507 CvWEAKOUTSIDE_on((CV*)sv);
508 SvREFCNT_dec(CvOUTSIDE((CV*)sv));
509 }
dd2155a4 510 return ix;
511}
512
513
514
515/*
516=for apidoc pad_check_dup
517
518Check for duplicate declarations: report any of:
519 * a my in the current scope with the same name;
520 * an our (anywhere in the pad) with the same name and the same stash
521 as C<ourstash>
522C<is_our> indicates that the name to check is an 'our' declaration
523
524=cut
525*/
526
527/* XXX DAPM integrate this into pad_add_name ??? */
528
529void
e1ec3a88 530Perl_pad_check_dup(pTHX_ const char *name, bool is_our, const HV *ourstash)
dd2155a4 531{
97aff369 532 dVAR;
53c1dcc0 533 SV **svp;
dd2155a4 534 PADOFFSET top, off;
535
f3548bdc 536 ASSERT_CURPAD_ACTIVE("pad_check_dup");
041457d9 537 if (AvFILLp(PL_comppad_name) < 0 || !ckWARN(WARN_MISC))
dd2155a4 538 return; /* nothing to check */
539
540 svp = AvARRAY(PL_comppad_name);
541 top = AvFILLp(PL_comppad_name);
542 /* check the current scope */
543 /* XXX DAPM - why the (I32) cast - shouldn't we ensure they're the same
544 * type ? */
545 for (off = top; (I32)off > PL_comppad_name_floor; off--) {
53c1dcc0 546 SV * const sv = svp[off];
547 if (sv
dd2155a4 548 && sv != &PL_sv_undef
ee6cee0c 549 && !SvFAKE(sv)
809abb02 550 && (COP_SEQ_RANGE_HIGH(sv) == PAD_MAX || COP_SEQ_RANGE_HIGH(sv) == 0)
b15aece3 551 && strEQ(name, SvPVX_const(sv)))
dd2155a4 552 {
00b1698f 553 if (is_our && (SvPAD_OUR(sv)))
7f73a9f1 554 break; /* "our" masking "our" */
dd2155a4 555 Perl_warner(aTHX_ packWARN(WARN_MISC),
556 "\"%s\" variable %s masks earlier declaration in same %s",
952306ac 557 (is_our ? "our" : PL_in_my == KEY_my ? "my" : "state"),
dd2155a4 558 name,
809abb02 559 (COP_SEQ_RANGE_HIGH(sv) == PAD_MAX ? "scope" : "statement"));
dd2155a4 560 --off;
561 break;
562 }
563 }
564 /* check the rest of the pad */
565 if (is_our) {
566 do {
53c1dcc0 567 SV * const sv = svp[off];
568 if (sv
dd2155a4 569 && sv != &PL_sv_undef
ee6cee0c 570 && !SvFAKE(sv)
809abb02 571 && (COP_SEQ_RANGE_HIGH(sv) == PAD_MAX || COP_SEQ_RANGE_HIGH(sv) == 0)
035dab74 572 && OURSTASH(sv) == ourstash
b15aece3 573 && strEQ(name, SvPVX_const(sv)))
dd2155a4 574 {
575 Perl_warner(aTHX_ packWARN(WARN_MISC),
576 "\"our\" variable %s redeclared", name);
624f69f5 577 if ((I32)off <= PL_comppad_name_floor)
7f73a9f1 578 Perl_warner(aTHX_ packWARN(WARN_MISC),
579 "\t(Did you mean \"local\" instead of \"our\"?)\n");
dd2155a4 580 break;
581 }
582 } while ( off-- > 0 );
583 }
584}
585
586
dd2155a4 587/*
588=for apidoc pad_findmy
589
590Given a lexical name, try to find its offset, first in the current pad,
591or failing that, in the pads of any lexically enclosing subs (including
592the complications introduced by eval). If the name is found in an outer pad,
593then a fake entry is added to the current pad.
594Returns the offset in the current pad, or NOT_IN_PAD on failure.
595
596=cut
597*/
598
599PADOFFSET
e1ec3a88 600Perl_pad_findmy(pTHX_ const char *name)
dd2155a4 601{
97aff369 602 dVAR;
b5c19bd7 603 SV *out_sv;
604 int out_flags;
929a0744 605 I32 offset;
e1ec3a88 606 const AV *nameav;
929a0744 607 SV **name_svp;
dd2155a4 608
1dba731d 609 pad_peg("pad_findmy");
9f7d9405 610 offset = pad_findlex(name, PL_compcv, PL_cop_seqmax, 1,
4608196e 611 NULL, &out_sv, &out_flags);
9f7d9405 612 if ((PADOFFSET)offset != NOT_IN_PAD)
929a0744 613 return offset;
614
615 /* look for an our that's being introduced; this allows
616 * our $foo = 0 unless defined $foo;
617 * to not give a warning. (Yes, this is a hack) */
618
619 nameav = (AV*)AvARRAY(CvPADLIST(PL_compcv))[0];
620 name_svp = AvARRAY(nameav);
621 for (offset = AvFILLp(nameav); offset > 0; offset--) {
551405c4 622 const SV * const namesv = name_svp[offset];
929a0744 623 if (namesv && namesv != &PL_sv_undef
624 && !SvFAKE(namesv)
00b1698f 625 && (SvPAD_OUR(namesv))
b15aece3 626 && strEQ(SvPVX_const(namesv), name)
809abb02 627 && COP_SEQ_RANGE_LOW(namesv) == PAD_MAX /* min */
929a0744 628 )
629 return offset;
630 }
631 return NOT_IN_PAD;
dd2155a4 632}
633
e1f795dc 634/*
635 * Returns the offset of a lexical $_, if there is one, at run time.
636 * Used by the UNDERBAR XS macro.
637 */
638
639PADOFFSET
29289021 640Perl_find_rundefsvoffset(pTHX)
e1f795dc 641{
97aff369 642 dVAR;
e1f795dc 643 SV *out_sv;
644 int out_flags;
645 return pad_findlex("$_", find_runcv(NULL), PL_curcop->cop_seq, 1,
4608196e 646 NULL, &out_sv, &out_flags);
e1f795dc 647}
dd2155a4 648
dd2155a4 649/*
650=for apidoc pad_findlex
651
652Find a named lexical anywhere in a chain of nested pads. Add fake entries
b5c19bd7 653in the inner pads if it's found in an outer one.
654
655Returns the offset in the bottom pad of the lex or the fake lex.
656cv is the CV in which to start the search, and seq is the current cop_seq
657to match against. If warn is true, print appropriate warnings. The out_*
658vars return values, and so are pointers to where the returned values
659should be stored. out_capture, if non-null, requests that the innermost
660instance of the lexical is captured; out_name_sv is set to the innermost
661matched namesv or fake namesv; out_flags returns the flags normally
662associated with the IVX field of a fake namesv.
663
664Note that pad_findlex() is recursive; it recurses up the chain of CVs,
665then comes back down, adding fake entries as it goes. It has to be this way
3441fb63 666because fake namesvs in anon protoypes have to store in xlow the index into
b5c19bd7 667the parent pad.
dd2155a4 668
669=cut
670*/
671
b5c19bd7 672/* the CV has finished being compiled. This is not a sufficient test for
673 * all CVs (eg XSUBs), but suffices for the CVs found in a lexical chain */
674#define CvCOMPILED(cv) CvROOT(cv)
675
71f882da 676/* the CV does late binding of its lexicals */
677#define CvLATE(cv) (CvANON(cv) || SvTYPE(cv) == SVt_PVFM)
678
b5c19bd7 679
dd2155a4 680STATIC PADOFFSET
e1ec3a88 681S_pad_findlex(pTHX_ const char *name, const CV* cv, U32 seq, int warn,
b5c19bd7 682 SV** out_capture, SV** out_name_sv, int *out_flags)
dd2155a4 683{
97aff369 684 dVAR;
b5c19bd7 685 I32 offset, new_offset;
686 SV *new_capture;
687 SV **new_capturep;
b64e5050 688 const AV * const padlist = CvPADLIST(cv);
dd2155a4 689
b5c19bd7 690 *out_flags = 0;
a3985cdc 691
b5c19bd7 692 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
693 "Pad findlex cv=0x%"UVxf" searching \"%s\" seq=%d%s\n",
694 PTR2UV(cv), name, (int)seq, out_capture ? " capturing" : "" ));
dd2155a4 695
b5c19bd7 696 /* first, search this pad */
dd2155a4 697
b5c19bd7 698 if (padlist) { /* not an undef CV */
699 I32 fake_offset = 0;
551405c4 700 const AV * const nameav = (AV*)AvARRAY(padlist)[0];
701 SV * const * const name_svp = AvARRAY(nameav);
ee6cee0c 702
b5c19bd7 703 for (offset = AvFILLp(nameav); offset > 0; offset--) {
551405c4 704 const SV * const namesv = name_svp[offset];
b5c19bd7 705 if (namesv && namesv != &PL_sv_undef
b15aece3 706 && strEQ(SvPVX_const(namesv), name))
b5c19bd7 707 {
708 if (SvFAKE(namesv))
709 fake_offset = offset; /* in case we don't find a real one */
809abb02 710 else if ( seq > COP_SEQ_RANGE_LOW(namesv) /* min */
711 && seq <= COP_SEQ_RANGE_HIGH(namesv)) /* max */
b5c19bd7 712 break;
ee6cee0c 713 }
714 }
715
b5c19bd7 716 if (offset > 0 || fake_offset > 0 ) { /* a match! */
717 if (offset > 0) { /* not fake */
718 fake_offset = 0;
719 *out_name_sv = name_svp[offset]; /* return the namesv */
720
721 /* set PAD_FAKELEX_MULTI if this lex can have multiple
722 * instances. For now, we just test !CvUNIQUE(cv), but
723 * ideally, we should detect my's declared within loops
724 * etc - this would allow a wider range of 'not stayed
725 * shared' warnings. We also treated alreadly-compiled
726 * lexes as not multi as viewed from evals. */
727
728 *out_flags = CvANON(cv) ?
729 PAD_FAKELEX_ANON :
730 (!CvUNIQUE(cv) && ! CvCOMPILED(cv))
731 ? PAD_FAKELEX_MULTI : 0;
732
733 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
809abb02 734 "Pad findlex cv=0x%"UVxf" matched: offset=%ld (%lu,%lu)\n",
735 PTR2UV(cv), (long)offset,
736 (unsigned long)COP_SEQ_RANGE_LOW(*out_name_sv),
737 (unsigned long)COP_SEQ_RANGE_HIGH(*out_name_sv)));
b5c19bd7 738 }
739 else { /* fake match */
740 offset = fake_offset;
741 *out_name_sv = name_svp[offset]; /* return the namesv */
809abb02 742 *out_flags = PARENT_FAKELEX_FLAGS(*out_name_sv);
b5c19bd7 743 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
19a5c512 744 "Pad findlex cv=0x%"UVxf" matched: offset=%ld flags=0x%lx index=%lu\n",
b5c19bd7 745 PTR2UV(cv), (long)offset, (unsigned long)*out_flags,
809abb02 746 (unsigned long) PARENT_PAD_INDEX(*out_name_sv)
b5c19bd7 747 ));
748 }
dd2155a4 749
b5c19bd7 750 /* return the lex? */
dd2155a4 751
b5c19bd7 752 if (out_capture) {
dd2155a4 753
b5c19bd7 754 /* our ? */
00b1698f 755 if (SvPAD_OUR(*out_name_sv)) {
a0714e2c 756 *out_capture = NULL;
b5c19bd7 757 return offset;
758 }
ee6cee0c 759
b5c19bd7 760 /* trying to capture from an anon prototype? */
761 if (CvCOMPILED(cv)
762 ? CvANON(cv) && CvCLONE(cv) && !CvCLONED(cv)
763 : *out_flags & PAD_FAKELEX_ANON)
764 {
765 if (warn && ckWARN(WARN_CLOSURE))
766 Perl_warner(aTHX_ packWARN(WARN_CLOSURE),
767 "Variable \"%s\" is not available", name);
a0714e2c 768 *out_capture = NULL;
b5c19bd7 769 }
ee6cee0c 770
b5c19bd7 771 /* real value */
772 else {
773 int newwarn = warn;
774 if (!CvCOMPILED(cv) && (*out_flags & PAD_FAKELEX_MULTI)
775 && warn && ckWARN(WARN_CLOSURE)) {
776 newwarn = 0;
777 Perl_warner(aTHX_ packWARN(WARN_CLOSURE),
778 "Variable \"%s\" will not stay shared", name);
779 }
dd2155a4 780
b5c19bd7 781 if (fake_offset && CvANON(cv)
782 && CvCLONE(cv) &&!CvCLONED(cv))
783 {
784 SV *n;
785 /* not yet caught - look further up */
786 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
787 "Pad findlex cv=0x%"UVxf" chasing lex in outer pad\n",
788 PTR2UV(cv)));
789 n = *out_name_sv;
282e1742 790 (void) pad_findlex(name, CvOUTSIDE(cv),
791 CvOUTSIDE_SEQ(cv),
b5c19bd7 792 newwarn, out_capture, out_name_sv, out_flags);
793 *out_name_sv = n;
794 return offset;
dd2155a4 795 }
b5c19bd7 796
797 *out_capture = AvARRAY((AV*)AvARRAY(padlist)[
798 CvDEPTH(cv) ? CvDEPTH(cv) : 1])[offset];
799 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
800 "Pad findlex cv=0x%"UVxf" found lex=0x%"UVxf"\n",
19a5c512 801 PTR2UV(cv), PTR2UV(*out_capture)));
b5c19bd7 802
803 if (SvPADSTALE(*out_capture)) {
804 if (ckWARN(WARN_CLOSURE))
ee6cee0c 805 Perl_warner(aTHX_ packWARN(WARN_CLOSURE),
b5c19bd7 806 "Variable \"%s\" is not available", name);
a0714e2c 807 *out_capture = NULL;
dd2155a4 808 }
809 }
b5c19bd7 810 if (!*out_capture) {
811 if (*name == '@')
812 *out_capture = sv_2mortal((SV*)newAV());
813 else if (*name == '%')
814 *out_capture = sv_2mortal((SV*)newHV());
815 else
816 *out_capture = sv_newmortal();
817 }
dd2155a4 818 }
b5c19bd7 819
820 return offset;
ee6cee0c 821 }
b5c19bd7 822 }
823
824 /* it's not in this pad - try above */
825
826 if (!CvOUTSIDE(cv))
827 return NOT_IN_PAD;
9f7d9405 828
b5c19bd7 829 /* out_capture non-null means caller wants us to capture lex; in
71f882da 830 * addition we capture ourselves unless it's an ANON/format */
b5c19bd7 831 new_capturep = out_capture ? out_capture :
4608196e 832 CvLATE(cv) ? NULL : &new_capture;
b5c19bd7 833
834 offset = pad_findlex(name, CvOUTSIDE(cv), CvOUTSIDE_SEQ(cv), 1,
835 new_capturep, out_name_sv, out_flags);
9f7d9405 836 if ((PADOFFSET)offset == NOT_IN_PAD)
b5c19bd7 837 return NOT_IN_PAD;
9f7d9405 838
b5c19bd7 839 /* found in an outer CV. Add appropriate fake entry to this pad */
840
841 /* don't add new fake entries (via eval) to CVs that we have already
842 * finished compiling, or to undef CVs */
843 if (CvCOMPILED(cv) || !padlist)
844 return 0; /* this dummy (and invalid) value isnt used by the caller */
845
846 {
847 SV *new_namesv;
53c1dcc0 848 AV * const ocomppad_name = PL_comppad_name;
849 PAD * const ocomppad = PL_comppad;
b5c19bd7 850 PL_comppad_name = (AV*)AvARRAY(padlist)[0];
851 PL_comppad = (AV*)AvARRAY(padlist)[1];
852 PL_curpad = AvARRAY(PL_comppad);
853
854 new_offset = pad_add_name(
b15aece3 855 SvPVX_const(*out_name_sv),
00b1698f 856 SvPAD_TYPED(*out_name_sv)
5c284bb0 857 ? SvSTASH(*out_name_sv) : NULL,
035dab74 858 OURSTASH(*out_name_sv),
952306ac 859 1, /* fake */
860 0 /* not a state variable */
b5c19bd7 861 );
862
863 new_namesv = AvARRAY(PL_comppad_name)[new_offset];
809abb02 864 PARENT_FAKELEX_FLAGS_set(new_namesv, *out_flags);
b5c19bd7 865
809abb02 866 PARENT_PAD_INDEX_set(new_namesv, 0);
00b1698f 867 if (SvPAD_OUR(new_namesv)) {
6f207bd3 868 NOOP; /* do nothing */
b5c19bd7 869 }
71f882da 870 else if (CvLATE(cv)) {
b5c19bd7 871 /* delayed creation - just note the offset within parent pad */
809abb02 872 PARENT_PAD_INDEX_set(new_namesv, offset);
b5c19bd7 873 CvCLONE_on(cv);
874 }
875 else {
876 /* immediate creation - capture outer value right now */
877 av_store(PL_comppad, new_offset, SvREFCNT_inc(*new_capturep));
878 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
879 "Pad findlex cv=0x%"UVxf" saved captured sv 0x%"UVxf" at offset %ld\n",
880 PTR2UV(cv), PTR2UV(*new_capturep), (long)new_offset));
dd2155a4 881 }
b5c19bd7 882 *out_name_sv = new_namesv;
809abb02 883 *out_flags = PARENT_FAKELEX_FLAGS(new_namesv);
b5c19bd7 884
885 PL_comppad_name = ocomppad_name;
886 PL_comppad = ocomppad;
4608196e 887 PL_curpad = ocomppad ? AvARRAY(ocomppad) : NULL;
dd2155a4 888 }
b5c19bd7 889 return new_offset;
dd2155a4 890}
891
fb8a9836 892
893#ifdef DEBUGGING
dd2155a4 894/*
895=for apidoc pad_sv
896
897Get the value at offset po in the current pad.
898Use macro PAD_SV instead of calling this function directly.
899
900=cut
901*/
902
903
904SV *
905Perl_pad_sv(pTHX_ PADOFFSET po)
906{
97aff369 907 dVAR;
f3548bdc 908 ASSERT_CURPAD_ACTIVE("pad_sv");
dd2155a4 909
dd2155a4 910 if (!po)
911 Perl_croak(aTHX_ "panic: pad_sv po");
dd2155a4 912 DEBUG_X(PerlIO_printf(Perl_debug_log,
913 "Pad 0x%"UVxf"[0x%"UVxf"] sv: %ld sv=0x%"UVxf"\n",
f3548bdc 914 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)po, PTR2UV(PL_curpad[po]))
dd2155a4 915 );
916 return PL_curpad[po];
917}
918
919
920/*
921=for apidoc pad_setsv
922
923Set the entry at offset po in the current pad to sv.
924Use the macro PAD_SETSV() rather than calling this function directly.
925
926=cut
927*/
928
dd2155a4 929void
930Perl_pad_setsv(pTHX_ PADOFFSET po, SV* sv)
931{
97aff369 932 dVAR;
f3548bdc 933 ASSERT_CURPAD_ACTIVE("pad_setsv");
dd2155a4 934
935 DEBUG_X(PerlIO_printf(Perl_debug_log,
936 "Pad 0x%"UVxf"[0x%"UVxf"] setsv: %ld sv=0x%"UVxf"\n",
f3548bdc 937 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)po, PTR2UV(sv))
dd2155a4 938 );
939 PL_curpad[po] = sv;
940}
941#endif
942
943
944
945/*
946=for apidoc pad_block_start
947
948Update the pad compilation state variables on entry to a new block
949
950=cut
951*/
952
953/* XXX DAPM perhaps:
954 * - integrate this in general state-saving routine ???
955 * - combine with the state-saving going on in pad_new ???
956 * - introduce a new SAVE type that does all this in one go ?
957 */
958
959void
960Perl_pad_block_start(pTHX_ int full)
961{
97aff369 962 dVAR;
f3548bdc 963 ASSERT_CURPAD_ACTIVE("pad_block_start");
dd2155a4 964 SAVEI32(PL_comppad_name_floor);
965 PL_comppad_name_floor = AvFILLp(PL_comppad_name);
966 if (full)
967 PL_comppad_name_fill = PL_comppad_name_floor;
968 if (PL_comppad_name_floor < 0)
969 PL_comppad_name_floor = 0;
970 SAVEI32(PL_min_intro_pending);
971 SAVEI32(PL_max_intro_pending);
972 PL_min_intro_pending = 0;
973 SAVEI32(PL_comppad_name_fill);
974 SAVEI32(PL_padix_floor);
975 PL_padix_floor = PL_padix;
976 PL_pad_reset_pending = FALSE;
977}
978
979
980/*
981=for apidoc intro_my
982
983"Introduce" my variables to visible status.
984
985=cut
986*/
987
988U32
989Perl_intro_my(pTHX)
990{
97aff369 991 dVAR;
dd2155a4 992 SV **svp;
dd2155a4 993 I32 i;
994
f3548bdc 995 ASSERT_CURPAD_ACTIVE("intro_my");
dd2155a4 996 if (! PL_min_intro_pending)
997 return PL_cop_seqmax;
998
999 svp = AvARRAY(PL_comppad_name);
1000 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
53c1dcc0 1001 SV * const sv = svp[i];
1002
809abb02 1003 if (sv && sv != &PL_sv_undef && !SvFAKE(sv) && !COP_SEQ_RANGE_HIGH(sv)) {
1004 COP_SEQ_RANGE_HIGH_set(sv, PAD_MAX); /* Don't know scope end yet. */
1005 COP_SEQ_RANGE_LOW_set(sv, PL_cop_seqmax);
dd2155a4 1006 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
809abb02 1007 "Pad intromy: %ld \"%s\", (%lu,%lu)\n",
b15aece3 1008 (long)i, SvPVX_const(sv),
809abb02 1009 (unsigned long)COP_SEQ_RANGE_LOW(sv),
1010 (unsigned long)COP_SEQ_RANGE_HIGH(sv))
dd2155a4 1011 );
1012 }
1013 }
1014 PL_min_intro_pending = 0;
1015 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
1016 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
1017 "Pad intromy: seq -> %ld\n", (long)(PL_cop_seqmax+1)));
1018
1019 return PL_cop_seqmax++;
1020}
1021
1022/*
1023=for apidoc pad_leavemy
1024
1025Cleanup at end of scope during compilation: set the max seq number for
1026lexicals in this scope and warn of any lexicals that never got introduced.
1027
1028=cut
1029*/
1030
1031void
1032Perl_pad_leavemy(pTHX)
1033{
97aff369 1034 dVAR;
dd2155a4 1035 I32 off;
551405c4 1036 SV * const * const svp = AvARRAY(PL_comppad_name);
dd2155a4 1037
1038 PL_pad_reset_pending = FALSE;
1039
f3548bdc 1040 ASSERT_CURPAD_ACTIVE("pad_leavemy");
dd2155a4 1041 if (PL_min_intro_pending && PL_comppad_name_fill < PL_min_intro_pending) {
1042 for (off = PL_max_intro_pending; off >= PL_min_intro_pending; off--) {
53c1dcc0 1043 const SV * const sv = svp[off];
1044 if (sv && sv != &PL_sv_undef
ee6cee0c 1045 && !SvFAKE(sv) && ckWARN_d(WARN_INTERNAL))
dd2155a4 1046 Perl_warner(aTHX_ packWARN(WARN_INTERNAL),
95b63a38 1047 "%"SVf" never introduced",
1048 (void*)sv);
dd2155a4 1049 }
1050 }
1051 /* "Deintroduce" my variables that are leaving with this scope. */
1052 for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_fill; off--) {
53c1dcc0 1053 const SV * const sv = svp[off];
809abb02 1054 if (sv && sv != &PL_sv_undef && !SvFAKE(sv) && COP_SEQ_RANGE_HIGH(sv) == PAD_MAX) {
1055 COP_SEQ_RANGE_HIGH_set(sv, PL_cop_seqmax);
dd2155a4 1056 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
809abb02 1057 "Pad leavemy: %ld \"%s\", (%lu,%lu)\n",
b15aece3 1058 (long)off, SvPVX_const(sv),
809abb02 1059 (unsigned long)COP_SEQ_RANGE_LOW(sv),
1060 (unsigned long)COP_SEQ_RANGE_HIGH(sv))
dd2155a4 1061 );
1062 }
1063 }
1064 PL_cop_seqmax++;
1065 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
1066 "Pad leavemy: seq = %ld\n", (long)PL_cop_seqmax));
1067}
1068
1069
1070/*
1071=for apidoc pad_swipe
1072
1073Abandon the tmp in the current pad at offset po and replace with a
1074new one.
1075
1076=cut
1077*/
1078
1079void
1080Perl_pad_swipe(pTHX_ PADOFFSET po, bool refadjust)
1081{
97aff369 1082 dVAR;
f3548bdc 1083 ASSERT_CURPAD_LEGAL("pad_swipe");
dd2155a4 1084 if (!PL_curpad)
1085 return;
1086 if (AvARRAY(PL_comppad) != PL_curpad)
1087 Perl_croak(aTHX_ "panic: pad_swipe curpad");
1088 if (!po)
1089 Perl_croak(aTHX_ "panic: pad_swipe po");
1090
1091 DEBUG_X(PerlIO_printf(Perl_debug_log,
1092 "Pad 0x%"UVxf"[0x%"UVxf"] swipe: %ld\n",
1093 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)po));
1094
1095 if (PL_curpad[po])
1096 SvPADTMP_off(PL_curpad[po]);
1097 if (refadjust)
1098 SvREFCNT_dec(PL_curpad[po]);
1099
9ad9869c 1100
1101 /* if pad tmps aren't shared between ops, then there's no need to
1102 * create a new tmp when an existing op is freed */
1103#ifdef USE_BROKEN_PAD_RESET
561b68a9 1104 PL_curpad[po] = newSV(0);
dd2155a4 1105 SvPADTMP_on(PL_curpad[po]);
9ad9869c 1106#else
1107 PL_curpad[po] = &PL_sv_undef;
97bf4a8d 1108#endif
dd2155a4 1109 if ((I32)po < PL_padix)
1110 PL_padix = po - 1;
1111}
1112
1113
1114/*
1115=for apidoc pad_reset
1116
1117Mark all the current temporaries for reuse
1118
1119=cut
1120*/
1121
1122/* XXX pad_reset() is currently disabled because it results in serious bugs.
1123 * It causes pad temp TARGs to be shared between OPs. Since TARGs are pushed
1124 * on the stack by OPs that use them, there are several ways to get an alias
1125 * to a shared TARG. Such an alias will change randomly and unpredictably.
1126 * We avoid doing this until we can think of a Better Way.
1127 * GSAR 97-10-29 */
1128void
1129Perl_pad_reset(pTHX)
1130{
97aff369 1131 dVAR;
dd2155a4 1132#ifdef USE_BROKEN_PAD_RESET
dd2155a4 1133 if (AvARRAY(PL_comppad) != PL_curpad)
1134 Perl_croak(aTHX_ "panic: pad_reset curpad");
1135
1136 DEBUG_X(PerlIO_printf(Perl_debug_log,
1137 "Pad 0x%"UVxf"[0x%"UVxf"] reset: padix %ld -> %ld",
1138 PTR2UV(PL_comppad), PTR2UV(PL_curpad),
1139 (long)PL_padix, (long)PL_padix_floor
1140 )
1141 );
1142
1143 if (!PL_tainting) { /* Can't mix tainted and non-tainted temporaries. */
e1ec3a88 1144 register I32 po;
dd2155a4 1145 for (po = AvMAX(PL_comppad); po > PL_padix_floor; po--) {
1146 if (PL_curpad[po] && !SvIMMORTAL(PL_curpad[po]))
1147 SvPADTMP_off(PL_curpad[po]);
1148 }
1149 PL_padix = PL_padix_floor;
1150 }
1151#endif
1152 PL_pad_reset_pending = FALSE;
1153}
1154
1155
1156/*
1157=for apidoc pad_tidy
1158
1159Tidy up a pad after we've finished compiling it:
1160 * remove most stuff from the pads of anonsub prototypes;
1161 * give it a @_;
1162 * mark tmps as such.
1163
1164=cut
1165*/
1166
1167/* XXX DAPM surely most of this stuff should be done properly
1168 * at the right time beforehand, rather than going around afterwards
1169 * cleaning up our mistakes ???
1170 */
1171
1172void
1173Perl_pad_tidy(pTHX_ padtidy_type type)
1174{
27da23d5 1175 dVAR;
dd2155a4 1176
f3548bdc 1177 ASSERT_CURPAD_ACTIVE("pad_tidy");
b5c19bd7 1178
1179 /* If this CV has had any 'eval-capable' ops planted in it
1180 * (ie it contains eval '...', //ee, /$var/ or /(?{..})/), Then any
1181 * anon prototypes in the chain of CVs should be marked as cloneable,
1182 * so that for example the eval's CV in C<< sub { eval '$x' } >> gets
1183 * the right CvOUTSIDE.
1184 * If running with -d, *any* sub may potentially have an eval
1185 * excuted within it.
1186 */
1187
1188 if (PL_cv_has_eval || PL_perldb) {
e1ec3a88 1189 const CV *cv;
b5c19bd7 1190 for (cv = PL_compcv ;cv; cv = CvOUTSIDE(cv)) {
1191 if (cv != PL_compcv && CvCOMPILED(cv))
1192 break; /* no need to mark already-compiled code */
1193 if (CvANON(cv)) {
1194 DEBUG_Xv(PerlIO_printf(Perl_debug_log,
1195 "Pad clone on cv=0x%"UVxf"\n", PTR2UV(cv)));
1196 CvCLONE_on(cv);
1197 }
1198 }
1199 }
1200
dd2155a4 1201 /* extend curpad to match namepad */
1202 if (AvFILLp(PL_comppad_name) < AvFILLp(PL_comppad))
a0714e2c 1203 av_store(PL_comppad_name, AvFILLp(PL_comppad), NULL);
dd2155a4 1204
1205 if (type == padtidy_SUBCLONE) {
551405c4 1206 SV * const * const namep = AvARRAY(PL_comppad_name);
504618e9 1207 PADOFFSET ix;
b5c19bd7 1208
dd2155a4 1209 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
1210 SV *namesv;
1211
1212 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
1213 continue;
1214 /*
1215 * The only things that a clonable function needs in its
b5c19bd7 1216 * pad are anonymous subs.
dd2155a4 1217 * The rest are created anew during cloning.
1218 */
a0714e2c 1219 if (!((namesv = namep[ix]) != NULL &&
dd2155a4 1220 namesv != &PL_sv_undef &&
b15aece3 1221 *SvPVX_const(namesv) == '&'))
dd2155a4 1222 {
1223 SvREFCNT_dec(PL_curpad[ix]);
a0714e2c 1224 PL_curpad[ix] = NULL;
dd2155a4 1225 }
1226 }
1227 }
1228 else if (type == padtidy_SUB) {
1229 /* XXX DAPM this same bit of code keeps appearing !!! Rationalise? */
53c1dcc0 1230 AV * const av = newAV(); /* Will be @_ */
dd2155a4 1231 av_extend(av, 0);
1232 av_store(PL_comppad, 0, (SV*)av);
11ca45c0 1233 AvREIFY_only(av);
dd2155a4 1234 }
1235
1236 /* XXX DAPM rationalise these two similar branches */
1237
1238 if (type == padtidy_SUB) {
504618e9 1239 PADOFFSET ix;
dd2155a4 1240 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
1241 if (SvIMMORTAL(PL_curpad[ix]) || IS_PADGV(PL_curpad[ix]) || IS_PADCONST(PL_curpad[ix]))
1242 continue;
1243 if (!SvPADMY(PL_curpad[ix]))
1244 SvPADTMP_on(PL_curpad[ix]);
1245 }
1246 }
1247 else if (type == padtidy_FORMAT) {
504618e9 1248 PADOFFSET ix;
dd2155a4 1249 for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
1250 if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))
1251 SvPADTMP_on(PL_curpad[ix]);
1252 }
1253 }
f3548bdc 1254 PL_curpad = AvARRAY(PL_comppad);
dd2155a4 1255}
1256
1257
1258/*
1259=for apidoc pad_free
1260
8627550a 1261Free the SV at offset po in the current pad.
dd2155a4 1262
1263=cut
1264*/
1265
1266/* XXX DAPM integrate with pad_swipe ???? */
1267void
1268Perl_pad_free(pTHX_ PADOFFSET po)
1269{
97aff369 1270 dVAR;
f3548bdc 1271 ASSERT_CURPAD_LEGAL("pad_free");
dd2155a4 1272 if (!PL_curpad)
1273 return;
1274 if (AvARRAY(PL_comppad) != PL_curpad)
1275 Perl_croak(aTHX_ "panic: pad_free curpad");
1276 if (!po)
1277 Perl_croak(aTHX_ "panic: pad_free po");
1278
1279 DEBUG_X(PerlIO_printf(Perl_debug_log,
1280 "Pad 0x%"UVxf"[0x%"UVxf"] free: %ld\n",
1281 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (long)po)
1282 );
1283
1284 if (PL_curpad[po] && PL_curpad[po] != &PL_sv_undef) {
1285 SvPADTMP_off(PL_curpad[po]);
1286#ifdef USE_ITHREADS
7e736055 1287 /* SV could be a shared hash key (eg bugid #19022) */
1288 if (
f8c7b90f 1289#ifdef PERL_OLD_COPY_ON_WRITE
7e736055 1290 !SvIsCOW(PL_curpad[po])
1291#else
1292 !SvFAKE(PL_curpad[po])
dd2155a4 1293#endif
7e736055 1294 )
dd2155a4 1295 SvREADONLY_off(PL_curpad[po]); /* could be a freed constant */
dd2155a4 1296#endif
1297 }
1298 if ((I32)po < PL_padix)
1299 PL_padix = po - 1;
1300}
1301
1302
1303
1304/*
1305=for apidoc do_dump_pad
1306
1307Dump the contents of a padlist
1308
1309=cut
1310*/
1311
1312void
1313Perl_do_dump_pad(pTHX_ I32 level, PerlIO *file, PADLIST *padlist, int full)
1314{
97aff369 1315 dVAR;
e1ec3a88 1316 const AV *pad_name;
1317 const AV *pad;
dd2155a4 1318 SV **pname;
1319 SV **ppad;
dd2155a4 1320 I32 ix;
1321
1322 if (!padlist) {
1323 return;
1324 }
1325 pad_name = (AV*)*av_fetch((AV*)padlist, 0, FALSE);
1326 pad = (AV*)*av_fetch((AV*)padlist, 1, FALSE);
1327 pname = AvARRAY(pad_name);
1328 ppad = AvARRAY(pad);
1329 Perl_dump_indent(aTHX_ level, file,
1330 "PADNAME = 0x%"UVxf"(0x%"UVxf") PAD = 0x%"UVxf"(0x%"UVxf")\n",
1331 PTR2UV(pad_name), PTR2UV(pname), PTR2UV(pad), PTR2UV(ppad)
1332 );
1333
1334 for (ix = 1; ix <= AvFILLp(pad_name); ix++) {
e1ec3a88 1335 const SV *namesv = pname[ix];
dd2155a4 1336 if (namesv && namesv == &PL_sv_undef) {
a0714e2c 1337 namesv = NULL;
dd2155a4 1338 }
1339 if (namesv) {
ee6cee0c 1340 if (SvFAKE(namesv))
1341 Perl_dump_indent(aTHX_ level+1, file,
c0fd1b42 1342 "%2d. 0x%"UVxf"<%lu> FAKE \"%s\" flags=0x%lx index=%lu\n",
ee6cee0c 1343 (int) ix,
1344 PTR2UV(ppad[ix]),
1345 (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0),
b15aece3 1346 SvPVX_const(namesv),
809abb02 1347 (unsigned long)PARENT_FAKELEX_FLAGS(namesv),
1348 (unsigned long)PARENT_PAD_INDEX(namesv)
b5c19bd7 1349
ee6cee0c 1350 );
1351 else
1352 Perl_dump_indent(aTHX_ level+1, file,
809abb02 1353 "%2d. 0x%"UVxf"<%lu> (%lu,%lu) \"%s\"\n",
ee6cee0c 1354 (int) ix,
1355 PTR2UV(ppad[ix]),
1356 (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0),
809abb02 1357 (unsigned long)COP_SEQ_RANGE_LOW(namesv),
1358 (unsigned long)COP_SEQ_RANGE_HIGH(namesv),
b15aece3 1359 SvPVX_const(namesv)
ee6cee0c 1360 );
dd2155a4 1361 }
1362 else if (full) {
1363 Perl_dump_indent(aTHX_ level+1, file,
1364 "%2d. 0x%"UVxf"<%lu>\n",
1365 (int) ix,
1366 PTR2UV(ppad[ix]),
1367 (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0)
1368 );
1369 }
1370 }
1371}
1372
1373
1374
1375/*
1376=for apidoc cv_dump
1377
1378dump the contents of a CV
1379
1380=cut
1381*/
1382
1383#ifdef DEBUGGING
1384STATIC void
e1ec3a88 1385S_cv_dump(pTHX_ const CV *cv, const char *title)
dd2155a4 1386{
97aff369 1387 dVAR;
53c1dcc0 1388 const CV * const outside = CvOUTSIDE(cv);
1389 AV* const padlist = CvPADLIST(cv);
dd2155a4 1390
1391 PerlIO_printf(Perl_debug_log,
1392 " %s: CV=0x%"UVxf" (%s), OUTSIDE=0x%"UVxf" (%s)\n",
1393 title,
1394 PTR2UV(cv),
1395 (CvANON(cv) ? "ANON"
71f882da 1396 : (SvTYPE(cv) == SVt_PVFM) ? "FORMAT"
dd2155a4 1397 : (cv == PL_main_cv) ? "MAIN"
1398 : CvUNIQUE(cv) ? "UNIQUE"
1399 : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"),
1400 PTR2UV(outside),
1401 (!outside ? "null"
1402 : CvANON(outside) ? "ANON"
1403 : (outside == PL_main_cv) ? "MAIN"
1404 : CvUNIQUE(outside) ? "UNIQUE"
1405 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
1406
1407 PerlIO_printf(Perl_debug_log,
1408 " PADLIST = 0x%"UVxf"\n", PTR2UV(padlist));
1409 do_dump_pad(1, Perl_debug_log, padlist, 1);
1410}
1411#endif /* DEBUGGING */
1412
1413
1414
1415
1416
1417/*
1418=for apidoc cv_clone
1419
1420Clone a CV: make a new CV which points to the same code etc, but which
1421has a newly-created pad built by copying the prototype pad and capturing
1422any outer lexicals.
1423
1424=cut
1425*/
1426
1427CV *
1428Perl_cv_clone(pTHX_ CV *proto)
1429{
27da23d5 1430 dVAR;
dd2155a4 1431 I32 ix;
53c1dcc0 1432 AV* const protopadlist = CvPADLIST(proto);
1433 const AV* const protopad_name = (AV*)*av_fetch(protopadlist, 0, FALSE);
1434 const AV* const protopad = (AV*)*av_fetch(protopadlist, 1, FALSE);
1435 SV** const pname = AvARRAY(protopad_name);
1436 SV** const ppad = AvARRAY(protopad);
e1ec3a88 1437 const I32 fname = AvFILLp(protopad_name);
1438 const I32 fpad = AvFILLp(protopad);
dd2155a4 1439 CV* cv;
b5c19bd7 1440 SV** outpad;
1441 CV* outside;
71f882da 1442 long depth;
dd2155a4 1443
1444 assert(!CvUNIQUE(proto));
1445
71f882da 1446 /* Since cloneable anon subs can be nested, CvOUTSIDE may point
1447 * to a prototype; we instead want the cloned parent who called us.
1448 * Note that in general for formats, CvOUTSIDE != find_runcv */
1449
1450 outside = CvOUTSIDE(proto);
1451 if (outside && CvCLONE(outside) && ! CvCLONED(outside))
1452 outside = find_runcv(NULL);
1453 depth = CvDEPTH(outside);
1454 assert(depth || SvTYPE(proto) == SVt_PVFM);
1455 if (!depth)
1456 depth = 1;
b5c19bd7 1457 assert(CvPADLIST(outside));
1458
dd2155a4 1459 ENTER;
1460 SAVESPTR(PL_compcv);
1461
561b68a9 1462 cv = PL_compcv = (CV*)newSV(0);
dd2155a4 1463 sv_upgrade((SV *)cv, SvTYPE(proto));
7dafbf52 1464 CvFLAGS(cv) = CvFLAGS(proto) & ~(CVf_CLONE|CVf_WEAKOUTSIDE);
dd2155a4 1465 CvCLONED_on(cv);
1466
dd2155a4 1467#ifdef USE_ITHREADS
aed2304a 1468 CvFILE(cv) = CvISXSUB(proto) ? CvFILE(proto)
1469 : savepv(CvFILE(proto));
dd2155a4 1470#else
1471 CvFILE(cv) = CvFILE(proto);
1472#endif
1473 CvGV(cv) = CvGV(proto);
1474 CvSTASH(cv) = CvSTASH(proto);
b34c0dd4 1475 OP_REFCNT_LOCK;
dd2155a4 1476 CvROOT(cv) = OpREFCNT_inc(CvROOT(proto));
b34c0dd4 1477 OP_REFCNT_UNLOCK;
dd2155a4 1478 CvSTART(cv) = CvSTART(proto);
b37c2d43 1479 CvOUTSIDE(cv) = (CV*)SvREFCNT_inc_simple(outside);
b5c19bd7 1480 CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(proto);
dd2155a4 1481
1482 if (SvPOK(proto))
b15aece3 1483 sv_setpvn((SV*)cv, SvPVX_const(proto), SvCUR(proto));
dd2155a4 1484
b7787f18 1485 CvPADLIST(cv) = pad_new(padnew_CLONE|padnew_SAVE);
dd2155a4 1486
b5c19bd7 1487 av_fill(PL_comppad, fpad);
dd2155a4 1488 for (ix = fname; ix >= 0; ix--)
1489 av_store(PL_comppad_name, ix, SvREFCNT_inc(pname[ix]));
1490
dd2155a4 1491 PL_curpad = AvARRAY(PL_comppad);
1492
71f882da 1493 outpad = AvARRAY(AvARRAY(CvPADLIST(outside))[depth]);
b5c19bd7 1494
dd2155a4 1495 for (ix = fpad; ix > 0; ix--) {
a0714e2c 1496 SV* const namesv = (ix <= fname) ? pname[ix] : NULL;
1497 SV *sv = NULL;
71f882da 1498 if (namesv && namesv != &PL_sv_undef) { /* lexical */
b5c19bd7 1499 if (SvFAKE(namesv)) { /* lexical from outside? */
809abb02 1500 sv = outpad[PARENT_PAD_INDEX(namesv)];
71f882da 1501 assert(sv);
1502 /* formats may have an inactive parent */
1503 if (SvTYPE(proto) == SVt_PVFM && SvPADSTALE(sv)) {
1504 if (ckWARN(WARN_CLOSURE))
1505 Perl_warner(aTHX_ packWARN(WARN_CLOSURE),
b15aece3 1506 "Variable \"%s\" is not available", SvPVX_const(namesv));
a0714e2c 1507 sv = NULL;
71f882da 1508 }
1509 else {
1510 assert(!SvPADSTALE(sv));
f84c484e 1511 SvREFCNT_inc_simple_void_NN(sv);
71f882da 1512 }
dd2155a4 1513 }
71f882da 1514 if (!sv) {
b15aece3 1515 const char sigil = SvPVX_const(namesv)[0];
e1ec3a88 1516 if (sigil == '&')
dd2155a4 1517 sv = SvREFCNT_inc(ppad[ix]);
e1ec3a88 1518 else if (sigil == '@')
dd2155a4 1519 sv = (SV*)newAV();
e1ec3a88 1520 else if (sigil == '%')
dd2155a4 1521 sv = (SV*)newHV();
1522 else
561b68a9 1523 sv = newSV(0);
235cc2e3 1524 SvPADMY_on(sv);
dd2155a4 1525 }
1526 }
1527 else if (IS_PADGV(ppad[ix]) || IS_PADCONST(ppad[ix])) {
f84c484e 1528 sv = SvREFCNT_inc_NN(ppad[ix]);
dd2155a4 1529 }
1530 else {
561b68a9 1531 sv = newSV(0);
dd2155a4 1532 SvPADTMP_on(sv);
dd2155a4 1533 }
71f882da 1534 PL_curpad[ix] = sv;
dd2155a4 1535 }
1536
dd2155a4 1537 DEBUG_Xv(
1538 PerlIO_printf(Perl_debug_log, "\nPad CV clone\n");
1539 cv_dump(outside, "Outside");
1540 cv_dump(proto, "Proto");
1541 cv_dump(cv, "To");
1542 );
1543
1544 LEAVE;
1545
1546 if (CvCONST(cv)) {
b5c19bd7 1547 /* Constant sub () { $x } closing over $x - see lib/constant.pm:
1548 * The prototype was marked as a candiate for const-ization,
1549 * so try to grab the current const value, and if successful,
1550 * turn into a const sub:
1551 */
551405c4 1552 SV* const const_sv = op_const_sv(CvSTART(cv), cv);
b5c19bd7 1553 if (const_sv) {
1554 SvREFCNT_dec(cv);
bd61b366 1555 cv = newCONSTSUB(CvSTASH(proto), NULL, const_sv);
b5c19bd7 1556 }
1557 else {
1558 CvCONST_off(cv);
1559 }
dd2155a4 1560 }
1561
1562 return cv;
1563}
1564
1565
1566/*
1567=for apidoc pad_fixup_inner_anons
1568
1569For any anon CVs in the pad, change CvOUTSIDE of that CV from
7dafbf52 1570old_cv to new_cv if necessary. Needed when a newly-compiled CV has to be
1571moved to a pre-existing CV struct.
dd2155a4 1572
1573=cut
1574*/
1575
1576void
1577Perl_pad_fixup_inner_anons(pTHX_ PADLIST *padlist, CV *old_cv, CV *new_cv)
1578{
97aff369 1579 dVAR;
dd2155a4 1580 I32 ix;
66a1b24b 1581 AV * const comppad_name = (AV*)AvARRAY(padlist)[0];
1582 AV * const comppad = (AV*)AvARRAY(padlist)[1];
53c1dcc0 1583 SV ** const namepad = AvARRAY(comppad_name);
1584 SV ** const curpad = AvARRAY(comppad);
294a48e9 1585 PERL_UNUSED_ARG(old_cv);
1586
dd2155a4 1587 for (ix = AvFILLp(comppad_name); ix > 0; ix--) {
551405c4 1588 const SV * const namesv = namepad[ix];
dd2155a4 1589 if (namesv && namesv != &PL_sv_undef
b15aece3 1590 && *SvPVX_const(namesv) == '&')
dd2155a4 1591 {
46c461b5 1592 CV * const innercv = (CV*)curpad[ix];
7dafbf52 1593 assert(CvWEAKOUTSIDE(innercv));
1594 assert(CvOUTSIDE(innercv) == old_cv);
1595 CvOUTSIDE(innercv) = new_cv;
dd2155a4 1596 }
1597 }
1598}
1599
7dafbf52 1600
dd2155a4 1601/*
1602=for apidoc pad_push
1603
1604Push a new pad frame onto the padlist, unless there's already a pad at
26019298 1605this depth, in which case don't bother creating a new one. Then give
1606the new pad an @_ in slot zero.
dd2155a4 1607
1608=cut
1609*/
1610
1611void
26019298 1612Perl_pad_push(pTHX_ PADLIST *padlist, int depth)
dd2155a4 1613{
97aff369 1614 dVAR;
b37c2d43 1615 if (depth > AvFILLp(padlist)) {
44f8325f 1616 SV** const svp = AvARRAY(padlist);
1617 AV* const newpad = newAV();
1618 SV** const oldpad = AvARRAY(svp[depth-1]);
dd2155a4 1619 I32 ix = AvFILLp((AV*)svp[1]);
e1ec3a88 1620 const I32 names_fill = AvFILLp((AV*)svp[0]);
44f8325f 1621 SV** const names = AvARRAY(svp[0]);
26019298 1622 AV *av;
1623
dd2155a4 1624 for ( ;ix > 0; ix--) {
1625 if (names_fill >= ix && names[ix] != &PL_sv_undef) {
b15aece3 1626 const char sigil = SvPVX_const(names[ix])[0];
26019298 1627 if ((SvFLAGS(names[ix]) & SVf_FAKE) || sigil == '&') {
dd2155a4 1628 /* outer lexical or anon code */
1629 av_store(newpad, ix, SvREFCNT_inc(oldpad[ix]));
1630 }
1631 else { /* our own lexical */
26019298 1632 SV *sv;
1633 if (sigil == '@')
1634 sv = (SV*)newAV();
1635 else if (sigil == '%')
1636 sv = (SV*)newHV();
dd2155a4 1637 else
561b68a9 1638 sv = newSV(0);
26019298 1639 av_store(newpad, ix, sv);
dd2155a4 1640 SvPADMY_on(sv);
1641 }
1642 }
1643 else if (IS_PADGV(oldpad[ix]) || IS_PADCONST(oldpad[ix])) {
f84c484e 1644 av_store(newpad, ix, SvREFCNT_inc_NN(oldpad[ix]));
dd2155a4 1645 }
1646 else {
1647 /* save temporaries on recursion? */
561b68a9 1648 SV * const sv = newSV(0);
26019298 1649 av_store(newpad, ix, sv);
dd2155a4 1650 SvPADTMP_on(sv);
1651 }
1652 }
26019298 1653 av = newAV();
1654 av_extend(av, 0);
1655 av_store(newpad, 0, (SV*)av);
11ca45c0 1656 AvREIFY_only(av);
26019298 1657
dd2155a4 1658 av_store(padlist, depth, (SV*)newpad);
1659 AvFILLp(padlist) = depth;
1660 }
1661}
b21dc031 1662
1663
1664HV *
1665Perl_pad_compname_type(pTHX_ const PADOFFSET po)
1666{
97aff369 1667 dVAR;
551405c4 1668 SV* const * const av = av_fetch(PL_comppad_name, po, FALSE);
00b1698f 1669 if ( SvPAD_TYPED(*av) ) {
b21dc031 1670 return SvSTASH(*av);
1671 }
5c284bb0 1672 return NULL;
b21dc031 1673}
66610fdd 1674
1675/*
1676 * Local variables:
1677 * c-indentation-style: bsd
1678 * c-basic-offset: 4
1679 * indent-tabs-mode: t
1680 * End:
1681 *
37442d52 1682 * ex: set ts=8 sts=4 sw=4 noet:
1683 */