This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Promote v5.36 usage and feature bundles doc
[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
dd2155a4
DM
14/* offsets within a pad */
15
d081a355 16typedef SSize_t PADOFFSET; /* signed so that -1 is a valid value */
dd2155a4 17#define NOT_IN_PAD ((PADOFFSET) -1)
809abb02 18
9b7476d7
FC
19/* B.xs expects the first members of these two structs to line up
20 (xpadl_max with xpadnl_fill).
21 */
7261499d
FC
22
23struct padlist {
24 SSize_t xpadl_max; /* max index for which array has space */
30dc90f1 25 union {
1604cfb0
MS
26 PAD ** xpadlarr_alloc; /* Pointer to beginning of array of AVs.
27 index 0 is a padnamelist * */
28 struct {
29 PADNAMELIST * padnl;
30 PAD * pad_1; /* this slice of PAD * array always alloced */
31 PAD * pad_2; /* maybe unalloced */
32 } * xpadlarr_dbg; /* for use with a C debugger only */
30dc90f1 33 } xpadl_arr;
b4db5868
FC
34 U32 xpadl_id; /* Semi-unique ID, shared between clones */
35 U32 xpadl_outid; /* ID of outer pad */
7261499d
FC
36};
37
9b7476d7
FC
38struct padnamelist {
39 SSize_t xpadnl_fill; /* max index in use */
40 PADNAME ** xpadnl_alloc; /* pointer to beginning of array */
41 SSize_t xpadnl_max; /* max index for which array has space */
42 PADOFFSET xpadnl_max_named; /* highest index with len > 0 */
43 U32 xpadnl_refcnt;
44};
45
66230865
FC
46/* PERL_PADNAME_MINIMAL uses less memory, but on some platforms
47 PERL_PADNAME_ALIGNED may be faster, so platform-specific hints can
48 define one or the other. */
49#if defined(PERL_PADNAME_MINIMAL) && defined (PERL_PADNAME_ALIGNED)
50# error PERL_PADNAME_MINIMAL and PERL_PADNAME_ALIGNED are exclusive
51#endif
52
53#if !defined(PERL_PADNAME_MINIMAL) && !defined(PERL_PADNAME_ALIGNED)
3d6de2cd 54# define PERL_PADNAME_MINIMAL
66230865
FC
55#endif
56
57#define _PADNAME_BASE \
58 char * xpadn_pv; \
59 HV * xpadn_ourstash; \
60 union { \
1604cfb0
MS
61 HV * xpadn_typestash; \
62 CV * xpadn_protocv; \
66230865
FC
63 } xpadn_type_u; \
64 U32 xpadn_low; \
65 U32 xpadn_high; \
66 U32 xpadn_refcnt; \
67 int xpadn_gen; \
68 U8 xpadn_len; \
69 U8 xpadn_flags
70
0f94cb1f 71struct padname {
66230865 72 _PADNAME_BASE;
0f94cb1f
FC
73};
74
75struct padname_with_str {
66230865
FC
76#ifdef PERL_PADNAME_MINIMAL
77 _PADNAME_BASE;
78#else
0f94cb1f 79 struct padname xpadn_padname;
66230865 80#endif
0f94cb1f
FC
81 char xpadn_str[1];
82};
83
66230865
FC
84#undef _PADNAME_BASE
85
0f94cb1f
FC
86#define PADNAME_FROM_PV(s) \
87 ((PADNAME *)((s) - STRUCT_OFFSET(struct padname_with_str, xpadn_str)))
88
7261499d 89
2df5bdd7
DM
90/* a value that PL_cop_seqmax is guaranteed never to be,
91 * flagging that a lexical is being introduced, or has not yet left scope
92 */
93#define PERL_PADSEQ_INTRO U32_MAX
953c8b80 94#define COP_SEQMAX_INC \
1604cfb0
MS
95 (PL_cop_seqmax++, \
96 (void)(PL_cop_seqmax == PERL_PADSEQ_INTRO && PL_cop_seqmax++))
2df5bdd7
DM
97
98
7948fc08 99/* B.xs needs these for the benefit of B::Deparse */
809abb02 100/* Low range end is exclusive (valid from the cop seq after this one) */
809abb02 101/* High range end is inclusive (valid up to this cop seq) */
809abb02 102
0f94cb1f
FC
103#define COP_SEQ_RANGE_LOW(pn) (pn)->xpadn_low
104#define COP_SEQ_RANGE_HIGH(pn) (pn)->xpadn_high
105#define PARENT_PAD_INDEX(pn) (pn)->xpadn_low
106#define PARENT_FAKELEX_FLAGS(pn) (pn)->xpadn_high
dd2155a4 107
6c5e080d 108/* Flags set in the SvIVX field of FAKE namesvs */
7948fc08 109
6c5e080d
NC
110#define PAD_FAKELEX_ANON 1 /* the lex is declared in an ANON, or ... */
111#define PAD_FAKELEX_MULTI 2 /* the lex can be instantiated multiple times */
112
dd2155a4
DM
113/* flags for the pad_new() function */
114
c7c737cb
DM
115#define padnew_CLONE 1 /* this pad is for a cloned CV */
116#define padnew_SAVE 2 /* save old globals */
117#define padnew_SAVESUB 4 /* also save extra stuff for start of sub */
dd2155a4
DM
118
119/* values for the pad_tidy() function */
120
121typedef enum {
1604cfb0
MS
122 padtidy_SUB, /* tidy up a pad for a sub, */
123 padtidy_SUBCLONE, /* a cloned sub, */
124 padtidy_FORMAT /* or a format */
dd2155a4
DM
125} padtidy_type;
126
9f6ec8dd 127/* flags for pad_add_name_pvn. */
35f82371 128
9f6ec8dd
BF
129#define padadd_OUR 0x01 /* our declaration. */
130#define padadd_STATE 0x02 /* state declaration. */
131#define padadd_NO_DUP_CHECK 0x04 /* skip warning on dups. */
7ef30830 132#define padadd_STALEOK 0x08 /* allow stale lexical in active
1604cfb0 133 * sub, but only one level up */
35f82371 134
f3548bdc
DM
135/* ASSERT_CURPAD_LEGAL and ASSERT_CURPAD_ACTIVE respectively determine
136 * whether PL_comppad and PL_curpad are consistent and whether they have
137 * active values */
dd2155a4 138
1dba731d 139# define pad_peg(label)
1dba731d 140
f3548bdc
DM
141#ifdef DEBUGGING
142# define ASSERT_CURPAD_LEGAL(label) \
1dba731d 143 pad_peg(label); \
f3548bdc 144 if (PL_comppad ? (AvARRAY(PL_comppad) != PL_curpad) : (PL_curpad != 0)) \
1604cfb0
MS
145 Perl_croak(aTHX_ "panic: illegal pad in %s: 0x%" UVxf "[0x%" UVxf "]",\
146 label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
f3548bdc
DM
147
148
149# define ASSERT_CURPAD_ACTIVE(label) \
1dba731d 150 pad_peg(label); \
f3548bdc 151 if (!PL_comppad || (AvARRAY(PL_comppad) != PL_curpad)) \
1604cfb0
MS
152 Perl_croak(aTHX_ "panic: invalid pad in %s: 0x%" UVxf "[0x%" UVxf "]",\
153 label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
f3548bdc
DM
154#else
155# define ASSERT_CURPAD_LEGAL(label)
156# define ASSERT_CURPAD_ACTIVE(label)
157#endif
158
159
160
161/* Note: the following three macros are actually defined in scope.h, but
dd2155a4
DM
162 * they are documented here for completeness, since they directly or
163 * indirectly affect pads.
164
165=for apidoc m|void|SAVEPADSV |PADOFFSET po
166Save a pad slot (used to restore after an iteration)
167
300ca747
KW
168=cut
169
f3548bdc 170XXX DAPM it would make more sense to make the arg a PADOFFSET
300ca747 171
dd2155a4 172=for apidoc m|void|SAVECLEARSV |SV **svp
154e47c8 173Clear the pointed to pad value on scope exit. (i.e. the runtime action of
796b6530 174C<my>)
dd2155a4
DM
175
176=for apidoc m|void|SAVECOMPPAD
796b6530 177save C<PL_comppad> and C<PL_curpad>
dd2155a4 178
dd2155a4 179
314fdcc2 180=for apidoc Amx|PAD **|PadlistARRAY|PADLIST * padlist
35e035cc
FC
181The C array of a padlist, containing the pads. Only subscript it with
182numbers >= 1, as the 0th entry is not guaranteed to remain usable.
dd2155a4 183
314fdcc2 184=for apidoc Amx|SSize_t|PadlistMAX|PADLIST * padlist
57ee99bb 185The index of the last allocated space in the padlist. Note that the last
796b6530 186pad may be in an earlier slot. Any entries following it will be C<NULL> in
57ee99bb 187that case.
35e035cc 188
314fdcc2 189=for apidoc Amx|PADNAMELIST *|PadlistNAMES|PADLIST * padlist
35e035cc
FC
190The names associated with pad entries.
191
314fdcc2 192=for apidoc Amx|PADNAME **|PadlistNAMESARRAY|PADLIST * padlist
35e035cc
FC
193The C array of pad names.
194
314fdcc2 195=for apidoc Amx|SSize_t|PadlistNAMESMAX|PADLIST * padlist
35e035cc
FC
196The index of the last pad name.
197
314fdcc2 198=for apidoc Amx|U32|PadlistREFCNT|PADLIST * padlist
35e035cc
FC
199The reference count of the padlist. Currently this is always 1.
200
314fdcc2 201=for apidoc Amx|PADNAME **|PadnamelistARRAY|PADNAMELIST * pnl
35e035cc
FC
202The C array of pad names.
203
314fdcc2 204=for apidoc Amx|SSize_t|PadnamelistMAX|PADNAMELIST * pnl
35e035cc
FC
205The index of the last pad name.
206
314fdcc2 207=for apidoc Amx|SSize_t|PadnamelistREFCNT|PADNAMELIST * pnl
9b7476d7
FC
208The reference count of the pad name list.
209
314fdcc2 210=for apidoc Amx|void|PadnamelistREFCNT_dec|PADNAMELIST * pnl
9b7476d7
FC
211Lowers the reference count of the pad name list.
212
314fdcc2 213=for apidoc Amx|SV **|PadARRAY|PAD * pad
35e035cc
FC
214The C array of pad entries.
215
314fdcc2 216=for apidoc Amx|SSize_t|PadMAX|PAD * pad
35e035cc
FC
217The index of the last pad entry.
218
314fdcc2 219=for apidoc Amx|char *|PadnamePV|PADNAME * pn
796b6530 220The name stored in the pad name struct. This returns C<NULL> for a target
863f2221 221slot.
35e035cc 222
314fdcc2 223=for apidoc Amx|STRLEN|PadnameLEN|PADNAME * pn
35e035cc
FC
224The length of the name.
225
314fdcc2 226=for apidoc Amx|bool|PadnameUTF8|PADNAME * pn
4a4088c4 227Whether PadnamePV is in UTF-8. Currently, this is always true.
35e035cc 228
314fdcc2 229=for apidoc Amx|SV *|PadnameSV|PADNAME * pn
0f94cb1f 230Returns the pad name as a mortal SV.
97dad6bd 231
314fdcc2 232=for apidoc m|bool|PadnameIsOUR|PADNAME * pn
35e035cc
FC
233Whether this is an "our" variable.
234
e935a39c 235=for apidoc m|HV *|PadnameOURSTASH|PADNAME * pn
35e035cc
FC
236The stash in which this "our" variable was declared.
237
314fdcc2 238=for apidoc m|bool|PadnameOUTER|PADNAME * pn
b19cb98d
FC
239Whether this entry belongs to an outer pad. Entries for which this is true
240are often referred to as 'fake'.
c44737a2 241
314fdcc2 242=for apidoc m|bool|PadnameIsSTATE|PADNAME * pn
643fe368
FC
243Whether this is a "state" variable.
244
314fdcc2 245=for apidoc m|HV *|PadnameTYPE|PADNAME * pn
796b6530 246The stash associated with a typed lexical. This returns the C<%Foo::> hash
35e035cc 247for C<my Foo $bar>.
dd2155a4 248
314fdcc2 249=for apidoc Amx|SSize_t|PadnameREFCNT|PADNAME * pn
0f94cb1f
FC
250The reference count of the pad name.
251
79277e97
PE
252=for apidoc Amx|PADNAME *|PadnameREFCNT_inc|PADNAME * pn
253Increases the reference count of the pad name. Returns the pad name itself.
254
314fdcc2 255=for apidoc Amx|void|PadnameREFCNT_dec|PADNAME * pn
0f94cb1f
FC
256Lowers the reference count of the pad name.
257
dd2155a4
DM
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 289=for apidoc m|void|PAD_SAVE_LOCAL|PAD *opad|PAD *npad
796b6530
KW
290Save the current pad to the local variable C<opad>, then make the
291current pad equal to C<npad>
f3548bdc
DM
292
293=for apidoc m|void|PAD_RESTORE_LOCAL|PAD *opad
796b6530 294Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()>
dd2155a4
DM
295
296=cut
297*/
298
30dc90f1 299#define PadlistARRAY(pl) (pl)->xpadl_arr.xpadlarr_alloc
86d2498c 300#define PadlistMAX(pl) (pl)->xpadl_max
73949fca 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
0f94cb1f
FC
315#define PadnamePV(pn) (pn)->xpadn_pv
316#define PadnameLEN(pn) (pn)->xpadn_len
317#define PadnameUTF8(pn) 1
318#define PadnameSV(pn) \
1604cfb0 319 newSVpvn_flags(PadnamePV(pn), PadnameLEN(pn), SVs_TEMP|SVf_UTF8)
0f94cb1f 320#define PadnameFLAGS(pn) (pn)->xpadn_flags
82943faa 321#define PadnameIsOUR(pn) cBOOL((pn)->xpadn_ourstash)
0f94cb1f
FC
322#define PadnameOURSTASH(pn) (pn)->xpadn_ourstash
323#define PadnameTYPE(pn) (pn)->xpadn_type_u.xpadn_typestash
49441290 324#define PadnameHasTYPE(pn) cBOOL(PadnameTYPE(pn))
0f94cb1f
FC
325#define PadnamePROTOCV(pn) (pn)->xpadn_type_u.xpadn_protocv
326#define PadnameREFCNT(pn) (pn)->xpadn_refcnt
79277e97 327#define PadnameREFCNT_inc(pn) Perl_padname_refcnt_inc(pn)
0f94cb1f
FC
328#define PadnameREFCNT_dec(pn) Perl_padname_free(aTHX_ pn)
329#define PadnameOURSTASH_set(pn,s) (PadnameOURSTASH(pn) = (s))
330#define PadnameTYPE_set(pn,s) (PadnameTYPE(pn) = (s))
792bf4ba
PE
331#define PadnameOUTER(pn) (PadnameFLAGS(pn) & PADNAMEf_OUTER)
332#define PadnameIsSTATE(pn) (PadnameFLAGS(pn) & PADNAMEf_STATE)
333#define PadnameLVALUE(pn) (PadnameFLAGS(pn) & PADNAMEf_LVALUE)
0f94cb1f 334
792bf4ba
PE
335#define PadnameLVALUE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_LVALUE)
336#define PadnameIsSTATE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_STATE)
0f94cb1f 337
792bf4ba
PE
338#define PADNAMEf_OUTER 0x01 /* outer lexical var */
339#define PADNAMEf_STATE 0x02 /* state var */
340#define PADNAMEf_LVALUE 0x04 /* used as lvalue */
341#define PADNAMEf_TYPED 0x08 /* for B; unused by core */
342#define PADNAMEf_OUR 0x10 /* for B; unused by core */
0f94cb1f
FC
343
344/* backward compatibility */
792bf4ba 345#ifndef PERL_CORE
49441290
PE
346# define SvPAD_STATE PadnameIsSTATE
347# define SvPAD_TYPED PadnameHasTYPE
348# define SvPAD_OUR(pn) cBOOL(PadnameOURSTASH(pn))
349# define SvPAD_STATE_on PadnameIsSTATE_on
350# define SvPAD_TYPED_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_TYPED)
351# define SvPAD_OUR_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_OUR)
352# define SvOURSTASH PadnameOURSTASH
353# define SvOURSTASH_set PadnameOURSTASH_set
354# define SVpad_STATE PADNAMEf_STATE
355# define SVpad_TYPED PADNAMEf_TYPED
356# define SVpad_OUR PADNAMEf_OUR
792bf4ba
PE
357# define PADNAMEt_OUTER PADNAMEf_OUTER
358# define PADNAMEt_STATE PADNAMEf_STATE
359# define PADNAMEt_LVALUE PADNAMEf_LVALUE
360# define PADNAMEt_TYPED PADNAMEf_TYPED
361# define PADNAMEt_OUR PADNAMEf_OUR
362#endif
35e035cc 363
dd2155a4
DM
364#ifdef DEBUGGING
365# define PAD_SV(po) pad_sv(po)
366# define PAD_SETSV(po,sv) pad_setsv(po,sv)
367#else
368# define PAD_SV(po) (PL_curpad[po])
369# define PAD_SETSV(po,sv) PL_curpad[po] = (sv)
370#endif
371
372#define PAD_SVl(po) (PL_curpad[po])
373
374#define PAD_BASE_SV(padlist, po) \
1604cfb0
MS
375 (PadlistARRAY(padlist)[1]) \
376 ? AvARRAY(MUTABLE_AV((PadlistARRAY(padlist)[1])))[po] \
377 : NULL;
7948fc08 378
dd2155a4 379
de5e01c2 380#define PAD_SET_CUR_NOSAVE(padlist,nth) \
1604cfb0
MS
381 PL_comppad = (PAD*) (PadlistARRAY(padlist)[nth]); \
382 PL_curpad = AvARRAY(PL_comppad); \
383 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
384 "Pad 0x%" UVxf "[0x%" UVxf "] set_cur depth=%d\n", \
385 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(nth)));
f3548bdc
DM
386
387
de5e01c2 388#define PAD_SET_CUR(padlist,nth) \
1604cfb0
MS
389 SAVECOMPPAD(); \
390 PAD_SET_CUR_NOSAVE(padlist,nth);
4e380990
DM
391
392
f3548bdc 393#define PAD_SAVE_SETNULLPAD() SAVECOMPPAD(); \
1604cfb0
MS
394 PL_comppad = NULL; PL_curpad = NULL; \
395 DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad set_null\n"));
f3548bdc
DM
396
397#define PAD_SAVE_LOCAL(opad,npad) \
1604cfb0
MS
398 opad = PL_comppad; \
399 PL_comppad = (npad); \
400 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \
401 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
402 "Pad 0x%" UVxf "[0x%" UVxf "] save_local\n", \
403 PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
f3548bdc
DM
404
405#define PAD_RESTORE_LOCAL(opad) \
8c63ea58 406 assert(!opad || !SvIS_FREED(opad)); \
1604cfb0
MS
407 PL_comppad = opad; \
408 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \
409 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
410 "Pad 0x%" UVxf "[0x%" UVxf "] restore_local\n", \
411 PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
dd2155a4
DM
412
413
414/*
415=for apidoc m|void|CX_CURPAD_SAVE|struct context
416Save the current pad in the given context block structure.
417
f3548bdc 418=for apidoc m|SV *|CX_CURPAD_SV|struct context|PADOFFSET po
796b6530 419Access the SV at offset C<po> in the saved current pad in the given
dd2155a4
DM
420context block structure (can be used as an lvalue).
421
422=cut
423*/
424
f3548bdc 425#define CX_CURPAD_SAVE(block) (block).oldcomppad = PL_comppad
a062e10d 426#define CX_CURPAD_SV(block,po) (AvARRAY(MUTABLE_AV(((block).oldcomppad)))[po])
dd2155a4
DM
427
428
429/*
430=for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po
431Return the flags for the current compiling pad name
154e47c8 432at offset C<po>. Assumes a valid slot entry.
dd2155a4
DM
433
434=for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po
435Return the name of the current compiling pad name
154e47c8 436at offset C<po>. Assumes a valid slot entry.
dd2155a4
DM
437
438=for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po
439Return the type (stash) of the current compiling pad name at offset
154e47c8 440C<po>. Must be a valid name. Returns null if not typed.
dd2155a4
DM
441
442=for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po
443Return the stash associated with an C<our> variable.
444Assumes the slot entry is a valid C<our> lexical.
445
446=for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po
447The generation number of the name at offset C<po> in the current
e25bbd9e 448compiling pad (lvalue).
dd2155a4 449
b162af07
SP
450=for apidoc m|STRLEN|PAD_COMPNAME_GEN_set|PADOFFSET po|int gen
451Sets the generation number of the name at offset C<po> in the current
e25bbd9e 452ling pad (lvalue) to C<gen>.
dd2155a4 453=cut
b162af07 454
dd2155a4
DM
455*/
456
35e035cc 457#define PAD_COMPNAME(po) PAD_COMPNAME_SV(po)
9b7476d7 458#define PAD_COMPNAME_SV(po) (PadnamelistARRAY(PL_comppad_name)[(po)])
0f94cb1f 459#define PAD_COMPNAME_FLAGS(po) PadnameFLAGS(PAD_COMPNAME(po))
49441290 460#define PAD_COMPNAME_FLAGS_isOUR(po) PadnameIsOUR(PAD_COMPNAME_SV(po))
e1c02f84 461#define PAD_COMPNAME_PV(po) PadnamePV(PAD_COMPNAME(po))
dd2155a4 462
afb6e3f5 463#define PAD_COMPNAME_TYPE(po) PadnameTYPE(PAD_COMPNAME(po))
dd2155a4 464
49441290 465#define PAD_COMPNAME_OURSTASH(po) (PadnameOURSTASH(PAD_COMPNAME_SV(po)))
dd2155a4 466
9b7476d7 467#define PAD_COMPNAME_GEN(po) \
0f94cb1f 468 ((STRLEN)PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen)
dd2155a4 469
9b7476d7 470#define PAD_COMPNAME_GEN_set(po, gen) \
0f94cb1f 471 (PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen = (gen))
dd2155a4
DM
472
473
474/*
d77cdebf 475=for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl|CLONE_PARAMS* param
dd2155a4
DM
476Clone the state variables associated with running and compiling pads.
477
478=cut
479*/
480
c5ab0850
DM
481/* NB - we set PL_comppad to null unless it points at a value that
482 * has already been dup'ed, ie it points to part of an active padlist.
483 * Otherwise PL_comppad ends up being a leaked scalar in code like
484 * the following:
485 * threads->create(sub { threads->create(sub {...} ) } );
486 * where the second thread dups the outer sub's comppad but not the
487 * sub's CV or padlist. */
f3548bdc 488
dd2155a4 489#define PAD_CLONE_VARS(proto_perl, param) \
253649d9 490 PL_comppad = av_dup(proto_perl->Icomppad, param); \
4608196e 491 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \
9b7476d7 492 PL_comppad_name = \
1604cfb0 493 padnamelist_dup(proto_perl->Icomppad_name, param); \
dd2155a4
DM
494 PL_comppad_name_fill = proto_perl->Icomppad_name_fill; \
495 PL_comppad_name_floor = proto_perl->Icomppad_name_floor; \
dd2155a4
DM
496 PL_min_intro_pending = proto_perl->Imin_intro_pending; \
497 PL_max_intro_pending = proto_perl->Imax_intro_pending; \
498 PL_padix = proto_perl->Ipadix; \
499 PL_padix_floor = proto_perl->Ipadix_floor; \
500 PL_pad_reset_pending = proto_perl->Ipad_reset_pending; \
501 PL_cop_seqmax = proto_perl->Icop_seqmax;
e9a8c099
MHM
502
503/*
3bb9fd01 504=for apidoc Am|PADOFFSET|pad_add_name_pvs|"name"|U32 flags|HV *typestash|HV *ourstash
cc76b5cc 505
1568d13a 506Exactly like L</pad_add_name_pvn>, but takes a literal string
0c395ea5 507instead of a string/length pair.
cc76b5cc
Z
508
509=cut
510*/
511
512#define pad_add_name_pvs(name,flags,typestash,ourstash) \
513 Perl_pad_add_name_pvn(aTHX_ STR_WITH_LEN(name), flags, typestash, ourstash)
514
515/*
3bb9fd01 516=for apidoc Am|PADOFFSET|pad_findmy_pvs|"name"|U32 flags
cc76b5cc 517
1568d13a 518Exactly like L</pad_findmy_pvn>, but takes a literal string
0c395ea5 519instead of a string/length pair.
cc76b5cc
Z
520
521=cut
522*/
523
524#define pad_findmy_pvs(name,flags) \
525 Perl_pad_findmy_pvn(aTHX_ STR_WITH_LEN(name), flags)
526
527/*
14d04a33 528 * ex: set ts=8 sts=4 sw=4 et:
e9a8c099 529 */