Commit | Line | Data |
---|---|---|
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 | |
22 | typedef U32TYPE PADOFFSET; | |
23 | #else | |
24 | # if PTRSIZE == 8 | |
25 | typedef 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 | |
34 | struct 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 |
40 | struct 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 | ||
133 | typedef 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 | |
178 | Save a pad slot (used to restore after an iteration) | |
179 | ||
f3548bdc | 180 | XXX DAPM it would make more sense to make the arg a PADOFFSET |
dd2155a4 | 181 | =for apidoc m|void|SAVECLEARSV |SV **svp |
154e47c8 FC |
182 | Clear 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 | 186 | save PL_comppad and PL_curpad |
dd2155a4 | 187 | |
dd2155a4 | 188 | |
86d2498c | 189 | =for apidoc Amx|PAD **|PadlistARRAY|PADLIST padlist |
35e035cc FC |
190 | The C array of a padlist, containing the pads. Only subscript it with |
191 | numbers >= 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 |
194 | The index of the last allocated space in the padlist. Note that the last |
195 | pad may be in an earlier slot. Any entries following it will be NULL in | |
196 | that case. | |
35e035cc | 197 | |
86d2498c | 198 | =for apidoc Amx|PADNAMELIST *|PadlistNAMES|PADLIST padlist |
35e035cc FC |
199 | The names associated with pad entries. |
200 | ||
86d2498c | 201 | =for apidoc Amx|PADNAME **|PadlistNAMESARRAY|PADLIST padlist |
35e035cc FC |
202 | The C array of pad names. |
203 | ||
86d2498c | 204 | =for apidoc Amx|SSize_t|PadlistNAMESMAX|PADLIST padlist |
35e035cc FC |
205 | The index of the last pad name. |
206 | ||
86d2498c | 207 | =for apidoc Amx|U32|PadlistREFCNT|PADLIST padlist |
35e035cc FC |
208 | The reference count of the padlist. Currently this is always 1. |
209 | ||
86d2498c | 210 | =for apidoc Amx|PADNAME **|PadnamelistARRAY|PADNAMELIST pnl |
35e035cc FC |
211 | The C array of pad names. |
212 | ||
86d2498c | 213 | =for apidoc Amx|SSize_t|PadnamelistMAX|PADNAMELIST pnl |
35e035cc FC |
214 | The index of the last pad name. |
215 | ||
9b7476d7 FC |
216 | =for apidoc Amx|SSize_t|PadnamelistREFCNT|PADNAMELIST pnl |
217 | The reference count of the pad name list. | |
218 | ||
219 | =for apidoc Amx|void|PadnamelistREFCNT_dec|PADNAMELIST pnl | |
220 | Lowers the reference count of the pad name list. | |
221 | ||
86d2498c | 222 | =for apidoc Amx|SV **|PadARRAY|PAD pad |
35e035cc FC |
223 | The C array of pad entries. |
224 | ||
86d2498c | 225 | =for apidoc Amx|SSize_t|PadMAX|PAD pad |
35e035cc FC |
226 | The index of the last pad entry. |
227 | ||
86d2498c | 228 | =for apidoc Amx|char *|PadnamePV|PADNAME pn |
863f2221 FC |
229 | The name stored in the pad name struct. This returns NULL for a target |
230 | slot. | |
35e035cc | 231 | |
86d2498c | 232 | =for apidoc Amx|STRLEN|PadnameLEN|PADNAME pn |
35e035cc FC |
233 | The length of the name. |
234 | ||
86d2498c | 235 | =for apidoc Amx|bool|PadnameUTF8|PADNAME pn |
2502ffdf | 236 | Whether PadnamePV is in UTF8. Currently, this is always true. |
35e035cc | 237 | |
86d2498c | 238 | =for apidoc Amx|SV *|PadnameSV|PADNAME pn |
97dad6bd FC |
239 | Returns the pad name as an SV. This is currently just C<pn>. It will |
240 | begin returning a new mortal SV if pad names ever stop being SVs. | |
241 | ||
86d2498c | 242 | =for apidoc m|bool|PadnameIsOUR|PADNAME pn |
35e035cc FC |
243 | Whether this is an "our" variable. |
244 | ||
86d2498c | 245 | =for apidoc m|HV *|PadnameOURSTASH |
35e035cc FC |
246 | The stash in which this "our" variable was declared. |
247 | ||
86d2498c | 248 | =for apidoc m|bool|PadnameOUTER|PADNAME pn |
b19cb98d FC |
249 | Whether this entry belongs to an outer pad. Entries for which this is true |
250 | are often referred to as 'fake'. | |
c44737a2 | 251 | |
3f6a9d3a | 252 | =for apidoc m|bool|PadnameIsSTATE|PADNAME pn |
643fe368 FC |
253 | Whether this is a "state" variable. |
254 | ||
86d2498c | 255 | =for apidoc m|HV *|PadnameTYPE|PADNAME pn |
35e035cc FC |
256 | The stash associated with a typed lexical. This returns the %Foo:: hash |
257 | for C<my Foo $bar>. | |
dd2155a4 DM |
258 | |
259 | ||
260 | =for apidoc m|SV *|PAD_SETSV |PADOFFSET po|SV* sv | |
261 | Set the slot at offset C<po> in the current pad to C<sv> | |
262 | ||
9a0afbbc | 263 | =for apidoc m|SV *|PAD_SV |PADOFFSET po |
dd2155a4 DM |
264 | Get the value at offset C<po> in the current pad |
265 | ||
266 | =for apidoc m|SV *|PAD_SVl |PADOFFSET po | |
267 | Lightweight and lvalue version of C<PAD_SV>. | |
268 | Get or set the value at offset C<po> in the current pad. | |
269 | Unlike C<PAD_SV>, does not print diagnostics with -DX. | |
270 | For internal use only. | |
271 | ||
272 | =for apidoc m|SV *|PAD_BASE_SV |PADLIST padlist|PADOFFSET po | |
273 | Get the value from slot C<po> in the base (DEPTH=1) pad of a padlist | |
274 | ||
275 | =for apidoc m|void|PAD_SET_CUR |PADLIST padlist|I32 n | |
276 | Set the current pad to be pad C<n> in the padlist, saving | |
154e47c8 | 277 | the previous current pad. NB currently this macro expands to a string too |
fd617465 DM |
278 | long for some compilers, so it's best to replace it with |
279 | ||
280 | SAVECOMPPAD(); | |
281 | PAD_SET_CUR_NOSAVE(padlist,n); | |
282 | ||
dd2155a4 | 283 | |
4e380990 DM |
284 | =for apidoc m|void|PAD_SET_CUR_NOSAVE |PADLIST padlist|I32 n |
285 | like PAD_SET_CUR, but without the save | |
286 | ||
dd2155a4 DM |
287 | =for apidoc m|void|PAD_SAVE_SETNULLPAD |
288 | Save the current pad then set it to null. | |
289 | ||
f3548bdc DM |
290 | =for apidoc m|void|PAD_SAVE_LOCAL|PAD *opad|PAD *npad |
291 | Save the current pad to the local variable opad, then make the | |
292 | current pad equal to npad | |
293 | ||
294 | =for apidoc m|void|PAD_RESTORE_LOCAL|PAD *opad | |
295 | Restore the old pad saved into the local variable opad by PAD_SAVE_LOCAL() | |
dd2155a4 DM |
296 | |
297 | =cut | |
298 | */ | |
299 | ||
86d2498c FC |
300 | #define PadlistARRAY(pl) (pl)->xpadl_alloc |
301 | #define PadlistMAX(pl) (pl)->xpadl_max | |
9b7476d7 | 302 | #define PadlistNAMES(pl) ((PADNAMELIST *)*PadlistARRAY(pl)) |
86d2498c FC |
303 | #define PadlistNAMESARRAY(pl) PadnamelistARRAY(PadlistNAMES(pl)) |
304 | #define PadlistNAMESMAX(pl) PadnamelistMAX(PadlistNAMES(pl)) | |
305 | #define PadlistREFCNT(pl) 1 /* reserved for future use */ | |
7261499d | 306 | |
9b7476d7 FC |
307 | #define PadnamelistARRAY(pnl) (pnl)->xpadnl_alloc |
308 | #define PadnamelistMAX(pnl) (pnl)->xpadnl_fill | |
309 | #define PadnamelistMAXNAMED(pnl) (pnl)->xpadnl_max_named | |
310 | #define PadnamelistREFCNT(pnl) (pnl)->xpadnl_refcnt | |
311 | #define PadnamelistREFCNT_dec(pnl) Perl_padnamelist_free(aTHX_ pnl) | |
35e035cc | 312 | |
86d2498c FC |
313 | #define PadARRAY(pad) AvARRAY(pad) |
314 | #define PadMAX(pad) AvFILLp(pad) | |
35e035cc | 315 | |
e1c02f84 FC |
316 | #define PadnamePV(pn) (SvPOKp(pn) ? SvPVX_const(pn) : NULL) |
317 | #define PadnameLEN(pn) ((SV*)(pn) == &PL_sv_undef ? 0 : SvCUR(pn)) | |
2502ffdf | 318 | #define PadnameUTF8(pn) (assert_(SvUTF8(pn)) 1) |
86d2498c FC |
319 | #define PadnameSV(pn) pn |
320 | #define PadnameIsOUR(pn) !!SvPAD_OUR(pn) | |
321 | #define PadnameOURSTASH(pn) SvOURSTASH(pn) | |
322 | #define PadnameOUTER(pn) !!SvFAKE(pn) | |
3f6a9d3a | 323 | #define PadnameIsSTATE(pn) !!SvPAD_STATE(pn) |
86d2498c | 324 | #define PadnameTYPE(pn) (SvPAD_TYPED(pn) ? SvSTASH(pn) : NULL) |
72af0f20 FC |
325 | #define PadnameLVALUE(pn) \ |
326 | ((SvFLAGS(pn) & (SVpad_NAME|SVpad_LVALUE))==(SVpad_NAME|SVpad_LVALUE)) | |
35e035cc | 327 | |
72af0f20 | 328 | #define PadnameLVALUE_on(pn) (SvFLAGS(pn) |= SVpad_NAME|SVpad_LVALUE) |
35e035cc | 329 | |
dd2155a4 DM |
330 | #ifdef DEBUGGING |
331 | # define PAD_SV(po) pad_sv(po) | |
332 | # define PAD_SETSV(po,sv) pad_setsv(po,sv) | |
333 | #else | |
334 | # define PAD_SV(po) (PL_curpad[po]) | |
335 | # define PAD_SETSV(po,sv) PL_curpad[po] = (sv) | |
336 | #endif | |
337 | ||
338 | #define PAD_SVl(po) (PL_curpad[po]) | |
339 | ||
340 | #define PAD_BASE_SV(padlist, po) \ | |
86d2498c FC |
341 | (PadlistARRAY(padlist)[1]) \ |
342 | ? AvARRAY(MUTABLE_AV((PadlistARRAY(padlist)[1])))[po] \ | |
7261499d | 343 | : NULL; |
7948fc08 | 344 | |
dd2155a4 | 345 | |
de5e01c2 | 346 | #define PAD_SET_CUR_NOSAVE(padlist,nth) \ |
86d2498c | 347 | PL_comppad = (PAD*) (PadlistARRAY(padlist)[nth]); \ |
f3548bdc DM |
348 | PL_curpad = AvARRAY(PL_comppad); \ |
349 | DEBUG_Xv(PerlIO_printf(Perl_debug_log, \ | |
61608bb7 | 350 | "Pad 0x%" UVxf "[0x%" UVxf "] set_cur depth=%d\n", \ |
de5e01c2 | 351 | PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(nth))); |
f3548bdc DM |
352 | |
353 | ||
de5e01c2 | 354 | #define PAD_SET_CUR(padlist,nth) \ |
4e380990 | 355 | SAVECOMPPAD(); \ |
de5e01c2 | 356 | PAD_SET_CUR_NOSAVE(padlist,nth); |
4e380990 DM |
357 | |
358 | ||
f3548bdc | 359 | #define PAD_SAVE_SETNULLPAD() SAVECOMPPAD(); \ |
4608196e | 360 | PL_comppad = NULL; PL_curpad = NULL; \ |
f3548bdc DM |
361 | DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad set_null\n")); |
362 | ||
363 | #define PAD_SAVE_LOCAL(opad,npad) \ | |
364 | opad = PL_comppad; \ | |
365 | PL_comppad = (npad); \ | |
4608196e | 366 | PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \ |
f3548bdc | 367 | DEBUG_Xv(PerlIO_printf(Perl_debug_log, \ |
61608bb7 | 368 | "Pad 0x%" UVxf "[0x%" UVxf "] save_local\n", \ |
f3548bdc DM |
369 | PTR2UV(PL_comppad), PTR2UV(PL_curpad))); |
370 | ||
371 | #define PAD_RESTORE_LOCAL(opad) \ | |
8c63ea58 GG |
372 | assert(!opad || !SvIS_FREED(opad)); \ |
373 | PL_comppad = opad; \ | |
4608196e | 374 | PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \ |
f3548bdc | 375 | DEBUG_Xv(PerlIO_printf(Perl_debug_log, \ |
61608bb7 | 376 | "Pad 0x%" UVxf "[0x%" UVxf "] restore_local\n", \ |
f3548bdc | 377 | PTR2UV(PL_comppad), PTR2UV(PL_curpad))); |
dd2155a4 DM |
378 | |
379 | ||
380 | /* | |
381 | =for apidoc m|void|CX_CURPAD_SAVE|struct context | |
382 | Save the current pad in the given context block structure. | |
383 | ||
f3548bdc | 384 | =for apidoc m|SV *|CX_CURPAD_SV|struct context|PADOFFSET po |
dd2155a4 DM |
385 | Access the SV at offset po in the saved current pad in the given |
386 | context block structure (can be used as an lvalue). | |
387 | ||
388 | =cut | |
389 | */ | |
390 | ||
f3548bdc | 391 | #define CX_CURPAD_SAVE(block) (block).oldcomppad = PL_comppad |
a062e10d | 392 | #define CX_CURPAD_SV(block,po) (AvARRAY(MUTABLE_AV(((block).oldcomppad)))[po]) |
dd2155a4 DM |
393 | |
394 | ||
395 | /* | |
396 | =for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po | |
397 | Return the flags for the current compiling pad name | |
154e47c8 | 398 | at offset C<po>. Assumes a valid slot entry. |
dd2155a4 DM |
399 | |
400 | =for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po | |
401 | Return the name of the current compiling pad name | |
154e47c8 | 402 | at offset C<po>. Assumes a valid slot entry. |
dd2155a4 DM |
403 | |
404 | =for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po | |
405 | Return the type (stash) of the current compiling pad name at offset | |
154e47c8 | 406 | C<po>. Must be a valid name. Returns null if not typed. |
dd2155a4 DM |
407 | |
408 | =for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po | |
409 | Return the stash associated with an C<our> variable. | |
410 | Assumes the slot entry is a valid C<our> lexical. | |
411 | ||
412 | =for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po | |
413 | The generation number of the name at offset C<po> in the current | |
154e47c8 | 414 | compiling pad (lvalue). Note that C<SvUVX> is hijacked for this purpose. |
dd2155a4 | 415 | |
b162af07 SP |
416 | =for apidoc m|STRLEN|PAD_COMPNAME_GEN_set|PADOFFSET po|int gen |
417 | Sets the generation number of the name at offset C<po> in the current | |
931b58fb | 418 | ling pad (lvalue) to C<gen>. Note that C<SvUV_set> is hijacked for this purpose. |
b162af07 | 419 | |
dd2155a4 | 420 | =cut |
b162af07 | 421 | |
dd2155a4 DM |
422 | */ |
423 | ||
35e035cc | 424 | #define PAD_COMPNAME(po) PAD_COMPNAME_SV(po) |
9b7476d7 | 425 | #define PAD_COMPNAME_SV(po) (PadnamelistARRAY(PL_comppad_name)[(po)]) |
f8503592 | 426 | #define PAD_COMPNAME_FLAGS(po) SvFLAGS(PAD_COMPNAME_SV(po)) |
1979170b | 427 | #define PAD_COMPNAME_FLAGS_isOUR(po) SvPAD_OUR(PAD_COMPNAME_SV(po)) |
e1c02f84 | 428 | #define PAD_COMPNAME_PV(po) PadnamePV(PAD_COMPNAME(po)) |
dd2155a4 | 429 | |
afb6e3f5 | 430 | #define PAD_COMPNAME_TYPE(po) PadnameTYPE(PAD_COMPNAME(po)) |
dd2155a4 DM |
431 | |
432 | #define PAD_COMPNAME_OURSTASH(po) \ | |
73d95100 | 433 | (SvOURSTASH(PAD_COMPNAME_SV(po))) |
dd2155a4 | 434 | |
9b7476d7 FC |
435 | #define PAD_COMPNAME_GEN(po) \ |
436 | ((STRLEN)SvUVX(PadnamelistARRAY(PL_comppad_name)[po])) | |
dd2155a4 | 437 | |
9b7476d7 FC |
438 | #define PAD_COMPNAME_GEN_set(po, gen) \ |
439 | SvUV_set(PadnamelistARRAY(PL_comppad_name)[po], (UV)(gen)) | |
dd2155a4 DM |
440 | |
441 | ||
442 | /* | |
d77cdebf | 443 | =for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl|CLONE_PARAMS* param |
dd2155a4 DM |
444 | Clone the state variables associated with running and compiling pads. |
445 | ||
446 | =cut | |
447 | */ | |
448 | ||
c5ab0850 DM |
449 | /* NB - we set PL_comppad to null unless it points at a value that |
450 | * has already been dup'ed, ie it points to part of an active padlist. | |
451 | * Otherwise PL_comppad ends up being a leaked scalar in code like | |
452 | * the following: | |
453 | * threads->create(sub { threads->create(sub {...} ) } ); | |
454 | * where the second thread dups the outer sub's comppad but not the | |
455 | * sub's CV or padlist. */ | |
f3548bdc | 456 | |
dd2155a4 | 457 | #define PAD_CLONE_VARS(proto_perl, param) \ |
253649d9 | 458 | PL_comppad = av_dup(proto_perl->Icomppad, param); \ |
4608196e | 459 | PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \ |
9b7476d7 FC |
460 | PL_comppad_name = \ |
461 | padnamelist_dup(proto_perl->Icomppad_name, param); \ | |
dd2155a4 DM |
462 | PL_comppad_name_fill = proto_perl->Icomppad_name_fill; \ |
463 | PL_comppad_name_floor = proto_perl->Icomppad_name_floor; \ | |
dd2155a4 DM |
464 | PL_min_intro_pending = proto_perl->Imin_intro_pending; \ |
465 | PL_max_intro_pending = proto_perl->Imax_intro_pending; \ | |
466 | PL_padix = proto_perl->Ipadix; \ | |
467 | PL_padix_floor = proto_perl->Ipadix_floor; \ | |
468 | PL_pad_reset_pending = proto_perl->Ipad_reset_pending; \ | |
469 | PL_cop_seqmax = proto_perl->Icop_seqmax; | |
e9a8c099 MHM |
470 | |
471 | /* | |
cc76b5cc Z |
472 | =for apidoc Am|PADOFFSET|pad_add_name_pvs|const char *name|U32 flags|HV *typestash|HV *ourstash |
473 | ||
474 | Exactly like L</pad_add_name_pvn>, but takes a literal string instead | |
475 | of a string/length pair. | |
476 | ||
477 | =cut | |
478 | */ | |
479 | ||
480 | #define pad_add_name_pvs(name,flags,typestash,ourstash) \ | |
481 | Perl_pad_add_name_pvn(aTHX_ STR_WITH_LEN(name), flags, typestash, ourstash) | |
482 | ||
483 | /* | |
484 | =for apidoc Am|PADOFFSET|pad_findmy_pvs|const char *name|U32 flags | |
485 | ||
486 | Exactly like L</pad_findmy_pvn>, but takes a literal string instead | |
487 | of a string/length pair. | |
488 | ||
489 | =cut | |
490 | */ | |
491 | ||
492 | #define pad_findmy_pvs(name,flags) \ | |
493 | Perl_pad_findmy_pvn(aTHX_ STR_WITH_LEN(name), flags) | |
494 | ||
495 | /* | |
e9a8c099 MHM |
496 | * Local variables: |
497 | * c-indentation-style: bsd | |
498 | * c-basic-offset: 4 | |
14d04a33 | 499 | * indent-tabs-mode: nil |
e9a8c099 MHM |
500 | * End: |
501 | * | |
14d04a33 | 502 | * ex: set ts=8 sts=4 sw=4 et: |
e9a8c099 | 503 | */ |