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 | ||
66230865 FC |
48 | /* PERL_PADNAME_MINIMAL uses less memory, but on some platforms |
49 | PERL_PADNAME_ALIGNED may be faster, so platform-specific hints can | |
50 | define one or the other. */ | |
51 | #if defined(PERL_PADNAME_MINIMAL) && defined (PERL_PADNAME_ALIGNED) | |
52 | # error PERL_PADNAME_MINIMAL and PERL_PADNAME_ALIGNED are exclusive | |
53 | #endif | |
54 | ||
55 | #if !defined(PERL_PADNAME_MINIMAL) && !defined(PERL_PADNAME_ALIGNED) | |
3d6de2cd | 56 | # define PERL_PADNAME_MINIMAL |
66230865 FC |
57 | #endif |
58 | ||
59 | #define _PADNAME_BASE \ | |
60 | char * xpadn_pv; \ | |
61 | HV * xpadn_ourstash; \ | |
62 | union { \ | |
63 | HV * xpadn_typestash; \ | |
64 | CV * xpadn_protocv; \ | |
65 | } xpadn_type_u; \ | |
66 | U32 xpadn_low; \ | |
67 | U32 xpadn_high; \ | |
68 | U32 xpadn_refcnt; \ | |
69 | int xpadn_gen; \ | |
70 | U8 xpadn_len; \ | |
71 | U8 xpadn_flags | |
72 | ||
0f94cb1f | 73 | struct padname { |
66230865 | 74 | _PADNAME_BASE; |
0f94cb1f FC |
75 | }; |
76 | ||
77 | struct padname_with_str { | |
66230865 FC |
78 | #ifdef PERL_PADNAME_MINIMAL |
79 | _PADNAME_BASE; | |
80 | #else | |
0f94cb1f | 81 | struct padname xpadn_padname; |
66230865 | 82 | #endif |
0f94cb1f FC |
83 | char xpadn_str[1]; |
84 | }; | |
85 | ||
66230865 FC |
86 | #undef _PADNAME_BASE |
87 | ||
0f94cb1f FC |
88 | #define PADNAME_FROM_PV(s) \ |
89 | ((PADNAME *)((s) - STRUCT_OFFSET(struct padname_with_str, xpadn_str))) | |
90 | ||
7261499d | 91 | |
2df5bdd7 DM |
92 | /* a value that PL_cop_seqmax is guaranteed never to be, |
93 | * flagging that a lexical is being introduced, or has not yet left scope | |
94 | */ | |
95 | #define PERL_PADSEQ_INTRO U32_MAX | |
953c8b80 FC |
96 | #define COP_SEQMAX_INC \ |
97 | (PL_cop_seqmax++, \ | |
98 | (void)(PL_cop_seqmax == PERL_PADSEQ_INTRO && PL_cop_seqmax++)) | |
2df5bdd7 DM |
99 | |
100 | ||
7948fc08 | 101 | /* B.xs needs these for the benefit of B::Deparse */ |
809abb02 | 102 | /* Low range end is exclusive (valid from the cop seq after this one) */ |
809abb02 | 103 | /* High range end is inclusive (valid up to this cop seq) */ |
809abb02 | 104 | |
0f94cb1f FC |
105 | #define COP_SEQ_RANGE_LOW(pn) (pn)->xpadn_low |
106 | #define COP_SEQ_RANGE_HIGH(pn) (pn)->xpadn_high | |
107 | #define PARENT_PAD_INDEX(pn) (pn)->xpadn_low | |
108 | #define PARENT_FAKELEX_FLAGS(pn) (pn)->xpadn_high | |
dd2155a4 | 109 | |
6c5e080d | 110 | /* Flags set in the SvIVX field of FAKE namesvs */ |
7948fc08 | 111 | |
6c5e080d NC |
112 | #define PAD_FAKELEX_ANON 1 /* the lex is declared in an ANON, or ... */ |
113 | #define PAD_FAKELEX_MULTI 2 /* the lex can be instantiated multiple times */ | |
114 | ||
dd2155a4 DM |
115 | /* flags for the pad_new() function */ |
116 | ||
c7c737cb DM |
117 | #define padnew_CLONE 1 /* this pad is for a cloned CV */ |
118 | #define padnew_SAVE 2 /* save old globals */ | |
119 | #define padnew_SAVESUB 4 /* also save extra stuff for start of sub */ | |
dd2155a4 DM |
120 | |
121 | /* values for the pad_tidy() function */ | |
122 | ||
123 | typedef enum { | |
124 | padtidy_SUB, /* tidy up a pad for a sub, */ | |
125 | padtidy_SUBCLONE, /* a cloned sub, */ | |
126 | padtidy_FORMAT /* or a format */ | |
127 | } padtidy_type; | |
128 | ||
9f6ec8dd | 129 | /* flags for pad_add_name_pvn. */ |
35f82371 | 130 | |
9f6ec8dd BF |
131 | #define padadd_OUR 0x01 /* our declaration. */ |
132 | #define padadd_STATE 0x02 /* state declaration. */ | |
133 | #define padadd_NO_DUP_CHECK 0x04 /* skip warning on dups. */ | |
7ef30830 FC |
134 | #define padadd_STALEOK 0x08 /* allow stale lexical in active |
135 | * sub, but only one level up */ | |
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 | ||
9b7476d7 FC |
206 | =for apidoc Amx|SSize_t|PadnamelistREFCNT|PADNAMELIST pnl |
207 | The reference count of the pad name list. | |
208 | ||
209 | =for apidoc Amx|void|PadnamelistREFCNT_dec|PADNAMELIST pnl | |
210 | Lowers the reference count of the pad name list. | |
211 | ||
86d2498c | 212 | =for apidoc Amx|SV **|PadARRAY|PAD pad |
35e035cc FC |
213 | The C array of pad entries. |
214 | ||
86d2498c | 215 | =for apidoc Amx|SSize_t|PadMAX|PAD pad |
35e035cc FC |
216 | The index of the last pad entry. |
217 | ||
86d2498c | 218 | =for apidoc Amx|char *|PadnamePV|PADNAME pn |
863f2221 FC |
219 | The name stored in the pad name struct. This returns NULL for a target |
220 | slot. | |
35e035cc | 221 | |
86d2498c | 222 | =for apidoc Amx|STRLEN|PadnameLEN|PADNAME pn |
35e035cc FC |
223 | The length of the name. |
224 | ||
86d2498c | 225 | =for apidoc Amx|bool|PadnameUTF8|PADNAME pn |
2502ffdf | 226 | Whether PadnamePV is in UTF8. Currently, this is always true. |
35e035cc | 227 | |
86d2498c | 228 | =for apidoc Amx|SV *|PadnameSV|PADNAME pn |
0f94cb1f | 229 | Returns the pad name as a mortal SV. |
97dad6bd | 230 | |
86d2498c | 231 | =for apidoc m|bool|PadnameIsOUR|PADNAME pn |
35e035cc FC |
232 | Whether this is an "our" variable. |
233 | ||
86d2498c | 234 | =for apidoc m|HV *|PadnameOURSTASH |
35e035cc FC |
235 | The stash in which this "our" variable was declared. |
236 | ||
86d2498c | 237 | =for apidoc m|bool|PadnameOUTER|PADNAME pn |
b19cb98d FC |
238 | Whether this entry belongs to an outer pad. Entries for which this is true |
239 | are often referred to as 'fake'. | |
c44737a2 | 240 | |
3f6a9d3a | 241 | =for apidoc m|bool|PadnameIsSTATE|PADNAME pn |
643fe368 FC |
242 | Whether this is a "state" variable. |
243 | ||
86d2498c | 244 | =for apidoc m|HV *|PadnameTYPE|PADNAME pn |
35e035cc FC |
245 | The stash associated with a typed lexical. This returns the %Foo:: hash |
246 | for C<my Foo $bar>. | |
dd2155a4 | 247 | |
0f94cb1f FC |
248 | =for apidoc Amx|SSize_t|PadnameREFCNT|PADNAME pn |
249 | The reference count of the pad name. | |
250 | ||
251 | =for apidoc Amx|void|PadnameREFCNT_dec|PADNAME pn | |
252 | Lowers the reference count of the pad name. | |
253 | ||
dd2155a4 DM |
254 | |
255 | =for apidoc m|SV *|PAD_SETSV |PADOFFSET po|SV* sv | |
256 | Set the slot at offset C<po> in the current pad to C<sv> | |
257 | ||
9a0afbbc | 258 | =for apidoc m|SV *|PAD_SV |PADOFFSET po |
dd2155a4 DM |
259 | Get the value at offset C<po> in the current pad |
260 | ||
261 | =for apidoc m|SV *|PAD_SVl |PADOFFSET po | |
262 | Lightweight and lvalue version of C<PAD_SV>. | |
263 | Get or set the value at offset C<po> in the current pad. | |
264 | Unlike C<PAD_SV>, does not print diagnostics with -DX. | |
265 | For internal use only. | |
266 | ||
267 | =for apidoc m|SV *|PAD_BASE_SV |PADLIST padlist|PADOFFSET po | |
268 | Get the value from slot C<po> in the base (DEPTH=1) pad of a padlist | |
269 | ||
270 | =for apidoc m|void|PAD_SET_CUR |PADLIST padlist|I32 n | |
271 | Set the current pad to be pad C<n> in the padlist, saving | |
154e47c8 | 272 | the previous current pad. NB currently this macro expands to a string too |
fd617465 DM |
273 | long for some compilers, so it's best to replace it with |
274 | ||
275 | SAVECOMPPAD(); | |
276 | PAD_SET_CUR_NOSAVE(padlist,n); | |
277 | ||
dd2155a4 | 278 | |
4e380990 DM |
279 | =for apidoc m|void|PAD_SET_CUR_NOSAVE |PADLIST padlist|I32 n |
280 | like PAD_SET_CUR, but without the save | |
281 | ||
dd2155a4 DM |
282 | =for apidoc m|void|PAD_SAVE_SETNULLPAD |
283 | Save the current pad then set it to null. | |
284 | ||
f3548bdc DM |
285 | =for apidoc m|void|PAD_SAVE_LOCAL|PAD *opad|PAD *npad |
286 | Save the current pad to the local variable opad, then make the | |
287 | current pad equal to npad | |
288 | ||
289 | =for apidoc m|void|PAD_RESTORE_LOCAL|PAD *opad | |
290 | Restore the old pad saved into the local variable opad by PAD_SAVE_LOCAL() | |
dd2155a4 DM |
291 | |
292 | =cut | |
293 | */ | |
294 | ||
86d2498c FC |
295 | #define PadlistARRAY(pl) (pl)->xpadl_alloc |
296 | #define PadlistMAX(pl) (pl)->xpadl_max | |
9b7476d7 | 297 | #define PadlistNAMES(pl) ((PADNAMELIST *)*PadlistARRAY(pl)) |
86d2498c FC |
298 | #define PadlistNAMESARRAY(pl) PadnamelistARRAY(PadlistNAMES(pl)) |
299 | #define PadlistNAMESMAX(pl) PadnamelistMAX(PadlistNAMES(pl)) | |
300 | #define PadlistREFCNT(pl) 1 /* reserved for future use */ | |
7261499d | 301 | |
9b7476d7 FC |
302 | #define PadnamelistARRAY(pnl) (pnl)->xpadnl_alloc |
303 | #define PadnamelistMAX(pnl) (pnl)->xpadnl_fill | |
304 | #define PadnamelistMAXNAMED(pnl) (pnl)->xpadnl_max_named | |
305 | #define PadnamelistREFCNT(pnl) (pnl)->xpadnl_refcnt | |
306 | #define PadnamelistREFCNT_dec(pnl) Perl_padnamelist_free(aTHX_ pnl) | |
35e035cc | 307 | |
86d2498c FC |
308 | #define PadARRAY(pad) AvARRAY(pad) |
309 | #define PadMAX(pad) AvFILLp(pad) | |
35e035cc | 310 | |
0f94cb1f FC |
311 | #define PadnamePV(pn) (pn)->xpadn_pv |
312 | #define PadnameLEN(pn) (pn)->xpadn_len | |
313 | #define PadnameUTF8(pn) 1 | |
314 | #define PadnameSV(pn) \ | |
315 | newSVpvn_flags(PadnamePV(pn), PadnameLEN(pn), SVs_TEMP|SVf_UTF8) | |
316 | #define PadnameFLAGS(pn) (pn)->xpadn_flags | |
317 | #define PadnameIsOUR(pn) (!!(pn)->xpadn_ourstash) | |
318 | #define PadnameOURSTASH(pn) (pn)->xpadn_ourstash | |
319 | #define PadnameTYPE(pn) (pn)->xpadn_type_u.xpadn_typestash | |
320 | #define PadnamePROTOCV(pn) (pn)->xpadn_type_u.xpadn_protocv | |
321 | #define PadnameREFCNT(pn) (pn)->xpadn_refcnt | |
322 | #define PadnameREFCNT_dec(pn) Perl_padname_free(aTHX_ pn) | |
323 | #define PadnameOURSTASH_set(pn,s) (PadnameOURSTASH(pn) = (s)) | |
324 | #define PadnameTYPE_set(pn,s) (PadnameTYPE(pn) = (s)) | |
325 | #define PadnameOUTER(pn) (PadnameFLAGS(pn) & PADNAMEt_OUTER) | |
326 | #define PadnameIsSTATE(pn) (PadnameFLAGS(pn) & PADNAMEt_STATE) | |
327 | #define PadnameLVALUE(pn) (PadnameFLAGS(pn) & PADNAMEt_LVALUE) | |
328 | ||
329 | #define PadnameLVALUE_on(pn) (PadnameFLAGS(pn) |= PADNAMEt_LVALUE) | |
330 | #define PadnameIsSTATE_on(pn) (PadnameFLAGS(pn) |= PADNAMEt_STATE) | |
331 | ||
332 | #define PADNAMEt_OUTER 1 /* outer lexical var */ | |
333 | #define PADNAMEt_STATE 2 /* state var */ | |
334 | #define PADNAMEt_LVALUE 4 /* used as lvalue */ | |
335 | #define PADNAMEt_TYPED 8 /* for B; unused by core */ | |
336 | #define PADNAMEt_OUR 16 /* for B; unused by core */ | |
337 | ||
338 | /* backward compatibility */ | |
339 | #define SvPAD_STATE PadnameIsSTATE | |
340 | #define SvPAD_TYPED(pn) (!!PadnameTYPE(pn)) | |
341 | #define SvPAD_OUR(pn) (!!PadnameOURSTASH(pn)) | |
342 | #define SvPAD_STATE_on PadnameIsSTATE_on | |
343 | #define SvPAD_TYPED_on(pn) (PadnameFLAGS(pn) |= PADNAMEt_TYPED) | |
344 | #define SvPAD_OUR_on(pn) (PadnameFLAGS(pn) |= PADNAMEt_OUR) | |
345 | #define SvOURSTASH PadnameOURSTASH | |
346 | #define SvOURSTASH_set PadnameOURSTASH_set | |
347 | #define SVpad_STATE PADNAMEt_STATE | |
348 | #define SVpad_TYPED PADNAMEt_TYPED | |
349 | #define SVpad_OUR PADNAMEt_OUR | |
35e035cc | 350 | |
dd2155a4 DM |
351 | #ifdef DEBUGGING |
352 | # define PAD_SV(po) pad_sv(po) | |
353 | # define PAD_SETSV(po,sv) pad_setsv(po,sv) | |
354 | #else | |
355 | # define PAD_SV(po) (PL_curpad[po]) | |
356 | # define PAD_SETSV(po,sv) PL_curpad[po] = (sv) | |
357 | #endif | |
358 | ||
359 | #define PAD_SVl(po) (PL_curpad[po]) | |
360 | ||
361 | #define PAD_BASE_SV(padlist, po) \ | |
86d2498c FC |
362 | (PadlistARRAY(padlist)[1]) \ |
363 | ? AvARRAY(MUTABLE_AV((PadlistARRAY(padlist)[1])))[po] \ | |
7261499d | 364 | : NULL; |
7948fc08 | 365 | |
dd2155a4 | 366 | |
de5e01c2 | 367 | #define PAD_SET_CUR_NOSAVE(padlist,nth) \ |
86d2498c | 368 | PL_comppad = (PAD*) (PadlistARRAY(padlist)[nth]); \ |
f3548bdc DM |
369 | PL_curpad = AvARRAY(PL_comppad); \ |
370 | DEBUG_Xv(PerlIO_printf(Perl_debug_log, \ | |
61608bb7 | 371 | "Pad 0x%" UVxf "[0x%" UVxf "] set_cur depth=%d\n", \ |
de5e01c2 | 372 | PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(nth))); |
f3548bdc DM |
373 | |
374 | ||
de5e01c2 | 375 | #define PAD_SET_CUR(padlist,nth) \ |
4e380990 | 376 | SAVECOMPPAD(); \ |
de5e01c2 | 377 | PAD_SET_CUR_NOSAVE(padlist,nth); |
4e380990 DM |
378 | |
379 | ||
f3548bdc | 380 | #define PAD_SAVE_SETNULLPAD() SAVECOMPPAD(); \ |
4608196e | 381 | PL_comppad = NULL; PL_curpad = NULL; \ |
f3548bdc DM |
382 | DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad set_null\n")); |
383 | ||
384 | #define PAD_SAVE_LOCAL(opad,npad) \ | |
385 | opad = PL_comppad; \ | |
386 | PL_comppad = (npad); \ | |
4608196e | 387 | PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \ |
f3548bdc | 388 | DEBUG_Xv(PerlIO_printf(Perl_debug_log, \ |
61608bb7 | 389 | "Pad 0x%" UVxf "[0x%" UVxf "] save_local\n", \ |
f3548bdc DM |
390 | PTR2UV(PL_comppad), PTR2UV(PL_curpad))); |
391 | ||
392 | #define PAD_RESTORE_LOCAL(opad) \ | |
8c63ea58 GG |
393 | assert(!opad || !SvIS_FREED(opad)); \ |
394 | PL_comppad = opad; \ | |
4608196e | 395 | PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \ |
f3548bdc | 396 | DEBUG_Xv(PerlIO_printf(Perl_debug_log, \ |
61608bb7 | 397 | "Pad 0x%" UVxf "[0x%" UVxf "] restore_local\n", \ |
f3548bdc | 398 | PTR2UV(PL_comppad), PTR2UV(PL_curpad))); |
dd2155a4 DM |
399 | |
400 | ||
401 | /* | |
402 | =for apidoc m|void|CX_CURPAD_SAVE|struct context | |
403 | Save the current pad in the given context block structure. | |
404 | ||
f3548bdc | 405 | =for apidoc m|SV *|CX_CURPAD_SV|struct context|PADOFFSET po |
dd2155a4 DM |
406 | Access the SV at offset po in the saved current pad in the given |
407 | context block structure (can be used as an lvalue). | |
408 | ||
409 | =cut | |
410 | */ | |
411 | ||
f3548bdc | 412 | #define CX_CURPAD_SAVE(block) (block).oldcomppad = PL_comppad |
a062e10d | 413 | #define CX_CURPAD_SV(block,po) (AvARRAY(MUTABLE_AV(((block).oldcomppad)))[po]) |
dd2155a4 DM |
414 | |
415 | ||
416 | /* | |
417 | =for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po | |
418 | Return the flags for the current compiling pad name | |
154e47c8 | 419 | at offset C<po>. Assumes a valid slot entry. |
dd2155a4 DM |
420 | |
421 | =for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po | |
422 | Return the name of the current compiling pad name | |
154e47c8 | 423 | at offset C<po>. Assumes a valid slot entry. |
dd2155a4 DM |
424 | |
425 | =for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po | |
426 | Return the type (stash) of the current compiling pad name at offset | |
154e47c8 | 427 | C<po>. Must be a valid name. Returns null if not typed. |
dd2155a4 DM |
428 | |
429 | =for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po | |
430 | Return the stash associated with an C<our> variable. | |
431 | Assumes the slot entry is a valid C<our> lexical. | |
432 | ||
433 | =for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po | |
434 | The generation number of the name at offset C<po> in the current | |
154e47c8 | 435 | compiling pad (lvalue). Note that C<SvUVX> is hijacked for this purpose. |
dd2155a4 | 436 | |
b162af07 SP |
437 | =for apidoc m|STRLEN|PAD_COMPNAME_GEN_set|PADOFFSET po|int gen |
438 | Sets the generation number of the name at offset C<po> in the current | |
931b58fb | 439 | ling pad (lvalue) to C<gen>. Note that C<SvUV_set> is hijacked for this purpose. |
b162af07 | 440 | |
dd2155a4 | 441 | =cut |
b162af07 | 442 | |
dd2155a4 DM |
443 | */ |
444 | ||
35e035cc | 445 | #define PAD_COMPNAME(po) PAD_COMPNAME_SV(po) |
9b7476d7 | 446 | #define PAD_COMPNAME_SV(po) (PadnamelistARRAY(PL_comppad_name)[(po)]) |
0f94cb1f | 447 | #define PAD_COMPNAME_FLAGS(po) PadnameFLAGS(PAD_COMPNAME(po)) |
1979170b | 448 | #define PAD_COMPNAME_FLAGS_isOUR(po) SvPAD_OUR(PAD_COMPNAME_SV(po)) |
e1c02f84 | 449 | #define PAD_COMPNAME_PV(po) PadnamePV(PAD_COMPNAME(po)) |
dd2155a4 | 450 | |
afb6e3f5 | 451 | #define PAD_COMPNAME_TYPE(po) PadnameTYPE(PAD_COMPNAME(po)) |
dd2155a4 DM |
452 | |
453 | #define PAD_COMPNAME_OURSTASH(po) \ | |
73d95100 | 454 | (SvOURSTASH(PAD_COMPNAME_SV(po))) |
dd2155a4 | 455 | |
9b7476d7 | 456 | #define PAD_COMPNAME_GEN(po) \ |
0f94cb1f | 457 | ((STRLEN)PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen) |
dd2155a4 | 458 | |
9b7476d7 | 459 | #define PAD_COMPNAME_GEN_set(po, gen) \ |
0f94cb1f | 460 | (PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen = (gen)) |
dd2155a4 DM |
461 | |
462 | ||
463 | /* | |
d77cdebf | 464 | =for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl|CLONE_PARAMS* param |
dd2155a4 DM |
465 | Clone the state variables associated with running and compiling pads. |
466 | ||
467 | =cut | |
468 | */ | |
469 | ||
c5ab0850 DM |
470 | /* NB - we set PL_comppad to null unless it points at a value that |
471 | * has already been dup'ed, ie it points to part of an active padlist. | |
472 | * Otherwise PL_comppad ends up being a leaked scalar in code like | |
473 | * the following: | |
474 | * threads->create(sub { threads->create(sub {...} ) } ); | |
475 | * where the second thread dups the outer sub's comppad but not the | |
476 | * sub's CV or padlist. */ | |
f3548bdc | 477 | |
dd2155a4 | 478 | #define PAD_CLONE_VARS(proto_perl, param) \ |
253649d9 | 479 | PL_comppad = av_dup(proto_perl->Icomppad, param); \ |
4608196e | 480 | PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \ |
9b7476d7 FC |
481 | PL_comppad_name = \ |
482 | padnamelist_dup(proto_perl->Icomppad_name, param); \ | |
dd2155a4 DM |
483 | PL_comppad_name_fill = proto_perl->Icomppad_name_fill; \ |
484 | PL_comppad_name_floor = proto_perl->Icomppad_name_floor; \ | |
dd2155a4 DM |
485 | PL_min_intro_pending = proto_perl->Imin_intro_pending; \ |
486 | PL_max_intro_pending = proto_perl->Imax_intro_pending; \ | |
487 | PL_padix = proto_perl->Ipadix; \ | |
488 | PL_padix_floor = proto_perl->Ipadix_floor; \ | |
489 | PL_pad_reset_pending = proto_perl->Ipad_reset_pending; \ | |
490 | PL_cop_seqmax = proto_perl->Icop_seqmax; | |
e9a8c099 MHM |
491 | |
492 | /* | |
cc76b5cc Z |
493 | =for apidoc Am|PADOFFSET|pad_add_name_pvs|const char *name|U32 flags|HV *typestash|HV *ourstash |
494 | ||
495 | Exactly like L</pad_add_name_pvn>, but takes a literal string instead | |
496 | of a string/length pair. | |
497 | ||
498 | =cut | |
499 | */ | |
500 | ||
501 | #define pad_add_name_pvs(name,flags,typestash,ourstash) \ | |
502 | Perl_pad_add_name_pvn(aTHX_ STR_WITH_LEN(name), flags, typestash, ourstash) | |
503 | ||
504 | /* | |
505 | =for apidoc Am|PADOFFSET|pad_findmy_pvs|const char *name|U32 flags | |
506 | ||
507 | Exactly like L</pad_findmy_pvn>, but takes a literal string instead | |
508 | of a string/length pair. | |
509 | ||
510 | =cut | |
511 | */ | |
512 | ||
513 | #define pad_findmy_pvs(name,flags) \ | |
514 | Perl_pad_findmy_pvn(aTHX_ STR_WITH_LEN(name), flags) | |
515 | ||
516 | /* | |
e9a8c099 MHM |
517 | * Local variables: |
518 | * c-indentation-style: bsd | |
519 | * c-basic-offset: 4 | |
14d04a33 | 520 | * indent-tabs-mode: nil |
e9a8c099 MHM |
521 | * End: |
522 | * | |
14d04a33 | 523 | * ex: set ts=8 sts=4 sw=4 et: |
e9a8c099 | 524 | */ |