This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use PADNAME rather than SV in pad.c:padlist_dup
[perl5.git] / pad.h
CommitLineData
dd2155a4
DM
1/* pad.h
2 *
2eee27d7
SS
3 * Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008,
4 * 2009, 2010, 2011 by Larry Wall and others
dd2155a4
DM
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
cc76b5cc
Z
14/*
15=head1 Pad Data Structures
16*/
dd2155a4
DM
17
18
dd2155a4
DM
19/* offsets within a pad */
20
21#if PTRSIZE == 4
22typedef U32TYPE PADOFFSET;
23#else
24# if PTRSIZE == 8
25typedef U64TYPE PADOFFSET;
26# endif
27#endif
28#define NOT_IN_PAD ((PADOFFSET) -1)
809abb02 29
9b7476d7
FC
30/* B.xs expects the first members of these two structs to line up
31 (xpadl_max with xpadnl_fill).
32 */
7261499d
FC
33
34struct padlist {
35 SSize_t xpadl_max; /* max index for which array has space */
36 PAD ** xpadl_alloc; /* pointer to beginning of array of AVs */
8771da69 37 PADNAMELIST*xpadl_outid; /* Padnamelist of outer pad; used as ID */
7261499d
FC
38};
39
9b7476d7
FC
40struct padnamelist {
41 SSize_t xpadnl_fill; /* max index in use */
42 PADNAME ** xpadnl_alloc; /* pointer to beginning of array */
43 SSize_t xpadnl_max; /* max index for which array has space */
44 PADOFFSET xpadnl_max_named; /* highest index with len > 0 */
45 U32 xpadnl_refcnt;
46};
47
7261499d 48
2df5bdd7
DM
49/* a value that PL_cop_seqmax is guaranteed never to be,
50 * flagging that a lexical is being introduced, or has not yet left scope
51 */
52#define PERL_PADSEQ_INTRO U32_MAX
953c8b80
FC
53#define COP_SEQMAX_INC \
54 (PL_cop_seqmax++, \
55 (void)(PL_cop_seqmax == PERL_PADSEQ_INTRO && PL_cop_seqmax++))
2df5bdd7
DM
56
57
7948fc08 58/* B.xs needs these for the benefit of B::Deparse */
809abb02 59/* Low range end is exclusive (valid from the cop seq after this one) */
809abb02 60/* High range end is inclusive (valid up to this cop seq) */
809abb02 61
3441fb63
NC
62#if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
63# define COP_SEQ_RANGE_LOW(sv) \
b1bc3f34 64 (({ const SV *const _sv_cop_seq_range_low = (const SV *) (sv); \
7948fc08
RU
65 assert(SvTYPE(_sv_cop_seq_range_low) == SVt_NV \
66 || SvTYPE(_sv_cop_seq_range_low) >= SVt_PVNV); \
67 assert(SvTYPE(_sv_cop_seq_range_low) != SVt_PVAV); \
68 assert(SvTYPE(_sv_cop_seq_range_low) != SVt_PVHV); \
69 assert(SvTYPE(_sv_cop_seq_range_low) != SVt_PVCV); \
70 assert(SvTYPE(_sv_cop_seq_range_low) != SVt_PVFM); \
71 assert(!isGV_with_GP(_sv_cop_seq_range_low)); \
b1bc3f34 72 ((XPVNV*) MUTABLE_PTR(SvANY(_sv_cop_seq_range_low)))->xnv_u.xpad_cop_seq.xlow; \
3441fb63
NC
73 }))
74# define COP_SEQ_RANGE_HIGH(sv) \
b1bc3f34 75 (({ const SV *const _sv_cop_seq_range_high = (const SV *) (sv); \
7948fc08
RU
76 assert(SvTYPE(_sv_cop_seq_range_high) == SVt_NV \
77 || SvTYPE(_sv_cop_seq_range_high) >= SVt_PVNV); \
78 assert(SvTYPE(_sv_cop_seq_range_high) != SVt_PVAV); \
79 assert(SvTYPE(_sv_cop_seq_range_high) != SVt_PVHV); \
80 assert(SvTYPE(_sv_cop_seq_range_high) != SVt_PVCV); \
81 assert(SvTYPE(_sv_cop_seq_range_high) != SVt_PVFM); \
82 assert(!isGV_with_GP(_sv_cop_seq_range_high)); \
b1bc3f34 83 ((XPVNV*) MUTABLE_PTR(SvANY(_sv_cop_seq_range_high)))->xnv_u.xpad_cop_seq.xhigh; \
3441fb63
NC
84 }))
85# define PARENT_PAD_INDEX(sv) \
b1bc3f34 86 (({ const SV *const _sv_parent_pad_index = (const SV *) (sv); \
7948fc08
RU
87 assert(SvTYPE(_sv_parent_pad_index) == SVt_NV \
88 || SvTYPE(_sv_parent_pad_index) >= SVt_PVNV); \
89 assert(SvTYPE(_sv_parent_pad_index) != SVt_PVAV); \
90 assert(SvTYPE(_sv_parent_pad_index) != SVt_PVHV); \
91 assert(SvTYPE(_sv_parent_pad_index) != SVt_PVCV); \
92 assert(SvTYPE(_sv_parent_pad_index) != SVt_PVFM); \
93 assert(!isGV_with_GP(_sv_parent_pad_index)); \
b1bc3f34 94 ((XPVNV*) MUTABLE_PTR(SvANY(_sv_parent_pad_index)))->xnv_u.xpad_cop_seq.xlow; \
3441fb63
NC
95 }))
96# define PARENT_FAKELEX_FLAGS(sv) \
b1bc3f34 97 (({ const SV *const _sv_parent_fakelex_flags = (const SV *) (sv); \
7948fc08
RU
98 assert(SvTYPE(_sv_parent_fakelex_flags) == SVt_NV \
99 || SvTYPE(_sv_parent_fakelex_flags) >= SVt_PVNV); \
100 assert(SvTYPE(_sv_parent_fakelex_flags) != SVt_PVAV); \
101 assert(SvTYPE(_sv_parent_fakelex_flags) != SVt_PVHV); \
102 assert(SvTYPE(_sv_parent_fakelex_flags) != SVt_PVCV); \
103 assert(SvTYPE(_sv_parent_fakelex_flags) != SVt_PVFM); \
104 assert(!isGV_with_GP(_sv_parent_fakelex_flags)); \
b1bc3f34 105 ((XPVNV*) MUTABLE_PTR(SvANY(_sv_parent_fakelex_flags)))->xnv_u.xpad_cop_seq.xhigh; \
3441fb63
NC
106 }))
107#else
108# define COP_SEQ_RANGE_LOW(sv) \
109 (0 + (((XPVNV*) SvANY(sv))->xnv_u.xpad_cop_seq.xlow))
110# define COP_SEQ_RANGE_HIGH(sv) \
111 (0 + (((XPVNV*) SvANY(sv))->xnv_u.xpad_cop_seq.xhigh))
112
113
114# define PARENT_PAD_INDEX(sv) \
115 (0 + (((XPVNV*) SvANY(sv))->xnv_u.xpad_cop_seq.xlow))
116# define PARENT_FAKELEX_FLAGS(sv) \
117 (0 + (((XPVNV*) SvANY(sv))->xnv_u.xpad_cop_seq.xhigh))
118#endif
dd2155a4 119
6c5e080d 120/* Flags set in the SvIVX field of FAKE namesvs */
7948fc08 121
6c5e080d
NC
122#define PAD_FAKELEX_ANON 1 /* the lex is declared in an ANON, or ... */
123#define PAD_FAKELEX_MULTI 2 /* the lex can be instantiated multiple times */
124
dd2155a4
DM
125/* flags for the pad_new() function */
126
c7c737cb
DM
127#define padnew_CLONE 1 /* this pad is for a cloned CV */
128#define padnew_SAVE 2 /* save old globals */
129#define padnew_SAVESUB 4 /* also save extra stuff for start of sub */
dd2155a4
DM
130
131/* values for the pad_tidy() function */
132
133typedef enum {
134 padtidy_SUB, /* tidy up a pad for a sub, */
135 padtidy_SUBCLONE, /* a cloned sub, */
136 padtidy_FORMAT /* or a format */
137} padtidy_type;
138
9f6ec8dd 139/* flags for pad_add_name_pvn. */
35f82371 140
9f6ec8dd
BF
141#define padadd_OUR 0x01 /* our declaration. */
142#define padadd_STATE 0x02 /* state declaration. */
143#define padadd_NO_DUP_CHECK 0x04 /* skip warning on dups. */
7ef30830
FC
144#define padadd_STALEOK 0x08 /* allow stale lexical in active
145 * sub, but only one level up */
35f82371 146
f3548bdc
DM
147/* ASSERT_CURPAD_LEGAL and ASSERT_CURPAD_ACTIVE respectively determine
148 * whether PL_comppad and PL_curpad are consistent and whether they have
149 * active values */
dd2155a4 150
1dba731d 151# define pad_peg(label)
1dba731d 152
f3548bdc
DM
153#ifdef DEBUGGING
154# define ASSERT_CURPAD_LEGAL(label) \
1dba731d 155 pad_peg(label); \
f3548bdc 156 if (PL_comppad ? (AvARRAY(PL_comppad) != PL_curpad) : (PL_curpad != 0)) \
61608bb7 157 Perl_croak(aTHX_ "panic: illegal pad in %s: 0x%" UVxf "[0x%" UVxf "]",\
f3548bdc
DM
158 label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
159
160
161# define ASSERT_CURPAD_ACTIVE(label) \
1dba731d 162 pad_peg(label); \
f3548bdc 163 if (!PL_comppad || (AvARRAY(PL_comppad) != PL_curpad)) \
61608bb7 164 Perl_croak(aTHX_ "panic: invalid pad in %s: 0x%" UVxf "[0x%" UVxf "]",\
f3548bdc
DM
165 label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
166#else
167# define ASSERT_CURPAD_LEGAL(label)
168# define ASSERT_CURPAD_ACTIVE(label)
169#endif
170
171
172
173/* Note: the following three macros are actually defined in scope.h, but
dd2155a4
DM
174 * they are documented here for completeness, since they directly or
175 * indirectly affect pads.
176
177=for apidoc m|void|SAVEPADSV |PADOFFSET po
178Save a pad slot (used to restore after an iteration)
179
f3548bdc 180XXX DAPM it would make more sense to make the arg a PADOFFSET
dd2155a4 181=for apidoc m|void|SAVECLEARSV |SV **svp
154e47c8
FC
182Clear the pointed to pad value on scope exit. (i.e. the runtime action of
183'my')
dd2155a4
DM
184
185=for apidoc m|void|SAVECOMPPAD
9c47725a 186save PL_comppad and PL_curpad
dd2155a4 187
dd2155a4 188
86d2498c 189=for apidoc Amx|PAD **|PadlistARRAY|PADLIST padlist
35e035cc
FC
190The C array of a padlist, containing the pads. Only subscript it with
191numbers >= 1, as the 0th entry is not guaranteed to remain usable.
dd2155a4 192
86d2498c 193=for apidoc Amx|SSize_t|PadlistMAX|PADLIST padlist
57ee99bb
FC
194The index of the last allocated space in the padlist. Note that the last
195pad may be in an earlier slot. Any entries following it will be NULL in
196that case.
35e035cc 197
86d2498c 198=for apidoc Amx|PADNAMELIST *|PadlistNAMES|PADLIST padlist
35e035cc
FC
199The names associated with pad entries.
200
86d2498c 201=for apidoc Amx|PADNAME **|PadlistNAMESARRAY|PADLIST padlist
35e035cc
FC
202The C array of pad names.
203
86d2498c 204=for apidoc Amx|SSize_t|PadlistNAMESMAX|PADLIST padlist
35e035cc
FC
205The index of the last pad name.
206
86d2498c 207=for apidoc Amx|U32|PadlistREFCNT|PADLIST padlist
35e035cc
FC
208The reference count of the padlist. Currently this is always 1.
209
86d2498c 210=for apidoc Amx|PADNAME **|PadnamelistARRAY|PADNAMELIST pnl
35e035cc
FC
211The C array of pad names.
212
86d2498c 213=for apidoc Amx|SSize_t|PadnamelistMAX|PADNAMELIST pnl
35e035cc
FC
214The index of the last pad name.
215
9b7476d7
FC
216=for apidoc Amx|SSize_t|PadnamelistREFCNT|PADNAMELIST pnl
217The reference count of the pad name list.
218
219=for apidoc Amx|void|PadnamelistREFCNT_dec|PADNAMELIST pnl
220Lowers the reference count of the pad name list.
221
86d2498c 222=for apidoc Amx|SV **|PadARRAY|PAD pad
35e035cc
FC
223The C array of pad entries.
224
86d2498c 225=for apidoc Amx|SSize_t|PadMAX|PAD pad
35e035cc
FC
226The index of the last pad entry.
227
86d2498c 228=for apidoc Amx|char *|PadnamePV|PADNAME pn
44510545
FC
229The name stored in the pad name struct. This returns NULL for a target or
230GV slot.
35e035cc 231
86d2498c 232=for apidoc Amx|STRLEN|PadnameLEN|PADNAME pn
35e035cc
FC
233The length of the name.
234
86d2498c 235=for apidoc Amx|bool|PadnameUTF8|PADNAME pn
2502ffdf 236Whether PadnamePV is in UTF8. Currently, this is always true.
35e035cc 237
86d2498c 238=for apidoc Amx|SV *|PadnameSV|PADNAME pn
97dad6bd
FC
239Returns the pad name as an SV. This is currently just C<pn>. It will
240begin returning a new mortal SV if pad names ever stop being SVs.
241
86d2498c 242=for apidoc m|bool|PadnameIsOUR|PADNAME pn
35e035cc
FC
243Whether this is an "our" variable.
244
86d2498c 245=for apidoc m|HV *|PadnameOURSTASH
35e035cc
FC
246The stash in which this "our" variable was declared.
247
86d2498c 248=for apidoc m|bool|PadnameOUTER|PADNAME pn
c44737a2
FC
249Whether this entry belongs to an outer pad.
250
3f6a9d3a 251=for apidoc m|bool|PadnameIsSTATE|PADNAME pn
643fe368
FC
252Whether this is a "state" variable.
253
86d2498c 254=for apidoc m|HV *|PadnameTYPE|PADNAME pn
35e035cc
FC
255The stash associated with a typed lexical. This returns the %Foo:: hash
256for C<my Foo $bar>.
dd2155a4
DM
257
258
259=for apidoc m|SV *|PAD_SETSV |PADOFFSET po|SV* sv
260Set the slot at offset C<po> in the current pad to C<sv>
261
9a0afbbc 262=for apidoc m|SV *|PAD_SV |PADOFFSET po
dd2155a4
DM
263Get the value at offset C<po> in the current pad
264
265=for apidoc m|SV *|PAD_SVl |PADOFFSET po
266Lightweight and lvalue version of C<PAD_SV>.
267Get or set the value at offset C<po> in the current pad.
268Unlike C<PAD_SV>, does not print diagnostics with -DX.
269For internal use only.
270
271=for apidoc m|SV *|PAD_BASE_SV |PADLIST padlist|PADOFFSET po
272Get the value from slot C<po> in the base (DEPTH=1) pad of a padlist
273
274=for apidoc m|void|PAD_SET_CUR |PADLIST padlist|I32 n
275Set the current pad to be pad C<n> in the padlist, saving
154e47c8 276the previous current pad. NB currently this macro expands to a string too
fd617465
DM
277long for some compilers, so it's best to replace it with
278
279 SAVECOMPPAD();
280 PAD_SET_CUR_NOSAVE(padlist,n);
281
dd2155a4 282
4e380990
DM
283=for apidoc m|void|PAD_SET_CUR_NOSAVE |PADLIST padlist|I32 n
284like PAD_SET_CUR, but without the save
285
dd2155a4
DM
286=for apidoc m|void|PAD_SAVE_SETNULLPAD
287Save the current pad then set it to null.
288
f3548bdc
DM
289=for apidoc m|void|PAD_SAVE_LOCAL|PAD *opad|PAD *npad
290Save the current pad to the local variable opad, then make the
291current pad equal to npad
292
293=for apidoc m|void|PAD_RESTORE_LOCAL|PAD *opad
294Restore the old pad saved into the local variable opad by PAD_SAVE_LOCAL()
dd2155a4
DM
295
296=cut
297*/
298
86d2498c
FC
299#define PadlistARRAY(pl) (pl)->xpadl_alloc
300#define PadlistMAX(pl) (pl)->xpadl_max
9b7476d7 301#define PadlistNAMES(pl) ((PADNAMELIST *)*PadlistARRAY(pl))
86d2498c
FC
302#define PadlistNAMESARRAY(pl) PadnamelistARRAY(PadlistNAMES(pl))
303#define PadlistNAMESMAX(pl) PadnamelistMAX(PadlistNAMES(pl))
304#define PadlistREFCNT(pl) 1 /* reserved for future use */
7261499d 305
9b7476d7
FC
306#define PadnamelistARRAY(pnl) (pnl)->xpadnl_alloc
307#define PadnamelistMAX(pnl) (pnl)->xpadnl_fill
308#define PadnamelistMAXNAMED(pnl) (pnl)->xpadnl_max_named
309#define PadnamelistREFCNT(pnl) (pnl)->xpadnl_refcnt
310#define PadnamelistREFCNT_dec(pnl) Perl_padnamelist_free(aTHX_ pnl)
35e035cc 311
86d2498c
FC
312#define PadARRAY(pad) AvARRAY(pad)
313#define PadMAX(pad) AvFILLp(pad)
35e035cc 314
e1c02f84
FC
315#define PadnamePV(pn) (SvPOKp(pn) ? SvPVX_const(pn) : NULL)
316#define PadnameLEN(pn) ((SV*)(pn) == &PL_sv_undef ? 0 : SvCUR(pn))
2502ffdf 317#define PadnameUTF8(pn) (assert_(SvUTF8(pn)) 1)
86d2498c
FC
318#define PadnameSV(pn) pn
319#define PadnameIsOUR(pn) !!SvPAD_OUR(pn)
320#define PadnameOURSTASH(pn) SvOURSTASH(pn)
321#define PadnameOUTER(pn) !!SvFAKE(pn)
3f6a9d3a 322#define PadnameIsSTATE(pn) !!SvPAD_STATE(pn)
86d2498c 323#define PadnameTYPE(pn) (SvPAD_TYPED(pn) ? SvSTASH(pn) : NULL)
72af0f20
FC
324#define PadnameLVALUE(pn) \
325 ((SvFLAGS(pn) & (SVpad_NAME|SVpad_LVALUE))==(SVpad_NAME|SVpad_LVALUE))
35e035cc 326
72af0f20 327#define PadnameLVALUE_on(pn) (SvFLAGS(pn) |= SVpad_NAME|SVpad_LVALUE)
35e035cc 328
dd2155a4
DM
329#ifdef DEBUGGING
330# define PAD_SV(po) pad_sv(po)
331# define PAD_SETSV(po,sv) pad_setsv(po,sv)
332#else
333# define PAD_SV(po) (PL_curpad[po])
334# define PAD_SETSV(po,sv) PL_curpad[po] = (sv)
335#endif
336
337#define PAD_SVl(po) (PL_curpad[po])
338
339#define PAD_BASE_SV(padlist, po) \
86d2498c
FC
340 (PadlistARRAY(padlist)[1]) \
341 ? AvARRAY(MUTABLE_AV((PadlistARRAY(padlist)[1])))[po] \
7261499d 342 : NULL;
7948fc08 343
dd2155a4 344
de5e01c2 345#define PAD_SET_CUR_NOSAVE(padlist,nth) \
86d2498c 346 PL_comppad = (PAD*) (PadlistARRAY(padlist)[nth]); \
f3548bdc
DM
347 PL_curpad = AvARRAY(PL_comppad); \
348 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
61608bb7 349 "Pad 0x%" UVxf "[0x%" UVxf "] set_cur depth=%d\n", \
de5e01c2 350 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(nth)));
f3548bdc
DM
351
352
de5e01c2 353#define PAD_SET_CUR(padlist,nth) \
4e380990 354 SAVECOMPPAD(); \
de5e01c2 355 PAD_SET_CUR_NOSAVE(padlist,nth);
4e380990
DM
356
357
f3548bdc 358#define PAD_SAVE_SETNULLPAD() SAVECOMPPAD(); \
4608196e 359 PL_comppad = NULL; PL_curpad = NULL; \
f3548bdc
DM
360 DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad set_null\n"));
361
362#define PAD_SAVE_LOCAL(opad,npad) \
363 opad = PL_comppad; \
364 PL_comppad = (npad); \
4608196e 365 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \
f3548bdc 366 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
61608bb7 367 "Pad 0x%" UVxf "[0x%" UVxf "] save_local\n", \
f3548bdc
DM
368 PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
369
370#define PAD_RESTORE_LOCAL(opad) \
8c63ea58
GG
371 assert(!opad || !SvIS_FREED(opad)); \
372 PL_comppad = opad; \
4608196e 373 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \
f3548bdc 374 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
61608bb7 375 "Pad 0x%" UVxf "[0x%" UVxf "] restore_local\n", \
f3548bdc 376 PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
dd2155a4
DM
377
378
379/*
380=for apidoc m|void|CX_CURPAD_SAVE|struct context
381Save the current pad in the given context block structure.
382
f3548bdc 383=for apidoc m|SV *|CX_CURPAD_SV|struct context|PADOFFSET po
dd2155a4
DM
384Access the SV at offset po in the saved current pad in the given
385context block structure (can be used as an lvalue).
386
387=cut
388*/
389
f3548bdc 390#define CX_CURPAD_SAVE(block) (block).oldcomppad = PL_comppad
a062e10d 391#define CX_CURPAD_SV(block,po) (AvARRAY(MUTABLE_AV(((block).oldcomppad)))[po])
dd2155a4
DM
392
393
394/*
395=for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po
396Return the flags for the current compiling pad name
154e47c8 397at offset C<po>. Assumes a valid slot entry.
dd2155a4
DM
398
399=for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po
400Return the name of the current compiling pad name
154e47c8 401at offset C<po>. Assumes a valid slot entry.
dd2155a4
DM
402
403=for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po
404Return the type (stash) of the current compiling pad name at offset
154e47c8 405C<po>. Must be a valid name. Returns null if not typed.
dd2155a4
DM
406
407=for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po
408Return the stash associated with an C<our> variable.
409Assumes the slot entry is a valid C<our> lexical.
410
411=for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po
412The generation number of the name at offset C<po> in the current
154e47c8 413compiling pad (lvalue). Note that C<SvUVX> is hijacked for this purpose.
dd2155a4 414
b162af07
SP
415=for apidoc m|STRLEN|PAD_COMPNAME_GEN_set|PADOFFSET po|int gen
416Sets the generation number of the name at offset C<po> in the current
931b58fb 417ling pad (lvalue) to C<gen>. Note that C<SvUV_set> is hijacked for this purpose.
b162af07 418
dd2155a4 419=cut
b162af07 420
dd2155a4
DM
421*/
422
35e035cc 423#define PAD_COMPNAME(po) PAD_COMPNAME_SV(po)
9b7476d7 424#define PAD_COMPNAME_SV(po) (PadnamelistARRAY(PL_comppad_name)[(po)])
f8503592 425#define PAD_COMPNAME_FLAGS(po) SvFLAGS(PAD_COMPNAME_SV(po))
1979170b 426#define PAD_COMPNAME_FLAGS_isOUR(po) SvPAD_OUR(PAD_COMPNAME_SV(po))
e1c02f84 427#define PAD_COMPNAME_PV(po) PadnamePV(PAD_COMPNAME(po))
dd2155a4 428
afb6e3f5 429#define PAD_COMPNAME_TYPE(po) PadnameTYPE(PAD_COMPNAME(po))
dd2155a4
DM
430
431#define PAD_COMPNAME_OURSTASH(po) \
73d95100 432 (SvOURSTASH(PAD_COMPNAME_SV(po)))
dd2155a4 433
9b7476d7
FC
434#define PAD_COMPNAME_GEN(po) \
435 ((STRLEN)SvUVX(PadnamelistARRAY(PL_comppad_name)[po]))
dd2155a4 436
9b7476d7
FC
437#define PAD_COMPNAME_GEN_set(po, gen) \
438 SvUV_set(PadnamelistARRAY(PL_comppad_name)[po], (UV)(gen))
dd2155a4
DM
439
440
441/*
d77cdebf 442=for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl|CLONE_PARAMS* param
dd2155a4
DM
443Clone the state variables associated with running and compiling pads.
444
445=cut
446*/
447
c5ab0850
DM
448/* NB - we set PL_comppad to null unless it points at a value that
449 * has already been dup'ed, ie it points to part of an active padlist.
450 * Otherwise PL_comppad ends up being a leaked scalar in code like
451 * the following:
452 * threads->create(sub { threads->create(sub {...} ) } );
453 * where the second thread dups the outer sub's comppad but not the
454 * sub's CV or padlist. */
f3548bdc 455
dd2155a4 456#define PAD_CLONE_VARS(proto_perl, param) \
253649d9 457 PL_comppad = av_dup(proto_perl->Icomppad, param); \
4608196e 458 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \
9b7476d7
FC
459 PL_comppad_name = \
460 padnamelist_dup(proto_perl->Icomppad_name, param); \
dd2155a4
DM
461 PL_comppad_name_fill = proto_perl->Icomppad_name_fill; \
462 PL_comppad_name_floor = proto_perl->Icomppad_name_floor; \
dd2155a4
DM
463 PL_min_intro_pending = proto_perl->Imin_intro_pending; \
464 PL_max_intro_pending = proto_perl->Imax_intro_pending; \
465 PL_padix = proto_perl->Ipadix; \
466 PL_padix_floor = proto_perl->Ipadix_floor; \
467 PL_pad_reset_pending = proto_perl->Ipad_reset_pending; \
468 PL_cop_seqmax = proto_perl->Icop_seqmax;
e9a8c099
MHM
469
470/*
cc76b5cc
Z
471=for apidoc Am|PADOFFSET|pad_add_name_pvs|const char *name|U32 flags|HV *typestash|HV *ourstash
472
473Exactly like L</pad_add_name_pvn>, but takes a literal string instead
474of a string/length pair.
475
476=cut
477*/
478
479#define pad_add_name_pvs(name,flags,typestash,ourstash) \
480 Perl_pad_add_name_pvn(aTHX_ STR_WITH_LEN(name), flags, typestash, ourstash)
481
482/*
483=for apidoc Am|PADOFFSET|pad_findmy_pvs|const char *name|U32 flags
484
485Exactly like L</pad_findmy_pvn>, but takes a literal string instead
486of a string/length pair.
487
488=cut
489*/
490
491#define pad_findmy_pvs(name,flags) \
492 Perl_pad_findmy_pvn(aTHX_ STR_WITH_LEN(name), flags)
493
494/*
e9a8c099
MHM
495 * Local variables:
496 * c-indentation-style: bsd
497 * c-basic-offset: 4
14d04a33 498 * indent-tabs-mode: nil
e9a8c099
MHM
499 * End:
500 *
14d04a33 501 * ex: set ts=8 sts=4 sw=4 et:
e9a8c099 502 */