This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta for fea90cfbe1f
[perl5.git] / pad.h
1 /*    pad.h
2  *
3  *    Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008,
4  *    2009, 2010, 2011 by Larry Wall and others
5  *
6  *    You may distribute under the terms of either the GNU General Public
7  *    License or the Artistic License, as specified in the README file.
8  *
9  * This file defines the types and macros associated with the API for
10  * manipulating scratchpads, which are used by perl to store lexical
11  * variables, op targets and constants.
12  */
13
14 /* offsets within a pad */
15
16 typedef SSize_t PADOFFSET; /* signed so that -1 is a valid value */
17 #define NOT_IN_PAD ((PADOFFSET) -1)
18
19 /* B.xs expects the first members of these two structs to line up
20    (xpadl_max with xpadnl_fill).
21  */
22
23 struct padlist {
24     SSize_t     xpadl_max;      /* max index for which array has space */
25     union {
26         PAD **  xpadlarr_alloc; /* Pointer to beginning of array of AVs.
27                                    Note that a 'padnamelist *' is stored
28                                    in the 0 index of the AV. */
29         struct {
30             PADNAMELIST * padnl;
31             PAD * pad_1;        /* this slice of PAD * array always alloced */
32             PAD * pad_2;        /* maybe unalloced */
33         } * xpadlarr_dbg;       /* for use with a C debugger only */
34     } xpadl_arr;
35     U32         xpadl_id;       /* Semi-unique ID, shared between clones */
36     U32         xpadl_outid;    /* ID of outer pad */
37 };
38
39 struct padnamelist {
40     SSize_t     xpadnl_fill;    /* max index in use */
41     PADNAME **  xpadnl_alloc;   /* pointer to beginning of array */
42     SSize_t     xpadnl_max;     /* max index for which array has space */
43     PADOFFSET   xpadnl_max_named; /* highest index with len > 0 */
44     U32         xpadnl_refcnt;
45 };
46
47 /* PERL_PADNAME_MINIMAL uses less memory, but on some platforms
48    PERL_PADNAME_ALIGNED may be faster, so platform-specific hints can
49    define one or the other.  */
50 #if defined(PERL_PADNAME_MINIMAL) && defined (PERL_PADNAME_ALIGNED)
51 #  error PERL_PADNAME_MINIMAL and PERL_PADNAME_ALIGNED are exclusive
52 #endif
53
54 #if !defined(PERL_PADNAME_MINIMAL) && !defined(PERL_PADNAME_ALIGNED)
55 #  define PERL_PADNAME_MINIMAL
56 #endif
57
58 struct padname_fieldinfo;
59
60 #define _PADNAME_BASE \
61     char *      xpadn_pv;               \
62     HV *        xpadn_ourstash;         \
63     union {                             \
64         HV *    xpadn_typestash;        \
65         CV *    xpadn_protocv;          \
66     } xpadn_type_u;                     \
67     struct padname_fieldinfo *xpadn_fieldinfo; \
68     U32         xpadn_low;              \
69     U32         xpadn_high;             \
70     U32         xpadn_refcnt;           \
71     int         xpadn_gen;              \
72     U8          xpadn_len;              \
73     U8          xpadn_flags
74
75 struct padname {
76     _PADNAME_BASE;
77 };
78
79 struct padname_with_str {
80 #ifdef PERL_PADNAME_MINIMAL
81     _PADNAME_BASE;
82 #else
83     struct padname      xpadn_padname;
84 #endif
85     char                xpadn_str[1];
86 };
87
88 #undef _PADNAME_BASE
89
90 #define PADNAME_FROM_PV(s) \
91     ((PADNAME *)((s) - STRUCT_OFFSET(struct padname_with_str, xpadn_str)))
92
93 /* Most padnames are not field names. Keep all the field-related info in its
94  * own substructure, stored in ->xpadn_fieldinfo.
95  */
96 struct padname_fieldinfo {
97     U32        refcount;
98     PADOFFSET  fieldix;    /* index of this field within ObjectFIELDS() array */
99     HV        *fieldstash; /* original class package which added this field */
100     OP        *defop;      /* optree fragment for defaulting expression */
101     SV        *paramname;  /* name of the :param to look for in constructor */
102     int        def_if_undef : 1; /* default op uses //= */
103     int        def_if_false : 1; /* default op uses ||= */
104 };
105
106
107 /* a value that PL_cop_seqmax is guaranteed never to be,
108  * flagging that a lexical is being introduced, or has not yet left scope
109  */
110 #define PERL_PADSEQ_INTRO  U32_MAX
111 #define COP_SEQMAX_INC \
112         (PL_cop_seqmax++, \
113          (void)(PL_cop_seqmax == PERL_PADSEQ_INTRO && PL_cop_seqmax++))
114
115
116 /* B.xs needs these for the benefit of B::Deparse */
117 /* Low range end is exclusive (valid from the cop seq after this one) */
118 /* High range end is inclusive (valid up to this cop seq) */
119
120 #define COP_SEQ_RANGE_LOW(pn)           (pn)->xpadn_low
121 #define COP_SEQ_RANGE_HIGH(pn)          (pn)->xpadn_high
122 #define PARENT_PAD_INDEX(pn)            (pn)->xpadn_low
123 #define PARENT_FAKELEX_FLAGS(pn)        (pn)->xpadn_high
124
125 /* Flags set in the SvIVX field of FAKE namesvs */
126
127 #define PAD_FAKELEX_ANON   1 /* the lex is declared in an ANON, or ... */
128 #define PAD_FAKELEX_MULTI  2 /* the lex can be instantiated multiple times */
129
130 /* flags for the pad_new() function */
131
132 #define padnew_CLONE    1       /* this pad is for a cloned CV */
133 #define padnew_SAVE     2       /* save old globals */
134 #define padnew_SAVESUB  4       /* also save extra stuff for start of sub */
135
136 /* values for the pad_tidy() function */
137
138 typedef enum {
139         padtidy_SUB,            /* tidy up a pad for a sub, */
140         padtidy_SUBCLONE,       /* a cloned sub, */
141         padtidy_FORMAT          /* or a format */
142 } padtidy_type;
143
144 /* flags for pad_add_name_pvn. */
145
146 #define padadd_OUR              0x01       /* our declaration. */
147 #define padadd_STATE            0x02       /* state declaration. */
148 #define padadd_NO_DUP_CHECK     0x04       /* skip warning on dups. */
149 #define padadd_STALEOK          0x08       /* allow stale lexical in active
150                                             * sub, but only one level up */
151 #define padadd_FIELD            0x10       /* set PADNAMEt_FIELD */
152 #define padfind_FIELD_OK        0x20       /* pad_findlex is permitted to see fields */
153 #define padadd_TOMBSTONE        0x40       /* set PadnameIsTOMBSTONE on the new entry */
154
155 /* ASSERT_CURPAD_LEGAL and ASSERT_CURPAD_ACTIVE respectively determine
156  * whether PL_comppad and PL_curpad are consistent and whether they have
157  * active values */
158
159 #  define pad_peg(label)
160
161 #ifdef DEBUGGING
162 #  define ASSERT_CURPAD_LEGAL(label) \
163     pad_peg(label); \
164     if (PL_comppad ? (AvARRAY(PL_comppad) != PL_curpad) : (PL_curpad != 0))  \
165         Perl_croak(aTHX_ "panic: illegal pad in %s: 0x%" UVxf "[0x%" UVxf "]",\
166             label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
167
168
169 #  define ASSERT_CURPAD_ACTIVE(label) \
170     pad_peg(label); \
171     if (!PL_comppad || (AvARRAY(PL_comppad) != PL_curpad))                \
172         Perl_croak(aTHX_ "panic: invalid pad in %s: 0x%" UVxf "[0x%" UVxf "]",\
173             label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
174 #else
175 #  define ASSERT_CURPAD_LEGAL(label)
176 #  define ASSERT_CURPAD_ACTIVE(label)
177 #endif
178
179
180
181 /* Note: the following three macros are actually defined in scope.h, but
182  * they are documented here for completeness, since they directly or
183  * indirectly affect pads. */
184
185 /*
186 =for apidoc m|void|SAVEPADSV    |PADOFFSET po
187 Save a pad slot (used to restore after an iteration)
188
189 =cut
190
191 XXX DAPM it would make more sense to make the arg a PADOFFSET
192
193 =for apidoc m|void|SAVECLEARSV  |SV **svp
194 Clear the pointed to pad value on scope exit.  (i.e. the runtime action of
195 C<my>)
196
197 =for apidoc m|void|SAVECOMPPAD
198 save C<PL_comppad> and C<PL_curpad>
199
200
201 =for apidoc Amx|PAD **|PadlistARRAY|PADLIST * padlist
202 The C array of a padlist, containing the pads.  Only subscript it with
203 numbers >= 1, as the 0th entry is not guaranteed to remain usable.
204
205 =for apidoc Amx|SSize_t|PadlistMAX|PADLIST * padlist
206 The index of the last allocated space in the padlist.  Note that the last
207 pad may be in an earlier slot.  Any entries following it will be C<NULL> in
208 that case.
209
210 =for apidoc Amx|PADNAMELIST *|PadlistNAMES|PADLIST * padlist
211 The names associated with pad entries.
212
213 =for apidoc Amx|PADNAME **|PadlistNAMESARRAY|PADLIST * padlist
214 The C array of pad names.
215
216 =for apidoc Amx|SSize_t|PadlistNAMESMAX|PADLIST * padlist
217 The index of the last pad name.
218
219 =for apidoc Amx|U32|PadlistREFCNT|PADLIST * padlist
220 The reference count of the padlist.  Currently this is always 1.
221
222 =for apidoc Amx|PADNAME **|PadnamelistARRAY|PADNAMELIST * pnl
223 The C array of pad names.
224
225 =for apidoc Amx|SSize_t|PadnamelistMAX|PADNAMELIST * pnl
226 The index of the last pad name.
227
228 =for apidoc Amx|SSize_t|PadnamelistREFCNT|PADNAMELIST * pnl
229 The reference count of the pad name list.
230
231 =for apidoc Amx|void|PadnamelistREFCNT_dec|PADNAMELIST * pnl
232 Lowers the reference count of the pad name list.
233
234 =for apidoc Amx|SV **|PadARRAY|PAD * pad
235 The C array of pad entries.
236
237 =for apidoc Amx|SSize_t|PadMAX|PAD * pad
238 The index of the last pad entry.
239
240 =for apidoc Amx|char *|PadnamePV|PADNAME * pn
241 The name stored in the pad name struct.  This returns C<NULL> for a target
242 slot.
243
244 =for apidoc Amx|STRLEN|PadnameLEN|PADNAME * pn
245 The length of the name.
246
247 =for apidoc Amx|bool|PadnameUTF8|PADNAME * pn
248 Whether PadnamePV is in UTF-8.  Currently, this is always true.
249
250 =for apidoc Amx|SV *|PadnameSV|PADNAME * pn
251 Returns the pad name as a mortal SV.
252
253 =for apidoc m|bool|PadnameIsOUR|PADNAME * pn
254 Whether this is an "our" variable.
255
256 =for apidoc m|HV *|PadnameOURSTASH|PADNAME * pn
257 The stash in which this "our" variable was declared.
258
259 =for apidoc m|bool|PadnameOUTER|PADNAME * pn
260 Whether this entry belongs to an outer pad.  Entries for which this is true
261 are often referred to as 'fake'.
262
263 =for apidoc m|bool|PadnameIsSTATE|PADNAME * pn
264 Whether this is a "state" variable.
265
266 =for apidoc m|bool|PadnameIsFIELD|PADNAME * pn
267 Whether this is a "field" variable.  PADNAMEs where this is true will
268 have additional information available via C<PadnameFIELDINFO>.
269
270 =for apidoc m|bool|PadnameIsTOMBSTONE|PADNAME * pn
271 Whether this pad entry is a tombstone.  Such an entry indicates that a
272 previously-valid pad entry has now been deleted within this scope, and
273 should be ignored.
274
275 =for apidoc m|HV *|PadnameTYPE|PADNAME * pn
276 The stash associated with a typed lexical.  This returns the C<%Foo::> hash
277 for C<my Foo $bar>.
278
279 =for apidoc Amx|SSize_t|PadnameREFCNT|PADNAME * pn
280 The reference count of the pad name.
281
282 =for apidoc Amx|PADNAME *|PadnameREFCNT_inc|PADNAME * pn
283 Increases the reference count of the pad name.  Returns the pad name itself.
284
285 =for apidoc Amx|void|PadnameREFCNT_dec|PADNAME * pn
286 Lowers the reference count of the pad name.
287
288
289 =for apidoc m|SV *|PAD_SETSV    |PADOFFSET po|SV* sv
290 Set the slot at offset C<po> in the current pad to C<sv>
291
292 =for apidoc m|SV *|PAD_SV       |PADOFFSET po
293 Get the value at offset C<po> in the current pad
294
295 =for apidoc m|SV *|PAD_SVl      |PADOFFSET po
296 Lightweight and lvalue version of C<PAD_SV>.
297 Get or set the value at offset C<po> in the current pad.
298 Unlike C<PAD_SV>, does not print diagnostics with -DX.
299 For internal use only.
300
301 =for apidoc m|SV *|PAD_BASE_SV  |PADLIST padlist|PADOFFSET po
302 Get the value from slot C<po> in the base (DEPTH=1) pad of a padlist
303
304 =for apidoc m|void|PAD_SET_CUR  |PADLIST padlist|I32 n
305 Set the current pad to be pad C<n> in the padlist, saving
306 the previous current pad.  NB currently this macro expands to a string too
307 long for some compilers, so it's best to replace it with
308
309     SAVECOMPPAD();
310     PAD_SET_CUR_NOSAVE(padlist,n);
311
312
313 =for apidoc m|void|PAD_SET_CUR_NOSAVE   |PADLIST padlist|I32 n
314 like PAD_SET_CUR, but without the save
315
316 =for apidoc m|void|PAD_SAVE_SETNULLPAD
317 Save the current pad then set it to null.
318
319 =for apidoc m|void|PAD_SAVE_LOCAL|PAD *opad|PAD *npad
320 Save the current pad to the local variable C<opad>, then make the
321 current pad equal to C<npad>
322
323 =for apidoc m|void|PAD_RESTORE_LOCAL|PAD *opad
324 Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()>
325
326 =cut
327 */
328
329 #define PadlistARRAY(pl)        (pl)->xpadl_arr.xpadlarr_alloc
330 #define PadlistMAX(pl)          (pl)->xpadl_max
331 #define PadlistNAMES(pl)        *((PADNAMELIST **)PadlistARRAY(pl))
332 #define PadlistNAMESARRAY(pl)   PadnamelistARRAY(PadlistNAMES(pl))
333 #define PadlistNAMESMAX(pl)     PadnamelistMAX(PadlistNAMES(pl))
334 #define PadlistREFCNT(pl)       1       /* reserved for future use */
335
336 #define PadnamelistARRAY(pnl)           (pnl)->xpadnl_alloc
337 #define PadnamelistMAX(pnl)             (pnl)->xpadnl_fill
338 #define PadnamelistMAXNAMED(pnl)        (pnl)->xpadnl_max_named
339 #define PadnamelistREFCNT(pnl)          (pnl)->xpadnl_refcnt
340 #define PadnamelistREFCNT_inc(pnl)      Perl_padnamelist_refcnt_inc(pnl)
341 #define PadnamelistREFCNT_dec(pnl)      Perl_padnamelist_free(aTHX_ pnl)
342
343 #define PadARRAY(pad)           AvARRAY(pad)
344 #define PadMAX(pad)             AvFILLp(pad)
345
346 #define PadnamePV(pn)           (pn)->xpadn_pv
347 #define PadnameLEN(pn)          (pn)->xpadn_len
348 #define PadnameUTF8(pn)         1
349 #define PadnameSV(pn) \
350         newSVpvn_flags(PadnamePV(pn), PadnameLEN(pn), SVs_TEMP|SVf_UTF8)
351 #define PadnameFLAGS(pn)        (pn)->xpadn_flags
352 #define PadnameIsOUR(pn)        cBOOL((pn)->xpadn_ourstash)
353 #define PadnameOURSTASH(pn)     (pn)->xpadn_ourstash
354 #define PadnameTYPE(pn)         (pn)->xpadn_type_u.xpadn_typestash
355 #define PadnameHasTYPE(pn)      cBOOL(PadnameTYPE(pn))
356 #define PadnamePROTOCV(pn)      (pn)->xpadn_type_u.xpadn_protocv
357 #define PadnameREFCNT(pn)       (pn)->xpadn_refcnt
358 #define PadnameREFCNT_inc(pn)   Perl_padname_refcnt_inc(pn)
359 #define PadnameREFCNT_dec(pn)   Perl_padname_free(aTHX_ pn)
360 #define PadnameOURSTASH_set(pn,s) (PadnameOURSTASH(pn) = (s))
361 #define PadnameTYPE_set(pn,s)     (PadnameTYPE(pn) = (s))
362 #define PadnameFIELDINFO(pn)    (pn)->xpadn_fieldinfo
363 #define PadnameOUTER(pn)        (PadnameFLAGS(pn) & PADNAMEf_OUTER)
364 #define PadnameIsSTATE(pn)      (PadnameFLAGS(pn) & PADNAMEf_STATE)
365 #define PadnameLVALUE(pn)       (PadnameFLAGS(pn) & PADNAMEf_LVALUE)
366 #define PadnameIsFIELD(pn)      (PadnameFLAGS(pn) & PADNAMEf_FIELD)
367 #define PadnameIsTOMBSTONE(pn)  (PadnameFLAGS(pn) & PADNAMEf_TOMBSTONE)
368
369 #define PadnameLVALUE_on(pn)    (PadnameFLAGS(pn) |= PADNAMEf_LVALUE)
370 #define PadnameIsSTATE_on(pn)   (PadnameFLAGS(pn) |= PADNAMEf_STATE)
371
372 #define PADNAMEf_OUTER      0x01    /* outer lexical var */
373 #define PADNAMEf_STATE      0x02    /* state var */
374 #define PADNAMEf_LVALUE     0x04    /* used as lvalue */
375 #define PADNAMEf_TYPED      0x08    /* for B; unused by core */
376 #define PADNAMEf_OUR        0x10    /* for B; unused by core */
377 #define PADNAMEf_FIELD      0x20    /* field var */
378 #define PADNAMEf_TOMBSTONE  0x40    /* padname has been deleted */
379
380 /* backward compatibility */
381 #ifndef PERL_CORE
382 #  define SvPAD_STATE           PadnameIsSTATE
383 #  define SvPAD_TYPED           PadnameHasTYPE
384 #  define SvPAD_OUR(pn)         cBOOL(PadnameOURSTASH(pn))
385 #  define SvPAD_STATE_on        PadnameIsSTATE_on
386 #  define SvPAD_TYPED_on(pn)    (PadnameFLAGS(pn) |= PADNAMEf_TYPED)
387 #  define SvPAD_OUR_on(pn)      (PadnameFLAGS(pn) |= PADNAMEf_OUR)
388 #  define SvOURSTASH            PadnameOURSTASH
389 #  define SvOURSTASH_set        PadnameOURSTASH_set
390 #  define SVpad_STATE           PADNAMEf_STATE
391 #  define SVpad_TYPED           PADNAMEf_TYPED
392 #  define SVpad_OUR             PADNAMEf_OUR
393 #  define PADNAMEt_OUTER        PADNAMEf_OUTER
394 #  define PADNAMEt_STATE        PADNAMEf_STATE
395 #  define PADNAMEt_LVALUE       PADNAMEf_LVALUE
396 #  define PADNAMEt_TYPED        PADNAMEf_TYPED
397 #  define PADNAMEt_OUR          PADNAMEf_OUR
398 #endif
399
400 #ifdef USE_ITHREADS
401 #  define padnamelist_dup_inc(pnl,param)  PadnamelistREFCNT_inc(padnamelist_dup(pnl,param))
402 #  define padname_dup_inc(pn,param)       PadnameREFCNT_inc(padname_dup(pn,param))
403 #endif
404
405 #ifdef DEBUGGING
406 #  define PAD_SV(po)       pad_sv(po)
407 #  define PAD_SETSV(po,sv) pad_setsv(po,sv)
408 #else
409 #  define PAD_SV(po)       (PL_curpad[po])
410 #  define PAD_SETSV(po,sv) PL_curpad[po] = (sv)
411 #endif
412
413 #define PAD_SVl(po)       (PL_curpad[po])
414
415 #define PAD_BASE_SV(padlist, po) \
416         (PadlistARRAY(padlist)[1])                                      \
417             ? AvARRAY(MUTABLE_AV((PadlistARRAY(padlist)[1])))[po] \
418             : NULL;
419
420
421 #define PAD_SET_CUR_NOSAVE(padlist,nth) \
422         PL_comppad = (PAD*) (PadlistARRAY(padlist)[nth]);       \
423         PL_curpad = AvARRAY(PL_comppad);                        \
424         DEBUG_Xv(PerlIO_printf(Perl_debug_log,                  \
425               "Pad 0x%" UVxf "[0x%" UVxf "] set_cur    depth=%d\n",     \
426               PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(nth)));
427
428
429 #define PAD_SET_CUR(padlist,nth) \
430         SAVECOMPPAD();                                          \
431         PAD_SET_CUR_NOSAVE(padlist,nth);
432
433
434 #define PAD_SAVE_SETNULLPAD()   SAVECOMPPAD(); \
435         PL_comppad = NULL; PL_curpad = NULL;    \
436         DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad set_null\n"));
437
438 #define PAD_SAVE_LOCAL(opad,npad) \
439         opad = PL_comppad;                                      \
440         PL_comppad = (npad);                                    \
441         PL_curpad =  PL_comppad ? AvARRAY(PL_comppad) : NULL;   \
442         DEBUG_Xv(PerlIO_printf(Perl_debug_log,                  \
443               "Pad 0x%" UVxf "[0x%" UVxf "] save_local\n",              \
444               PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
445
446 #define PAD_RESTORE_LOCAL(opad) \
447         assert(!opad || !SvIS_FREED(opad));                                     \
448         PL_comppad = opad;                                              \
449         PL_curpad =  PL_comppad ? AvARRAY(PL_comppad) : NULL;   \
450         DEBUG_Xv(PerlIO_printf(Perl_debug_log,                  \
451               "Pad 0x%" UVxf "[0x%" UVxf "] restore_local\n",   \
452               PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
453
454
455 /*
456 =for apidoc m|void|CX_CURPAD_SAVE|struct context
457 Save the current pad in the given context block structure.
458
459 =for apidoc m|SV *|CX_CURPAD_SV|struct context|PADOFFSET po
460 Access the SV at offset C<po> in the saved current pad in the given
461 context block structure (can be used as an lvalue).
462
463 =cut
464 */
465
466 #define CX_CURPAD_SAVE(block)  (block).oldcomppad = PL_comppad
467 #define CX_CURPAD_SV(block,po) (AvARRAY(MUTABLE_AV(((block).oldcomppad)))[po])
468
469
470 /*
471 =for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po
472 Return the flags for the current compiling pad name
473 at offset C<po>.  Assumes a valid slot entry.
474
475 =for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po
476 Return the name of the current compiling pad name
477 at offset C<po>.  Assumes a valid slot entry.
478
479 =for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po
480 Return the type (stash) of the current compiling pad name at offset
481 C<po>.  Must be a valid name.  Returns null if not typed.
482
483 =for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po
484 Return the stash associated with an C<our> variable.
485 Assumes the slot entry is a valid C<our> lexical.
486
487 =for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po
488 The generation number of the name at offset C<po> in the current
489 compiling pad (lvalue).
490
491 =for apidoc m|STRLEN|PAD_COMPNAME_GEN_set|PADOFFSET po|int gen
492 Sets the generation number of the name at offset C<po> in the current
493 ling pad (lvalue) to C<gen>.
494 =cut
495
496 */
497
498 #define PAD_COMPNAME(po)        PAD_COMPNAME_SV(po)
499 #define PAD_COMPNAME_SV(po)     (PadnamelistARRAY(PL_comppad_name)[(po)])
500 #define PAD_COMPNAME_FLAGS(po)  PadnameFLAGS(PAD_COMPNAME(po))
501 #define PAD_COMPNAME_FLAGS_isOUR(po) PadnameIsOUR(PAD_COMPNAME_SV(po))
502 #define PAD_COMPNAME_PV(po)     PadnamePV(PAD_COMPNAME(po))
503
504 #define PAD_COMPNAME_TYPE(po)   PadnameTYPE(PAD_COMPNAME(po))
505
506 #define PAD_COMPNAME_OURSTASH(po)  (PadnameOURSTASH(PAD_COMPNAME_SV(po)))
507
508 #define PAD_COMPNAME_GEN(po) \
509     ((STRLEN)PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen)
510
511 #define PAD_COMPNAME_GEN_set(po, gen) \
512     (PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen = (gen))
513
514
515 /*
516 =for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl|CLONE_PARAMS* param
517 Clone the state variables associated with running and compiling pads.
518
519 =cut
520 */
521
522 /* NB - we set PL_comppad to null unless it points at a value that
523  * has already been dup'ed, ie it points to part of an active padlist.
524  * Otherwise PL_comppad ends up being a leaked scalar in code like
525  * the following:
526  *     threads->create(sub { threads->create(sub {...} ) } );
527  * where the second thread dups the outer sub's comppad but not the
528  * sub's CV or padlist. */
529
530 #define PAD_CLONE_VARS(proto_perl, param)                               \
531     PL_comppad                  = av_dup(proto_perl->Icomppad, param);  \
532     PL_curpad = PL_comppad ?  AvARRAY(PL_comppad) : NULL;               \
533     PL_comppad_name             =                                       \
534                   padnamelist_dup(proto_perl->Icomppad_name, param);    \
535     PL_comppad_name_fill        = proto_perl->Icomppad_name_fill;       \
536     PL_comppad_name_floor       = proto_perl->Icomppad_name_floor;      \
537     PL_min_intro_pending        = proto_perl->Imin_intro_pending;       \
538     PL_max_intro_pending        = proto_perl->Imax_intro_pending;       \
539     PL_padix                    = proto_perl->Ipadix;                   \
540     PL_padix_floor              = proto_perl->Ipadix_floor;             \
541     PL_pad_reset_pending        = proto_perl->Ipad_reset_pending;       \
542     PL_cop_seqmax               = proto_perl->Icop_seqmax;
543
544 /*
545 =for apidoc Am|PADOFFSET|pad_add_name_pvs|"name"|U32 flags|HV *typestash|HV *ourstash
546
547 Exactly like L</pad_add_name_pvn>, but takes a literal string
548 instead of a string/length pair.
549
550 =cut
551 */
552
553 #define pad_add_name_pvs(name,flags,typestash,ourstash) \
554     Perl_pad_add_name_pvn(aTHX_ STR_WITH_LEN(name), flags, typestash, ourstash)
555
556 /*
557 =for apidoc Am|PADOFFSET|pad_findmy_pvs|"name"|U32 flags
558
559 Exactly like L</pad_findmy_pvn>, but takes a literal string
560 instead of a string/length pair.
561
562 =cut
563 */
564
565 #define pad_findmy_pvs(name,flags) \
566     Perl_pad_findmy_pvn(aTHX_ STR_WITH_LEN(name), flags)
567
568 struct suspended_compcv
569 {
570     CV *compcv;
571     STRLEN padix, constpadix;
572     STRLEN comppad_name_fill;
573     STRLEN min_intro_pending, max_intro_pending;
574     bool cv_has_eval, pad_reset_pending;
575 };
576
577 #define resume_compcv_final(buffer)     Perl_resume_compcv(aTHX_ buffer, false)
578 #define resume_compcv_and_save(buffer)  Perl_resume_compcv(aTHX_ buffer, true)
579
580 /*
581  * ex: set ts=8 sts=4 sw=4 et:
582  */