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