Commit | Line | Data |
---|---|---|
a0d0e21e | 1 | /* cop.h |
79072805 | 2 | * |
1129b882 | 3 | * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
8622e0e2 | 4 | * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Larry Wall and others |
79072805 LW |
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 | * | |
8622e0e2 | 9 | * Control ops (cops) are one of the two ops OP_NEXTSTATE and OP_DBSTATE, |
775e5718 | 10 | * that (loosely speaking) are statement separators. |
3ffa1527 JH |
11 | * They hold information important for lexical state and error reporting. |
12 | * At run time, PL_curcop is set to point to the most recently executed cop, | |
a3985cdc | 13 | * and thus can be used to determine our current state. |
79072805 LW |
14 | */ |
15 | ||
0d2925a6 | 16 | /* A jmpenv packages the state required to perform a proper non-local jump. |
1c98cc53 DM |
17 | * Note that there is a PL_start_env initialized when perl starts, and |
18 | * PL_top_env points to this initially, so PL_top_env should always be | |
19 | * non-null. | |
0d2925a6 | 20 | * |
1c98cc53 DM |
21 | * Existence of a non-null PL_top_env->je_prev implies it is valid to call |
22 | * longjmp() at that runlevel (we make sure PL_start_env.je_prev is always | |
0d2925a6 DM |
23 | * null to ensure this). |
24 | * | |
25 | * je_mustcatch, when set at any runlevel to TRUE, means eval ops must | |
26 | * establish a local jmpenv to handle exception traps. Care must be taken | |
27 | * to restore the previous value of je_mustcatch before exiting the | |
28 | * stack frame iff JMPENV_PUSH was not called in that stack frame. | |
29 | * GSAR 97-03-27 | |
30 | */ | |
31 | ||
32 | struct jmpenv { | |
33 | struct jmpenv * je_prev; | |
caa674f3 | 34 | Sigjmp_buf je_buf; /* uninit if je_prev is NULL */ |
0d2925a6 | 35 | int je_ret; /* last exception thrown */ |
5bfa3d72 | 36 | bool je_mustcatch; /* longjmp()s must be caught locally */ |
a68090fe | 37 | U16 je_old_delaymagic; /* saved PL_delaymagic */ |
9449f0d6 | 38 | SSize_t je_old_stack_hwm; |
0d2925a6 DM |
39 | }; |
40 | ||
41 | typedef struct jmpenv JMPENV; | |
42 | ||
9449f0d6 DM |
43 | #if defined DEBUGGING && !defined DEBUGGING_RE_ONLY |
44 | # define JE_OLD_STACK_HWM_zero PL_start_env.je_old_stack_hwm = 0 | |
45 | # define JE_OLD_STACK_HWM_save(je) \ | |
46 | (je).je_old_stack_hwm = PL_curstackinfo->si_stack_hwm | |
47 | # define JE_OLD_STACK_HWM_restore(je) \ | |
978b1859 DM |
48 | if (PL_curstackinfo->si_stack_hwm < (je).je_old_stack_hwm) \ |
49 | PL_curstackinfo->si_stack_hwm = (je).je_old_stack_hwm | |
9449f0d6 DM |
50 | #else |
51 | # define JE_OLD_STACK_HWM_zero NOOP | |
52 | # define JE_OLD_STACK_HWM_save(je) NOOP | |
53 | # define JE_OLD_STACK_HWM_restore(je) NOOP | |
54 | #endif | |
55 | ||
0d2925a6 DM |
56 | /* |
57 | * How to build the first jmpenv. | |
58 | * | |
59 | * top_env needs to be non-zero. It points to an area | |
60 | * in which longjmp() stuff is stored, as C callstack | |
61 | * info there at least is thread specific this has to | |
62 | * be per-thread. Otherwise a 'die' in a thread gives | |
63 | * that thread the C stack of last thread to do an eval {}! | |
64 | */ | |
65 | ||
66 | #define JMPENV_BOOTSTRAP \ | |
67 | STMT_START { \ | |
1f4fbd3b MS |
68 | PERL_POISON_EXPR(PoisonNew(&PL_start_env, 1, JMPENV));\ |
69 | PL_top_env = &PL_start_env; \ | |
70 | PL_start_env.je_prev = NULL; \ | |
71 | PL_start_env.je_ret = -1; \ | |
72 | PL_start_env.je_mustcatch = TRUE; \ | |
73 | PL_start_env.je_old_delaymagic = 0; \ | |
9449f0d6 | 74 | JE_OLD_STACK_HWM_zero; \ |
0d2925a6 DM |
75 | } STMT_END |
76 | ||
77 | /* | |
78 | * PERL_FLEXIBLE_EXCEPTIONS | |
0bbec57d | 79 | * |
0d2925a6 DM |
80 | * All the flexible exceptions code has been removed. |
81 | * See the following threads for details: | |
82 | * | |
0bbec57d MM |
83 | * Message-Id: 20040713143217.GB1424@plum.flirble.org |
84 | * https://www.nntp.perl.org/group/perl.perl5.porters/2004/07/msg93041.html | |
85 | * | |
0d2925a6 | 86 | * Joshua's original patches (which weren't applied) and discussion: |
0bbec57d | 87 | * |
0d2925a6 DM |
88 | * http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1998-02/msg01396.html |
89 | * http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1998-02/msg01489.html | |
90 | * http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1998-02/msg01491.html | |
91 | * http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1998-02/msg01608.html | |
92 | * http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1998-02/msg02144.html | |
93 | * http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1998-02/msg02998.html | |
0bbec57d | 94 | * |
0d2925a6 | 95 | * Chip's reworked patch and discussion: |
0bbec57d | 96 | * |
0d2925a6 | 97 | * http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-03/msg00520.html |
0bbec57d | 98 | * |
0d2925a6 DM |
99 | * The flaw in these patches (which went unnoticed at the time) was |
100 | * that they moved some code that could potentially die() out of the | |
101 | * region protected by the setjmp()s. This caused exceptions within | |
102 | * END blocks and such to not be handled by the correct setjmp(). | |
c77726bb | 103 | * |
0d2925a6 DM |
104 | * The original patches that introduces flexible exceptions were: |
105 | * | |
47ef154c DB |
106 | * https://github.com/Perl/perl5/commit/312caa8e97f1c7ee342a9895c2f0e749625b4929 |
107 | * https://github.com/Perl/perl5/commit/14dd3ad8c9bf82cf09798a22cc89a9862dfd6d1a | |
c77726bb | 108 | * |
0d2925a6 DM |
109 | */ |
110 | ||
111 | #define dJMPENV JMPENV cur_env | |
112 | ||
112f4f94 | 113 | #define JMPENV_PUSH(v) \ |
0d2925a6 | 114 | STMT_START { \ |
112f4f94 | 115 | DEBUG_l({ \ |
aeff225d | 116 | int i = 0; \ |
112f4f94 | 117 | JMPENV *p = PL_top_env; \ |
1f4fbd3b | 118 | while (p) { i++; p = p->je_prev; } \ |
f31da5f4 YO |
119 | Perl_deb(aTHX_ "JMPENV_PUSH pre level=%d in %s at %s:%d\n", \ |
120 | i, SAFE_FUNCTION__, __FILE__, __LINE__); \ | |
112f4f94 | 121 | }); \ |
1f4fbd3b | 122 | cur_env.je_prev = PL_top_env; \ |
9449f0d6 | 123 | JE_OLD_STACK_HWM_save(cur_env); \ |
112f4f94 | 124 | cur_env.je_ret = PerlProc_setjmp(cur_env.je_buf, SCOPE_SAVES_SIGNAL_MASK); \ |
9449f0d6 | 125 | JE_OLD_STACK_HWM_restore(cur_env); \ |
1f4fbd3b MS |
126 | PL_top_env = &cur_env; \ |
127 | cur_env.je_mustcatch = FALSE; \ | |
128 | cur_env.je_old_delaymagic = PL_delaymagic; \ | |
112f4f94 | 129 | DEBUG_l({ \ |
aeff225d YO |
130 | int i = 0; \ |
131 | JMPENV *p = PL_top_env; \ | |
132 | while (p) { i++; p = p->je_prev; } \ | |
f31da5f4 YO |
133 | Perl_deb(aTHX_ "JMPENV_PUSH level=%d ret=%d in %s at %s:%d\n", \ |
134 | i, cur_env.je_ret, SAFE_FUNCTION__, __FILE__, __LINE__); \ | |
112f4f94 | 135 | }); \ |
aeff225d | 136 | (v) = cur_env.je_ret; \ |
0d2925a6 DM |
137 | } STMT_END |
138 | ||
139 | #define JMPENV_POP \ | |
140 | STMT_START { \ | |
112f4f94 | 141 | DEBUG_l({ \ |
1f4fbd3b MS |
142 | int i = -1; JMPENV *p = PL_top_env; \ |
143 | while (p) { i++; p = p->je_prev; } \ | |
f31da5f4 YO |
144 | Perl_deb(aTHX_ "JMPENV_POP level=%d in %s at %s:%d\n", \ |
145 | i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \ | |
1f4fbd3b MS |
146 | assert(PL_top_env == &cur_env); \ |
147 | PL_delaymagic = cur_env.je_old_delaymagic; \ | |
148 | PL_top_env = cur_env.je_prev; \ | |
0d2925a6 DM |
149 | } STMT_END |
150 | ||
151 | #define JMPENV_JUMP(v) \ | |
152 | STMT_START { \ | |
112f4f94 | 153 | DEBUG_l({ \ |
1f4fbd3b MS |
154 | int i = -1; JMPENV *p = PL_top_env; \ |
155 | while (p) { i++; p = p->je_prev; } \ | |
f31da5f4 YO |
156 | Perl_deb(aTHX_ "JMPENV_JUMP(%d) level=%d in %s at %s:%d\n", \ |
157 | (int)(v), i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \ | |
1f4fbd3b MS |
158 | if (PL_top_env->je_prev) \ |
159 | PerlProc_longjmp(PL_top_env->je_buf, (v)); \ | |
160 | if ((v) == 2) \ | |
161 | PerlProc_exit(STATUS_EXIT); \ | |
112f4f94 | 162 | PerlIO_printf(PerlIO_stderr(), "panic: top_env, v=%d\n", (int)(v)); \ |
1f4fbd3b | 163 | PerlProc_exit(1); \ |
0d2925a6 DM |
164 | } STMT_END |
165 | ||
166 | #define CATCH_GET (PL_top_env->je_mustcatch) | |
1c98cc53 DM |
167 | #define CATCH_SET(v) \ |
168 | STMT_START { \ | |
112f4f94 | 169 | DEBUG_l( \ |
1f4fbd3b | 170 | Perl_deb(aTHX_ \ |
f31da5f4 | 171 | "JUMPLEVEL set catch %d => %d (for %p) in %s at %s:%d\n", \ |
112f4f94 | 172 | PL_top_env->je_mustcatch, (v), (void*)PL_top_env, \ |
f31da5f4 | 173 | SAFE_FUNCTION__, __FILE__, __LINE__);) \ |
1f4fbd3b | 174 | PL_top_env->je_mustcatch = (v); \ |
1c98cc53 | 175 | } STMT_END |
0d2925a6 | 176 | |
20439bc7 | 177 | /* |
3f620621 | 178 | =for apidoc_section $COP |
20439bc7 Z |
179 | */ |
180 | ||
181 | typedef struct refcounted_he COPHH; | |
182 | ||
183 | #define COPHH_KEY_UTF8 REFCOUNTED_HE_KEY_UTF8 | |
d36f8b33 | 184 | #define COPHH_EXISTS REFCOUNTED_HE_EXISTS |
20439bc7 Z |
185 | |
186 | /* | |
1607e393 KW |
187 | =for apidoc Amx|SV *|cophh_fetch_pv |const COPHH *cophh|const char *key |U32 hash|U32 flags |
188 | =for apidoc_item|SV *|cophh_fetch_pvn|const COPHH *cophh|const char *key|STRLEN keylen|U32 hash|U32 flags | |
699ef60a KW |
189 | =for apidoc_item|SV *|cophh_fetch_pvs|const COPHH *cophh| "key" |U32 flags |
190 | =for apidoc_item|SV *|cophh_fetch_sv |const COPHH *cophh| SV *key |U32 hash|U32 flags | |
191 | ||
192 | These look up the entry in the cop hints hash C<cophh> with the key specified by | |
193 | C<key> (and C<keylen> in the C<pvn> form), returning that value as a mortal | |
194 | scalar copy, or C<&PL_sv_placeholder> if there is no value associated with the | |
195 | key. | |
196 | ||
197 | The forms differ in how the key is specified. | |
198 | In the plain C<pv> form, the key is a C language NUL-terminated string. | |
199 | In the C<pvs> form, the key is a C language string literal. | |
200 | In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of | |
201 | the string, which hence, may contain embedded-NUL characters. | |
202 | In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that. | |
203 | using C<L</SvPV_const>>. | |
204 | ||
205 | C<hash> is a precomputed hash of the key string, or zero if it has not been | |
206 | precomputed. This parameter is omitted from the C<pvs> form, as it is computed | |
207 | automatically at compile time. | |
208 | ||
209 | The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>. | |
210 | It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies | |
211 | whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if | |
212 | cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of | |
213 | the octets. | |
20439bc7 | 214 | |
5af38e47 KW |
215 | =for apidoc Amnh||COPHH_KEY_UTF8 |
216 | ||
20439bc7 | 217 | =cut |
9d0ade3b | 218 | |
20439bc7 Z |
219 | */ |
220 | ||
9d0ade3b KW |
221 | #define cophh_fetch_pvn(cophh, key, keylen, hash, flags) \ |
222 | Perl_refcounted_he_fetch_pvn(aTHX_ cophh, key, keylen, hash, \ | |
223 | (flags & COPHH_KEY_UTF8)) | |
20439bc7 | 224 | |
9d0ade3b KW |
225 | #define cophh_fetch_pvs(cophh, key, flags) \ |
226 | Perl_refcounted_he_fetch_pvn(aTHX_ cophh, STR_WITH_LEN(key), 0, \ | |
227 | (flags & COPHH_KEY_UTF8)) | |
20439bc7 | 228 | |
9d0ade3b KW |
229 | #define cophh_fetch_pv(cophh, key, hash, flags) \ |
230 | Perl_refcounted_he_fetch_pv(aTHX_ cophh, key, hash, \ | |
231 | (flags & COPHH_KEY_UTF8)) | |
20439bc7 | 232 | |
9d0ade3b KW |
233 | #define cophh_fetch_sv(cophh, key, hash, flags) \ |
234 | Perl_refcounted_he_fetch_sv(aTHX_ cophh, key, hash, \ | |
235 | (flags & COPHH_KEY_UTF8)) | |
20439bc7 Z |
236 | |
237 | /* | |
c4f35413 | 238 | =for apidoc Amx|bool|cophh_exists_pvn|const COPHH *cophh|const char *key|STRLEN keylen|U32 hash|U32 flags |
d36f8b33 | 239 | |
c4f35413 KW |
240 | These look up the hint entry in the cop C<cop> with the key specified by |
241 | C<key> (and C<keylen> in the C<pvn> form), returning true if a value exists, | |
242 | and false otherwise. | |
d36f8b33 | 243 | |
c4f35413 KW |
244 | The forms differ in how the key is specified. |
245 | In the plain C<pv> form, the key is a C language NUL-terminated string. | |
246 | In the C<pvs> form, the key is a C language string literal. | |
247 | In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of | |
248 | the string, which hence, may contain embedded-NUL characters. | |
249 | In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that. | |
250 | using C<L</SvPV_const>>. | |
d36f8b33 | 251 | |
c4f35413 KW |
252 | C<hash> is a precomputed hash of the key string, or zero if it has not been |
253 | precomputed. This parameter is omitted from the C<pvs> form, as it is computed | |
254 | automatically at compile time. | |
d36f8b33 | 255 | |
c4f35413 KW |
256 | The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>. |
257 | It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies | |
258 | whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if | |
259 | cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of | |
260 | the octets. | |
d36f8b33 LT |
261 | |
262 | =cut | |
263 | */ | |
264 | ||
c4f35413 KW |
265 | #define cophh_exists_pvn(cophh, key, keylen, hash, flags) \ |
266 | cBOOL(Perl_refcounted_he_fetch_pvn(aTHX_ cophh, key, keylen, hash, flags | COPHH_EXISTS)) | |
267 | ||
d36f8b33 LT |
268 | #define cophh_exists_pvs(cophh, key, flags) \ |
269 | cBOOL(Perl_refcounted_he_fetch_pvn(aTHX_ cophh, STR_WITH_LEN(key), 0, flags | COPHH_EXISTS)) | |
270 | ||
d36f8b33 LT |
271 | #define cophh_exists_pv(cophh, key, hash, flags) \ |
272 | cBOOL(Perl_refcounted_he_fetch_pv(aTHX_ cophh, key, hash, flags | COPHH_EXISTS)) | |
273 | ||
d36f8b33 LT |
274 | #define cophh_exists_sv(cophh, key, hash, flags) \ |
275 | cBOOL(Perl_refcounted_he_fetch_sv(aTHX_ cophh, key, hash, flags | COPHH_EXISTS)) | |
276 | ||
277 | /* | |
ffd08bbf | 278 | =for apidoc Amx|HV *|cophh_2hv|const COPHH *cophh|U32 flags |
20439bc7 Z |
279 | |
280 | Generates and returns a standard Perl hash representing the full set of | |
2d7f6611 | 281 | key/value pairs in the cop hints hash C<cophh>. C<flags> is currently |
20439bc7 Z |
282 | unused and must be zero. |
283 | ||
284 | =cut | |
285 | */ | |
286 | ||
287 | #define cophh_2hv(cophh, flags) \ | |
288 | Perl_refcounted_he_chain_2hv(aTHX_ cophh, flags) | |
289 | ||
290 | /* | |
ffd08bbf | 291 | =for apidoc Amx|COPHH *|cophh_copy|COPHH *cophh |
20439bc7 | 292 | |
2d7f6611 | 293 | Make and return a complete copy of the cop hints hash C<cophh>. |
20439bc7 Z |
294 | |
295 | =cut | |
296 | */ | |
297 | ||
298 | #define cophh_copy(cophh) Perl_refcounted_he_inc(aTHX_ cophh) | |
299 | ||
300 | /* | |
ffd08bbf | 301 | =for apidoc Amx|void|cophh_free|COPHH *cophh |
20439bc7 | 302 | |
2d7f6611 | 303 | Discard the cop hints hash C<cophh>, freeing all resources associated |
20439bc7 Z |
304 | with it. |
305 | ||
306 | =cut | |
307 | */ | |
308 | ||
309 | #define cophh_free(cophh) Perl_refcounted_he_free(aTHX_ cophh) | |
310 | ||
311 | /* | |
ffd08bbf | 312 | =for apidoc Amx|COPHH *|cophh_new_empty |
20439bc7 Z |
313 | |
314 | Generate and return a fresh cop hints hash containing no entries. | |
315 | ||
316 | =cut | |
317 | */ | |
318 | ||
319 | #define cophh_new_empty() ((COPHH *)NULL) | |
320 | ||
321 | /* | |
1607e393 KW |
322 | =for apidoc Amx|COPHH *|cophh_store_pv |COPHH *cophh|const char *key |U32 hash|SV *value|U32 flags |
323 | =for apidoc_item|COPHH *|cophh_store_pvn|COPHH *cophh|const char *key|STRLEN keylen|U32 hash|SV *value|U32 flags | |
51505c5b KW |
324 | =for apidoc_item|COPHH *|cophh_store_pvs|COPHH *cophh| "key" |SV *value|U32 flags |
325 | =for apidoc_item|COPHH *|cophh_store_sv |COPHH *cophh| SV *key |U32 hash|SV *value|U32 flags | |
20439bc7 | 326 | |
51505c5b KW |
327 | These store a value, associated with a key, in the cop hints hash C<cophh>, |
328 | and return the modified hash. The returned hash pointer is in general | |
20439bc7 Z |
329 | not the same as the hash pointer that was passed in. The input hash is |
330 | consumed by the function, and the pointer to it must not be subsequently | |
331 | used. Use L</cophh_copy> if you need both hashes. | |
332 | ||
2d7f6611 | 333 | C<value> is the scalar value to store for this key. C<value> is copied |
51505c5b KW |
334 | by these functions, which thus do not take ownership of any reference |
335 | to it, and hence later changes to the scalar will not be reflected in the value | |
336 | visible in the cop hints hash. Complex types of scalar will not be stored with | |
337 | referential integrity, but will be coerced to strings. | |
338 | ||
339 | The forms differ in how the key is specified. In all forms, the key is pointed | |
340 | to by C<key>. | |
341 | In the plain C<pv> form, the key is a C language NUL-terminated string. | |
342 | In the C<pvs> form, the key is a C language string literal. | |
343 | In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of | |
344 | the string, which hence, may contain embedded-NUL characters. | |
345 | In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that. | |
346 | using C<L</SvPV_const>>. | |
347 | ||
348 | C<hash> is a precomputed hash of the key string, or zero if it has not been | |
349 | precomputed. This parameter is omitted from the C<pvs> form, as it is computed | |
350 | automatically at compile time. | |
351 | ||
352 | The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>. | |
353 | It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies | |
354 | whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if | |
355 | cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of | |
356 | the octets. | |
20439bc7 Z |
357 | |
358 | =cut | |
359 | */ | |
360 | ||
51505c5b KW |
361 | #define cophh_store_pvn(cophh, key, keylen, hash, value, flags) \ |
362 | Perl_refcounted_he_new_pvn(aTHX_ cophh, key, keylen, hash, value, flags) | |
20439bc7 Z |
363 | |
364 | #define cophh_store_pvs(cophh, key, value, flags) \ | |
365 | Perl_refcounted_he_new_pvn(aTHX_ cophh, STR_WITH_LEN(key), 0, value, flags) | |
366 | ||
20439bc7 Z |
367 | #define cophh_store_pv(cophh, key, hash, value, flags) \ |
368 | Perl_refcounted_he_new_pv(aTHX_ cophh, key, hash, value, flags) | |
369 | ||
20439bc7 Z |
370 | #define cophh_store_sv(cophh, key, hash, value, flags) \ |
371 | Perl_refcounted_he_new_sv(aTHX_ cophh, key, hash, value, flags) | |
372 | ||
373 | /* | |
1607e393 KW |
374 | =for apidoc Amx|COPHH *|cophh_delete_pv |COPHH *cophh|const char *key |U32 hash|U32 flags |
375 | =for apidoc_item|COPHH *|cophh_delete_pvn|COPHH *cophh|const char *key|STRLEN keylen|U32 hash|U32 flags | |
226b86f1 KW |
376 | =for apidoc_item|COPHH *|cophh_delete_pvs|COPHH *cophh| "key" |U32 flags |
377 | =for apidoc_item|COPHH *|cophh_delete_sv |COPHH *cophh| SV *key |U32 hash|U32 flags | |
20439bc7 | 378 | |
226b86f1 KW |
379 | These delete a key and its associated value from the cop hints hash C<cophh>, |
380 | and return the modified hash. The returned hash pointer is in general | |
20439bc7 Z |
381 | not the same as the hash pointer that was passed in. The input hash is |
382 | consumed by the function, and the pointer to it must not be subsequently | |
383 | used. Use L</cophh_copy> if you need both hashes. | |
384 | ||
226b86f1 KW |
385 | The forms differ in how the key is specified. In all forms, the key is pointed |
386 | to by C<key>. | |
387 | In the plain C<pv> form, the key is a C language NUL-terminated string. | |
388 | In the C<pvs> form, the key is a C language string literal. | |
389 | In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of | |
390 | the string, which hence, may contain embedded-NUL characters. | |
391 | In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that. | |
392 | using C<L</SvPV_const>>. | |
20439bc7 | 393 | |
226b86f1 KW |
394 | C<hash> is a precomputed hash of the key string, or zero if it has not been |
395 | precomputed. This parameter is omitted from the C<pvs> form, as it is computed | |
396 | automatically at compile time. | |
20439bc7 | 397 | |
226b86f1 KW |
398 | The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>. |
399 | It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies | |
400 | whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if | |
401 | cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of | |
402 | the octets. | |
20439bc7 Z |
403 | |
404 | =cut | |
405 | */ | |
406 | ||
226b86f1 KW |
407 | #define cophh_delete_pvn(cophh, key, keylen, hash, flags) \ |
408 | Perl_refcounted_he_new_pvn(aTHX_ cophh, key, keylen, hash, \ | |
409 | (SV *)NULL, flags) | |
410 | ||
20439bc7 Z |
411 | #define cophh_delete_pvs(cophh, key, flags) \ |
412 | Perl_refcounted_he_new_pvn(aTHX_ cophh, STR_WITH_LEN(key), 0, \ | |
1f4fbd3b | 413 | (SV *)NULL, flags) |
20439bc7 | 414 | |
20439bc7 Z |
415 | #define cophh_delete_pv(cophh, key, hash, flags) \ |
416 | Perl_refcounted_he_new_pv(aTHX_ cophh, key, hash, (SV *)NULL, flags) | |
417 | ||
20439bc7 Z |
418 | #define cophh_delete_sv(cophh, key, hash, flags) \ |
419 | Perl_refcounted_he_new_sv(aTHX_ cophh, key, hash, (SV *)NULL, flags) | |
0d2925a6 | 420 | |
5ac1e9b2 | 421 | #include "mydtrace.h" |
0d2925a6 | 422 | |
88df5f01 FC |
423 | struct cop { |
424 | BASEOP | |
425 | /* On LP64 putting this here takes advantage of the fact that BASEOP isn't | |
426 | an exact multiple of 8 bytes to save structure padding. */ | |
427 | line_t cop_line; /* line # of this command */ | |
428 | /* label for this construct is now stored in cop_hints_hash */ | |
57843af0 | 429 | #ifdef USE_ITHREADS |
88df5f01 | 430 | PADOFFSET cop_stashoff; /* offset into PL_stashpad, for the |
1f4fbd3b | 431 | package the line was compiled in */ |
6600fe70 | 432 | char * cop_file; /* name of file this command is from */ |
57843af0 | 433 | #else |
88df5f01 | 434 | HV * cop_stash; /* package line was compiled in */ |
6600fe70 | 435 | GV * cop_filegv; /* name of GV file this command is from */ |
57843af0 | 436 | #endif |
88df5f01 FC |
437 | U32 cop_hints; /* hints bits from pragmata */ |
438 | U32 cop_seq; /* parse sequence number */ | |
439 | /* Beware. mg.c and warnings.pl assume the type of this is STRLEN *: */ | |
440 | STRLEN * cop_warnings; /* lexical warnings bitmask */ | |
441 | /* compile time state of %^H. See the comment in op.c for how this is | |
442 | used to recreate a hash to return from caller. */ | |
20439bc7 | 443 | COPHH * cop_hints_hash; |
9f601cf3 TC |
444 | /* for now just a bitmask stored here. |
445 | If we get sufficient features this may become a pointer. | |
446 | How these flags are stored is subject to change without | |
447 | notice. Use the macros to test for features. | |
448 | */ | |
449 | U32 cop_features; | |
79072805 LW |
450 | }; |
451 | ||
add0fa58 KW |
452 | /* |
453 | =for apidoc Am|const char *|CopFILE|const COP * c | |
454 | Returns the name of the file associated with the C<COP> C<c> | |
455 | ||
456 | =for apidoc Am|STRLEN|CopLINE|const COP * c | |
457 | Returns the line number in the source code associated with the C<COP> C<c> | |
458 | ||
459 | =for apidoc Am|AV *|CopFILEAV|const COP * c | |
9c913148 TC |
460 | Returns the AV associated with the C<COP> C<c>, creating it if necessary. |
461 | ||
462 | =for apidoc Am|AV *|CopFILEAVn|const COP * c | |
463 | Returns the AV associated with the C<COP> C<c>, returning NULL if it | |
464 | doesn't already exist. | |
add0fa58 KW |
465 | |
466 | =for apidoc Am|SV *|CopFILESV|const COP * c | |
467 | Returns the SV associated with the C<COP> C<c> | |
468 | ||
469 | =for apidoc Am|void|CopFILE_set|COP * c|const char * pv | |
470 | Makes C<pv> the name of the file associated with the C<COP> C<c> | |
471 | ||
472 | =for apidoc Am|GV *|CopFILEGV|const COP * c | |
473 | Returns the GV associated with the C<COP> C<c> | |
474 | ||
475 | =for apidoc CopFILEGV_set | |
476 | Available only on unthreaded perls. Makes C<pv> the name of the file | |
477 | associated with the C<COP> C<c> | |
478 | ||
7f02c139 KW |
479 | =for apidoc Am|HV *|CopSTASH|const COP * c |
480 | Returns the stash associated with C<c>. | |
481 | ||
482 | =for apidoc Am|bool|CopSTASH_eq|const COP * c|const HV * hv | |
483 | Returns a boolean as to whether or not C<hv> is the stash associated with C<c>. | |
484 | ||
485 | =for apidoc Am|bool|CopSTASH_set|COP * c|HV * hv | |
486 | Set the stash associated with C<c> to C<hv>. | |
487 | ||
488 | =for apidoc Am|char *|CopSTASHPV|const COP * c | |
489 | Returns the package name of the stash associated with C<c>, or C<NULL> if no | |
490 | associated stash | |
491 | ||
492 | =for apidoc Am|void|CopSTASHPV_set|COP * c|const char * pv | |
493 | Set the package name of the stash associated with C<c>, to the NUL-terminated C | |
494 | string C<p>, creating the package if necessary. | |
495 | ||
add0fa58 KW |
496 | =cut |
497 | */ | |
498 | ||
57843af0 | 499 | #ifdef USE_ITHREADS |
a8899380 | 500 | |
1dc74fdb FC |
501 | # define CopFILE(c) ((c)->cop_file) |
502 | # define CopFILEGV(c) (CopFILE(c) \ | |
1f4fbd3b | 503 | ? gv_fetchfile(CopFILE(c)) : NULL) |
0bbec57d | 504 | |
2eb109a4 DIM |
505 | # define CopFILE_set(c,pv) ((c)->cop_file = savesharedpv(pv)) |
506 | # define CopFILE_setn(c,pv,l) ((c)->cop_file = savesharedpvn((pv),(l))) | |
1dc74fdb FC |
507 | |
508 | # define CopFILESV(c) (CopFILE(c) \ | |
1f4fbd3b | 509 | ? GvSV(gv_fetchfile(CopFILE(c))) : NULL) |
1dc74fdb | 510 | # define CopFILEAV(c) (CopFILE(c) \ |
1f4fbd3b | 511 | ? GvAV(gv_fetchfile(CopFILE(c))) : NULL) |
1dc74fdb | 512 | # define CopFILEAVx(c) (assert_(CopFILE(c)) \ |
1f4fbd3b | 513 | GvAV(gv_fetchfile(CopFILE(c)))) |
9c913148 | 514 | # define CopFILEAVn(c) (cop_file_avn(c)) |
d4d03940 FC |
515 | # define CopSTASH(c) PL_stashpad[(c)->cop_stashoff] |
516 | # define CopSTASH_set(c,hv) ((c)->cop_stashoff = (hv) \ | |
1f4fbd3b MS |
517 | ? alloccopstash(hv) \ |
518 | : 0) | |
2eb109a4 | 519 | # define CopFILE_free(c) (PerlMemShared_free(CopFILE(c)),(CopFILE(c) = NULL)) |
a8899380 TC |
520 | |
521 | #else /* Above: yes threads; Below no threads */ | |
522 | ||
57843af0 | 523 | # define CopFILEGV(c) ((c)->cop_filegv) |
f4dd75d9 | 524 | # define CopFILEGV_set(c,gv) ((c)->cop_filegv = (GV*)SvREFCNT_inc(gv)) |
1dc74fdb FC |
525 | # define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv)) |
526 | # define CopFILE_setn(c,pv,l) CopFILEGV_set((c), gv_fetchfile_flags((pv),(l),0)) | |
527 | # define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : NULL) | |
528 | # define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : NULL) | |
529 | # ifdef DEBUGGING | |
530 | # define CopFILEAVx(c) (assert(CopFILEGV(c)), GvAV(CopFILEGV(c))) | |
531 | # else | |
532 | # define CopFILEAVx(c) (GvAV(CopFILEGV(c))) | |
533 | # endif | |
9c913148 | 534 | # define CopFILEAVn(c) (CopFILEGV(c) ? GvAVn(CopFILEGV(c)) : NULL) |
6600fe70 | 535 | # define CopFILE(c) (CopFILEGV(c) /* +2 for '_<' */ \ |
1f4fbd3b | 536 | ? GvNAME(CopFILEGV(c))+2 : NULL) |
57843af0 | 537 | # define CopSTASH(c) ((c)->cop_stash) |
f4dd75d9 | 538 | # define CopSTASH_set(c,hv) ((c)->cop_stash = (hv)) |
a0714e2c | 539 | # define CopFILE_free(c) (SvREFCNT_dec(CopFILEGV(c)),(CopFILEGV(c) = NULL)) |
05ec9bb3 | 540 | |
57843af0 | 541 | #endif /* USE_ITHREADS */ |
20439bc7 | 542 | |
d4d03940 FC |
543 | #define CopSTASHPV(c) (CopSTASH(c) ? HvNAME_get(CopSTASH(c)) : NULL) |
544 | /* cop_stash is not refcounted */ | |
545 | #define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD)) | |
546 | #define CopSTASH_eq(c,hv) (CopSTASH(c) == (hv)) | |
d4d03940 | 547 | |
20439bc7 Z |
548 | #define CopHINTHASH_get(c) ((COPHH*)((c)->cop_hints_hash)) |
549 | #define CopHINTHASH_set(c,h) ((c)->cop_hints_hash = (h)) | |
550 | ||
551 | /* | |
1607e393 KW |
552 | =for apidoc Am|SV *|cop_hints_fetch_pv |const COP *cop|const char *key |U32 hash|U32 flags |
553 | =for apidoc_item|SV *|cop_hints_fetch_pvn|const COP *cop|const char *key|STRLEN keylen|U32 hash|U32 flags | |
554 | =for apidoc_item|SV *|cop_hints_fetch_pvs|const COP *cop| "key" |U32 flags | |
c7c0c00c | 555 | =for apidoc_item|SV *|cop_hints_fetch_sv |const COP *cop| SV *key |U32 hash|U32 flags |
20439bc7 | 556 | |
c7c0c00c KW |
557 | These look up the hint entry in the cop C<cop> with the key specified by |
558 | C<key> (and C<keylen> in the C<pvn> form), returning that value as a mortal | |
559 | scalar copy, or C<&PL_sv_placeholder> if there is no value associated with the | |
560 | key. | |
20439bc7 | 561 | |
c7c0c00c KW |
562 | The forms differ in how the key is specified. |
563 | In the plain C<pv> form, the key is a C language NUL-terminated string. | |
564 | In the C<pvs> form, the key is a C language string literal. | |
565 | In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of | |
566 | the string, which hence, may contain embedded-NUL characters. | |
567 | In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that. | |
568 | using C<L</SvPV_const>>. | |
20439bc7 | 569 | |
c7c0c00c KW |
570 | C<hash> is a precomputed hash of the key string, or zero if it has not been |
571 | precomputed. This parameter is omitted from the C<pvs> form, as it is computed | |
572 | automatically at compile time. | |
20439bc7 | 573 | |
c7c0c00c KW |
574 | The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>. |
575 | It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies | |
576 | whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if | |
577 | cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of | |
578 | the octets. | |
20439bc7 Z |
579 | |
580 | =cut | |
581 | */ | |
582 | ||
c7c0c00c KW |
583 | #define cop_hints_fetch_pvn(cop, key, keylen, hash, flags) \ |
584 | cophh_fetch_pvn(CopHINTHASH_get(cop), key, keylen, hash, flags) | |
585 | ||
20439bc7 Z |
586 | #define cop_hints_fetch_pvs(cop, key, flags) \ |
587 | cophh_fetch_pvs(CopHINTHASH_get(cop), key, flags) | |
588 | ||
20439bc7 Z |
589 | #define cop_hints_fetch_pv(cop, key, hash, flags) \ |
590 | cophh_fetch_pv(CopHINTHASH_get(cop), key, hash, flags) | |
591 | ||
20439bc7 Z |
592 | #define cop_hints_fetch_sv(cop, key, hash, flags) \ |
593 | cophh_fetch_sv(CopHINTHASH_get(cop), key, hash, flags) | |
594 | ||
595 | /* | |
1607e393 KW |
596 | =for apidoc Am|bool|cop_hints_exists_pv |const COP *cop|const char *key|U32 hash |U32 flags |
597 | =for apidoc_item|bool|cop_hints_exists_pvn|const COP *cop|const char *key|STRLEN keylen|U32 hash|U32 flags | |
d809c335 KW |
598 | =for apidoc_item|bool|cop_hints_exists_pvs|const COP *cop| "key" |U32 flags |
599 | =for apidoc_item|bool|cop_hints_exists_sv |const COP *cop| SV *key |U32 hash|U32 flags | |
bbb58664 | 600 | |
d809c335 KW |
601 | These look up the hint entry in the cop C<cop> with the key specified by |
602 | C<key> (and C<keylen> in the C<pvn> form), returning true if a value exists, | |
603 | and false otherwise. | |
bbb58664 | 604 | |
d809c335 KW |
605 | The forms differ in how the key is specified. In all forms, the key is pointed |
606 | to by C<key>. | |
607 | In the plain C<pv> form, the key is a C language NUL-terminated string. | |
608 | In the C<pvs> form, the key is a C language string literal. | |
609 | In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of | |
610 | the string, which hence, may contain embedded-NUL characters. | |
611 | In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that. | |
612 | using C<L</SvPV_const>>. | |
bbb58664 | 613 | |
d809c335 KW |
614 | C<hash> is a precomputed hash of the key string, or zero if it has not been |
615 | precomputed. This parameter is omitted from the C<pvs> form, as it is computed | |
616 | automatically at compile time. | |
bbb58664 | 617 | |
d809c335 KW |
618 | The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>. |
619 | It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies | |
620 | whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if | |
621 | cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of | |
622 | the octets. | |
bbb58664 LT |
623 | |
624 | =cut | |
625 | */ | |
626 | ||
d809c335 KW |
627 | #define cop_hints_exists_pvn(cop, key, keylen, hash, flags) \ |
628 | cophh_exists_pvn(CopHINTHASH_get(cop), key, keylen, hash, flags) | |
629 | ||
bbb58664 LT |
630 | #define cop_hints_exists_pvs(cop, key, flags) \ |
631 | cophh_exists_pvs(CopHINTHASH_get(cop), key, flags) | |
632 | ||
bbb58664 LT |
633 | #define cop_hints_exists_pv(cop, key, hash, flags) \ |
634 | cophh_exists_pv(CopHINTHASH_get(cop), key, hash, flags) | |
635 | ||
bbb58664 LT |
636 | #define cop_hints_exists_sv(cop, key, hash, flags) \ |
637 | cophh_exists_sv(CopHINTHASH_get(cop), key, hash, flags) | |
638 | ||
639 | /* | |
20439bc7 Z |
640 | =for apidoc Am|HV *|cop_hints_2hv|const COP *cop|U32 flags |
641 | ||
642 | Generates and returns a standard Perl hash representing the full set of | |
2d7f6611 | 643 | hint entries in the cop C<cop>. C<flags> is currently unused and must |
20439bc7 Z |
644 | be zero. |
645 | ||
646 | =cut | |
647 | */ | |
648 | ||
649 | #define cop_hints_2hv(cop, flags) \ | |
650 | cophh_2hv(CopHINTHASH_get(cop), flags) | |
651 | ||
33d29c13 | 652 | /* |
71b454dc KW |
653 | =for apidoc Am|const char *|CopLABEL |COP *const cop |
654 | =for apidoc_item|const char *|CopLABEL_len |COP *const cop|STRLEN *len | |
655 | =for apidoc_item|const char *|CopLABEL_len_flags|COP *const cop|STRLEN *len|U32 *flags | |
33d29c13 | 656 | |
71b454dc | 657 | These return the label attached to a cop. |
33d29c13 | 658 | |
71b454dc KW |
659 | C<CopLABEL_len> and C<CopLABEL_len_flags> additionally store the number of |
660 | bytes comprising the returned label into C<*len>. | |
33d29c13 | 661 | |
71b454dc KW |
662 | C<CopLABEL_len_flags> additionally returns the UTF-8ness of the returned label, |
663 | by setting C<*flags> to 0 or C<SVf_UTF8>. | |
33d29c13 KW |
664 | |
665 | =cut | |
666 | */ | |
667 | ||
aebc0cbe | 668 | #define CopLABEL(c) Perl_cop_fetch_label(aTHX_ (c), NULL, NULL) |
5db1eb8d BF |
669 | #define CopLABEL_len(c,len) Perl_cop_fetch_label(aTHX_ (c), len, NULL) |
670 | #define CopLABEL_len_flags(c,len,flags) Perl_cop_fetch_label(aTHX_ (c), len, flags) | |
dca6062a | 671 | #define CopLABEL_alloc(pv) ((pv)?savepv(pv):NULL) |
57843af0 | 672 | |
ed094faf | 673 | #define CopSTASH_ne(c,hv) (!CopSTASH_eq(c,hv)) |
cc49e20b | 674 | #define CopLINE(c) ((c)->cop_line) |
57843af0 GS |
675 | #define CopLINE_inc(c) (++CopLINE(c)) |
676 | #define CopLINE_dec(c) (--CopLINE(c)) | |
677 | #define CopLINE_set(c,l) (CopLINE(c) = (l)) | |
cc49e20b | 678 | |
248c2a4d | 679 | /* OutCopFILE() is CopFILE for output (caller, die, warn, etc.) */ |
e37778c2 | 680 | #define OutCopFILE(c) CopFILE(c) |
248c2a4d | 681 | |
d5ec2987 | 682 | #define CopHINTS_get(c) ((c)->cop_hints + 0) |
623e6609 | 683 | #define CopHINTS_set(c, h) STMT_START { \ |
1f4fbd3b MS |
684 | (c)->cop_hints = (h); \ |
685 | } STMT_END | |
623e6609 | 686 | |
79072805 LW |
687 | /* |
688 | * Here we have some enormously heavy (or at least ponderous) wizardry. | |
689 | */ | |
690 | ||
691 | /* subroutine context */ | |
692 | struct block_sub { | |
f9c764c5 | 693 | OP * retop; /* op to execute on exit from sub */ |
5b6f7443 | 694 | I32 old_cxsubix; /* previous value of si_cxsubix */ |
adcbf118 | 695 | /* Above here is the same for sub, format and eval. */ |
9aa350eb | 696 | PAD *prevcomppad; /* the caller's PL_comppad */ |
8e663997 | 697 | CV * cv; |
f9c764c5 | 698 | /* Above here is the same for sub and format. */ |
bb172083 | 699 | I32 olddepth; |
3073d04f | 700 | AV *savearray; |
f9c764c5 NC |
701 | }; |
702 | ||
703 | ||
704 | /* format context */ | |
705 | struct block_format { | |
f39bc417 | 706 | OP * retop; /* op to execute on exit from sub */ |
5b6f7443 | 707 | I32 old_cxsubix; /* previous value of si_cxsubix */ |
adcbf118 | 708 | /* Above here is the same for sub, format and eval. */ |
9aa350eb | 709 | PAD *prevcomppad; /* the caller's PL_comppad */ |
8e663997 | 710 | CV * cv; |
f9c764c5 NC |
711 | /* Above here is the same for sub and format. */ |
712 | GV * gv; | |
713 | GV * dfoutgv; | |
79072805 LW |
714 | }; |
715 | ||
4ebe6e95 DM |
716 | /* return a pointer to the current context */ |
717 | ||
718 | #define CX_CUR() (&cxstack[cxstack_ix]) | |
719 | ||
dfe0f39b DM |
720 | /* free all savestack items back to the watermark of the specified context */ |
721 | ||
e992140c | 722 | #define CX_LEAVE_SCOPE(cx) LEAVE_SCOPE(cx->blk_oldsaveix) |
dfe0f39b | 723 | |
5da525e9 DM |
724 | #ifdef DEBUGGING |
725 | /* on debugging builds, poison cx afterwards so we know no code | |
726 | * uses it - because after doing cxstack_ix--, any ties, exceptions etc | |
727 | * may overwrite the current stack frame */ | |
728 | # define CX_POP(cx) \ | |
4ebe6e95 | 729 | assert(CX_CUR() == cx); \ |
5da525e9 DM |
730 | cxstack_ix--; \ |
731 | cx = NULL; | |
732 | #else | |
733 | # define CX_POP(cx) cxstack_ix--; | |
734 | #endif | |
735 | ||
490576d1 | 736 | #define CX_PUSHSUB_GET_LVALUE_MASK(func) \ |
1f4fbd3b MS |
737 | /* If the context is indeterminate, then only the lvalue */ \ |
738 | /* flags that the caller also has are applicable. */ \ | |
739 | ( \ | |
740 | (PL_op->op_flags & OPf_WANT) \ | |
741 | ? OPpENTERSUB_LVAL_MASK \ | |
742 | : !(PL_op->op_private & OPpENTERSUB_LVAL_MASK) \ | |
743 | ? 0 : (U8)func(aTHX) \ | |
744 | ) | |
4587c532 | 745 | |
fad386cb | 746 | /* Restore old @_ */ |
b405d38b | 747 | #define CX_POP_SAVEARRAY(cx) \ |
6d4ff0d2 | 748 | STMT_START { \ |
f2b9631d | 749 | AV *cx_pop_savearray_av = GvAV(PL_defgv); \ |
1f4fbd3b | 750 | GvAV(PL_defgv) = cx->blk_sub.savearray; \ |
656457d0 | 751 | cx->blk_sub.savearray = NULL; \ |
f2b9631d | 752 | SvREFCNT_dec(cx_pop_savearray_av); \ |
6d4ff0d2 | 753 | } STMT_END |
6d4ff0d2 | 754 | |
ecf8e9dd | 755 | /* junk in @_ spells trouble when cloning CVs and in pp_caller(), so don't |
8e09340b GS |
756 | * leave any (a fast av_clear(ary), basically) */ |
757 | #define CLEAR_ARGARRAY(ary) \ | |
758 | STMT_START { \ | |
1f4fbd3b MS |
759 | AvMAX(ary) += AvARRAY(ary) - AvALLOC(ary); \ |
760 | AvARRAY(ary) = AvALLOC(ary); \ | |
761 | AvFILLp(ary) = -1; \ | |
8e09340b | 762 | } STMT_END |
7766f137 | 763 | |
7e27c4a5 | 764 | |
79072805 LW |
765 | /* eval context */ |
766 | struct block_eval { | |
8e663997 | 767 | OP * retop; /* op to execute on exit from eval */ |
5b6f7443 | 768 | I32 old_cxsubix; /* previous value of si_cxsubix */ |
8e663997 | 769 | /* Above here is the same for sub, format and eval. */ |
0f79a09d | 770 | SV * old_namesv; |
79072805 | 771 | OP * old_eval_root; |
748a9306 | 772 | SV * cur_text; |
2090ab20 | 773 | CV * cv; |
abd70938 | 774 | JMPENV * cur_top_env; /* value of PL_top_env when eval CX created */ |
79072805 LW |
775 | }; |
776 | ||
17347a51 NC |
777 | /* If we ever need more than 512 op types, change the shift from 7. |
778 | blku_gimme is actually also only 2 bits, so could be merged with something. | |
779 | */ | |
780 | ||
4c57ced5 DM |
781 | /* blk_u16 bit usage for eval contexts: */ |
782 | ||
783 | #define CxOLD_IN_EVAL(cx) (((cx)->blk_u16) & 0x3F) /* saved PL in_eval */ | |
784 | #define CxEVAL_TXT_REFCNTED(cx) (((cx)->blk_u16) & 0x40) /* cur_text rc++ */ | |
785 | #define CxOLD_OP_TYPE(cx) (((cx)->blk_u16) >> 7) /* type of eval op */ | |
85a64632 | 786 | |
79072805 LW |
787 | /* loop context */ |
788 | struct block_loop { | |
022eaa24 | 789 | LOOP * my_op; /* My op, that contains redo, next and last ops. */ |
df530c37 | 790 | union { /* different ways of locating the iteration variable */ |
1f4fbd3b MS |
791 | SV **svp; /* for lexicals: address of pad slot */ |
792 | GV *gv; /* for package vars */ | |
df530c37 | 793 | } itervar_u; |
f0bb9bf7 | 794 | SV *itersave; /* the original iteration var */ |
493b0a3c | 795 | union { |
1f4fbd3b MS |
796 | struct { /* CXt_LOOP_ARY, C<for (@ary)> */ |
797 | AV *ary; /* array being iterated over */ | |
798 | IV ix; /* index relative to base of array */ | |
799 | } ary; | |
800 | struct { /* CXt_LOOP_LIST, C<for (list)> */ | |
801 | I32 basesp; /* first element of list on stack */ | |
802 | IV ix; /* index relative to basesp */ | |
803 | } stack; | |
804 | struct { /* CXt_LOOP_LAZYIV, C<for (1..9)> */ | |
805 | IV cur; | |
806 | IV end; | |
807 | } lazyiv; | |
808 | struct { /* CXt_LOOP_LAZYSV C<for ('a'..'z')> */ | |
809 | SV * cur; | |
810 | SV * end; /* maxiumum value (or minimum in reverse) */ | |
811 | } lazysv; | |
d01136d6 | 812 | } state_u; |
7766f137 | 813 | #ifdef USE_ITHREADS |
b52de964 | 814 | PAD *oldcomppad; /* needed to map itervar_u.svp during thread clone */ |
f83b46a0 | 815 | #endif |
b52de964 | 816 | }; |
f83b46a0 | 817 | |
9af0df0b DM |
818 | #define CxITERVAR(c) \ |
819 | (CxPADLOOP(c) \ | |
820 | ? (c)->blk_loop.itervar_u.svp \ | |
821 | : ((c)->cx_type & CXp_FOR_GV) \ | |
822 | ? &GvSV((c)->blk_loop.itervar_u.gv) \ | |
823 | : (SV **)&(c)->blk_loop.itervar_u.gv) | |
f83b46a0 | 824 | |
a8b89476 TC |
825 | #define CxLABEL(c) (CopLABEL((c)->blk_oldcop)) |
826 | #define CxLABEL_len(c,len) (CopLABEL_len((c)->blk_oldcop, len)) | |
827 | #define CxLABEL_len_flags(c,len,flags) ((const char *)CopLABEL_len_flags((c)->blk_oldcop, len, flags)) | |
ae423868 | 828 | #define CxHASARGS(c) (((c)->cx_type & CXp_HASARGS) == CXp_HASARGS) |
d9203e03 DM |
829 | |
830 | /* CxLVAL(): the lval flags of the call site: the relevant flag bits from | |
831 | * the op_private field of the calling pp_entersub (or its caller's caller | |
832 | * if the caller's lvalue context isn't known): | |
833 | * OPpLVAL_INTRO: sub used in lvalue context, e.g. f() = 1; | |
834 | * OPpENTERSUB_INARGS (in conjunction with OPpLVAL_INTRO): the | |
835 | * function is being used as a sub arg or as a referent, e.g. | |
836 | * g(...,f(),...) or $r = \f() | |
837 | * OPpDEREF: 2-bit mask indicating e.g. f()->[0]. | |
838 | * Note the contrast with CvLVALUE(), which is a property of the sub | |
839 | * rather than the call site. | |
840 | */ | |
fb1a3d54 | 841 | #define CxLVAL(c) (0 + ((U8)((c)->blk_u16))) |
1956db7e | 842 | |
7766f137 | 843 | |
79072805 | 844 | |
7896dde7 Z |
845 | /* given/when context */ |
846 | struct block_givwhen { | |
1f4fbd3b | 847 | OP *leave_op; |
7896dde7 | 848 | SV *defsv_save; /* the original $_ */ |
0d863452 RH |
849 | }; |
850 | ||
0d863452 | 851 | |
c5369ccc | 852 | |
79072805 LW |
853 | /* context common to subroutines, evals and loops */ |
854 | struct block { | |
446d0787 | 855 | U8 blku_type; /* what kind of context this is */ |
2e0df0e8 | 856 | U8 blku_gimme; /* is this block running in list context? */ |
17347a51 | 857 | U16 blku_u16; /* used by block_sub and block_eval (so far) */ |
e992140c DM |
858 | I32 blku_oldsaveix; /* saved PL_savestack_ix */ |
859 | /* all the fields above must be aligned with same-sized fields as sbu */ | |
1bef65a2 | 860 | I32 blku_oldsp; /* current sp floor: where nextstate pops to */ |
79072805 | 861 | I32 blku_oldmarksp; /* mark stack index */ |
f284fecd | 862 | COP * blku_oldcop; /* old curcop pointer */ |
79072805 | 863 | PMOP * blku_oldpm; /* values of pattern match vars */ |
bb3300d1 | 864 | SSize_t blku_old_tmpsfloor; /* saved PL_tmps_floor */ |
f284fecd | 865 | I32 blku_oldscopesp; /* scope stack index */ |
79072805 LW |
866 | |
867 | union { | |
1f4fbd3b MS |
868 | struct block_sub blku_sub; |
869 | struct block_format blku_format; | |
870 | struct block_eval blku_eval; | |
871 | struct block_loop blku_loop; | |
872 | struct block_givwhen blku_givwhen; | |
79072805 LW |
873 | } blk_u; |
874 | }; | |
875 | #define blk_oldsp cx_u.cx_blk.blku_oldsp | |
876 | #define blk_oldcop cx_u.cx_blk.blku_oldcop | |
79072805 LW |
877 | #define blk_oldmarksp cx_u.cx_blk.blku_oldmarksp |
878 | #define blk_oldscopesp cx_u.cx_blk.blku_oldscopesp | |
879 | #define blk_oldpm cx_u.cx_blk.blku_oldpm | |
880 | #define blk_gimme cx_u.cx_blk.blku_gimme | |
446d0787 | 881 | #define blk_u16 cx_u.cx_blk.blku_u16 |
e992140c | 882 | #define blk_oldsaveix cx_u.cx_blk.blku_oldsaveix |
ce8bb8d8 | 883 | #define blk_old_tmpsfloor cx_u.cx_blk.blku_old_tmpsfloor |
79072805 | 884 | #define blk_sub cx_u.cx_blk.blk_u.blku_sub |
f9c764c5 | 885 | #define blk_format cx_u.cx_blk.blk_u.blku_format |
79072805 LW |
886 | #define blk_eval cx_u.cx_blk.blk_u.blku_eval |
887 | #define blk_loop cx_u.cx_blk.blk_u.blku_loop | |
7896dde7 | 888 | #define blk_givwhen cx_u.cx_blk.blk_u.blku_givwhen |
79072805 | 889 | |
5e691bc6 | 890 | #define CX_DEBUG(cx, action) \ |
d9f81b50 | 891 | DEBUG_l( \ |
f31da5f4 | 892 | Perl_deb(aTHX_ "CX %ld %s %s (scope %ld,%ld) (save %ld,%ld) in %s at %s:%d\n",\ |
1f4fbd3b MS |
893 | (long)cxstack_ix, \ |
894 | action, \ | |
895 | PL_block_type[CxTYPE(cx)], \ | |
896 | (long)PL_scopestack_ix, \ | |
897 | (long)(cx->blk_oldscopesp), \ | |
898 | (long)PL_savestack_ix, \ | |
899 | (long)(cx->blk_oldsaveix), \ | |
f31da5f4 | 900 | SAFE_FUNCTION__, __FILE__, __LINE__)); |
1c98cc53 | 901 | |
ed8ff0f3 | 902 | |
79072805 LW |
903 | |
904 | /* substitution context */ | |
905 | struct subst { | |
e992140c | 906 | U8 sbu_type; /* same as blku_type */ |
1ed74d04 | 907 | U8 sbu_rflags; |
e992140c DM |
908 | U16 sbu_rxtainted; |
909 | I32 sbu_oldsaveix; /* same as blku_oldsaveix */ | |
a7f94955 | 910 | /* all the fields above must be aligned with same-sized fields as blk_u */ |
3c6ef0a5 FC |
911 | SSize_t sbu_iters; |
912 | SSize_t sbu_maxiters; | |
79072805 LW |
913 | char * sbu_orig; |
914 | SV * sbu_dstr; | |
915 | SV * sbu_targ; | |
916 | char * sbu_s; | |
917 | char * sbu_m; | |
918 | char * sbu_strend; | |
c90c0ff4 | 919 | void * sbu_rxres; |
c07a80fd | 920 | REGEXP * sbu_rx; |
79072805 | 921 | }; |
a0412c00 KW |
922 | |
923 | #ifdef PERL_CORE | |
924 | ||
79072805 LW |
925 | #define sb_iters cx_u.cx_subst.sbu_iters |
926 | #define sb_maxiters cx_u.cx_subst.sbu_maxiters | |
22e551b9 | 927 | #define sb_rflags cx_u.cx_subst.sbu_rflags |
71be2cbc | 928 | #define sb_rxtainted cx_u.cx_subst.sbu_rxtainted |
79072805 LW |
929 | #define sb_orig cx_u.cx_subst.sbu_orig |
930 | #define sb_dstr cx_u.cx_subst.sbu_dstr | |
931 | #define sb_targ cx_u.cx_subst.sbu_targ | |
932 | #define sb_s cx_u.cx_subst.sbu_s | |
933 | #define sb_m cx_u.cx_subst.sbu_m | |
934 | #define sb_strend cx_u.cx_subst.sbu_strend | |
c90c0ff4 | 935 | #define sb_rxres cx_u.cx_subst.sbu_rxres |
c07a80fd | 936 | #define sb_rx cx_u.cx_subst.sbu_rx |
79072805 | 937 | |
490576d1 | 938 | # define CX_PUSHSUBST(cx) CXINC, cx = CX_CUR(), \ |
1f4fbd3b MS |
939 | cx->blk_oldsaveix = oldsave, \ |
940 | cx->sb_iters = iters, \ | |
941 | cx->sb_maxiters = maxiters, \ | |
942 | cx->sb_rflags = r_flags, \ | |
943 | cx->sb_rxtainted = rxtainted, \ | |
944 | cx->sb_orig = orig, \ | |
945 | cx->sb_dstr = dstr, \ | |
946 | cx->sb_targ = targ, \ | |
947 | cx->sb_s = s, \ | |
948 | cx->sb_m = m, \ | |
949 | cx->sb_strend = strend, \ | |
950 | cx->sb_rxres = NULL, \ | |
951 | cx->sb_rx = rx, \ | |
952 | cx->cx_type = CXt_SUBST | (once ? CXp_ONCE : 0); \ | |
953 | rxres_save(&cx->sb_rxres, rx); \ | |
954 | (void)ReREFCNT_inc(rx); \ | |
cf69025f | 955 | SvREFCNT_inc_void_NN(targ) |
79072805 | 956 | |
b405d38b | 957 | # define CX_POPSUBST(cx) \ |
77189b8c DM |
958 | STMT_START { \ |
959 | REGEXP *re; \ | |
e4592eb4 | 960 | assert(CxTYPE(cx) == CXt_SUBST); \ |
1f4fbd3b MS |
961 | rxres_free(&cx->sb_rxres); \ |
962 | re = cx->sb_rx; \ | |
963 | cx->sb_rx = NULL; \ | |
964 | ReREFCNT_dec(re); \ | |
77189b8c DM |
965 | SvREFCNT_dec_NN(cx->sb_targ); \ |
966 | } STMT_END | |
9c105995 NC |
967 | #endif |
968 | ||
969 | #define CxONCE(cx) ((cx)->cx_type & CXp_ONCE) | |
79072805 LW |
970 | |
971 | struct context { | |
79072805 | 972 | union { |
1f4fbd3b MS |
973 | struct block cx_blk; |
974 | struct subst cx_subst; | |
79072805 LW |
975 | } cx_u; |
976 | }; | |
2e0df0e8 | 977 | #define cx_type cx_u.cx_subst.sbu_type |
6b35e009 | 978 | |
76753e7f NC |
979 | /* If you re-order these, there is also an array of uppercase names in perl.h |
980 | and a static array of context names in pp_ctl.c */ | |
3701055e | 981 | #define CXTYPEMASK 0xf |
79646418 | 982 | #define CXt_NULL 0 /* currently only used for sort BLOCK */ |
7896dde7 | 983 | #define CXt_WHEN 1 |
76753e7f | 984 | #define CXt_BLOCK 2 |
7896dde7 Z |
985 | /* When micro-optimising :-) keep GIVEN next to the LOOPs, as these 5 share a |
986 | jump table in pp_ctl.c | |
987 | The first 4 don't have a 'case' in at least one switch statement in pp_ctl.c | |
988 | */ | |
989 | #define CXt_GIVEN 3 | |
990 | ||
991 | /* be careful of the ordering of these five. Macros like CxTYPE_is_LOOP, | |
93661e56 | 992 | * CxFOREACH compare ranges */ |
c349b9a0 DM |
993 | #define CXt_LOOP_ARY 4 /* for (@ary) { ...; } */ |
994 | #define CXt_LOOP_LAZYSV 5 /* for ('a'..'z') { ...; } */ | |
995 | #define CXt_LOOP_LAZYIV 6 /* for (1..9) { ...; } */ | |
996 | #define CXt_LOOP_LIST 7 /* for (1,2,3) { ...; } */ | |
997 | #define CXt_LOOP_PLAIN 8 /* while (...) { ...; } | |
998 | or plain block { ...; } */ | |
93661e56 DM |
999 | #define CXt_SUB 9 |
1000 | #define CXt_FORMAT 10 | |
a1325b90 | 1001 | #define CXt_EVAL 11 /* eval'', eval{}, try{} */ |
93661e56 | 1002 | #define CXt_SUBST 12 |
f79e2ff9 | 1003 | #define CXt_DEFER 13 |
76753e7f | 1004 | /* SUBST doesn't feature in all switch statements. */ |
79072805 | 1005 | |
ae423868 | 1006 | /* private flags for CXt_SUB and CXt_FORMAT */ |
79646418 DM |
1007 | #define CXp_MULTICALL 0x10 /* part of a multicall (so don't tear down |
1008 | context on exit). (not CXt_FORMAT) */ | |
1f27d788 | 1009 | #define CXp_HASARGS 0x20 |
b0065247 DM |
1010 | #define CXp_SUB_RE 0x40 /* code called within regex, i.e. (?{}) */ |
1011 | #define CXp_SUB_RE_FAKE 0x80 /* fake sub CX for (?{}) in current scope */ | |
ae423868 | 1012 | |
6b35e009 | 1013 | /* private flags for CXt_EVAL */ |
1f27d788 | 1014 | #define CXp_REAL 0x20 /* truly eval'', not a lookalike */ |
99dbf645 | 1015 | #define CXp_EVALBLOCK 0x40 /* eval{}, not eval'' or similar */ |
a1325b90 | 1016 | #define CXp_TRY 0x80 /* try {} block */ |
6b35e009 | 1017 | |
7766f137 | 1018 | /* private flags for CXt_LOOP */ |
28e0cf42 | 1019 | |
7896dde7 Z |
1020 | /* this is only set in conjunction with CXp_FOR_GV */ |
1021 | #define CXp_FOR_DEF 0x10 /* foreach using $_ */ | |
28e0cf42 | 1022 | /* these 3 are mutually exclusive */ |
d39c26a6 | 1023 | #define CXp_FOR_LVREF 0x20 /* foreach using \$var */ |
9af0df0b DM |
1024 | #define CXp_FOR_GV 0x40 /* foreach using package var */ |
1025 | #define CXp_FOR_PAD 0x80 /* foreach using lexical var */ | |
28e0cf42 | 1026 | |
9af0df0b | 1027 | #define CxPADLOOP(c) ((c)->cx_type & CXp_FOR_PAD) |
e846cb92 | 1028 | |
1ed74d04 NC |
1029 | /* private flags for CXt_SUBST */ |
1030 | #define CXp_ONCE 0x10 /* What was sbu_once in struct subst */ | |
7766f137 | 1031 | |
6b35e009 | 1032 | #define CxTYPE(c) ((c)->cx_type & CXTYPEMASK) |
7896dde7 | 1033 | #define CxTYPE_is_LOOP(c) ( CxTYPE(cx) >= CXt_LOOP_ARY \ |
113ebcf5 | 1034 | && CxTYPE(cx) <= CXt_LOOP_PLAIN) |
79646418 | 1035 | #define CxMULTICALL(c) ((c)->cx_type & CXp_MULTICALL) |
0588a150 | 1036 | #define CxREALEVAL(c) (((c)->cx_type & (CXTYPEMASK|CXp_REAL)) \ |
1f4fbd3b | 1037 | == (CXt_EVAL|CXp_REAL)) |
99dbf645 | 1038 | #define CxEVALBLOCK(c) (((c)->cx_type & (CXTYPEMASK|CXp_EVALBLOCK)) \ |
1f4fbd3b | 1039 | == (CXt_EVAL|CXp_EVALBLOCK)) |
a1325b90 PE |
1040 | #define CxTRY(c) (((c)->cx_type & (CXTYPEMASK|CXp_TRY)) \ |
1041 | == (CXt_EVAL|CXp_TRY)) | |
113ebcf5 DM |
1042 | #define CxFOREACH(c) ( CxTYPE(cx) >= CXt_LOOP_ARY \ |
1043 | && CxTYPE(cx) <= CXt_LOOP_LIST) | |
6b35e009 | 1044 | |
e5e291f5 PE |
1045 | /* private flags for CXt_DEFER */ |
1046 | #define CXp_FINALLY 0x20 /* `finally` block; semantically identical | |
1047 | * but matters for diagnostic messages */ | |
1048 | ||
99dbf645 PE |
1049 | /* deprecated old name before real try/catch was added */ |
1050 | #define CXp_TRYBLOCK CXp_EVALBLOCK | |
1051 | #define CxTRYBLOCK(c) CxEVALBLOCK(c) | |
1052 | ||
109bf713 | 1053 | #define CXINC (cxstack_ix < cxstack_max ? ++cxstack_ix : (cxstack_ix = cxinc())) |
79072805 | 1054 | |
eb7e169e PE |
1055 | #define G_SCALAR 2 |
1056 | #define G_LIST 3 | |
1057 | #define G_VOID 1 | |
1058 | #define G_WANT 3 | |
1059 | ||
1060 | #ifndef PERL_CORE | |
1061 | /* name prior to 5.31.1 */ | |
1062 | # define G_ARRAY G_LIST | |
1063 | #endif | |
79072805 | 1064 | |
864dbfa3 | 1065 | /* extra flags for Perl_call_* routines */ |
66ff4fb5 | 1066 | #define G_DISCARD 0x4 /* Call FREETMPS. |
1f4fbd3b MS |
1067 | Don't change this without consulting the |
1068 | hash actions codes defined in hv.h */ | |
66ff4fb5 TC |
1069 | #define G_EVAL 0x8 /* Assume eval {} around subroutine call. */ |
1070 | #define G_NOARGS 0x10 /* Don't construct a @_ array. */ | |
1071 | #define G_KEEPERR 0x20 /* Warn for errors, don't overwrite $@ */ | |
1072 | #define G_NODEBUG 0x40 /* Disable debugging at toplevel. */ | |
1073 | #define G_METHOD 0x80 /* Calling method. */ | |
1074 | #define G_FAKINGEVAL 0x100 /* Faking an eval context for call_sv or | |
1f4fbd3b | 1075 | fold_constants. */ |
66ff4fb5 | 1076 | #define G_UNDEF_FILL 0x200 /* Fill the stack with &PL_sv_undef |
1f4fbd3b MS |
1077 | A special case for UNSHIFT in |
1078 | Perl_magic_methcall(). */ | |
66ff4fb5 | 1079 | #define G_WRITING_TO_STDERR 0x400 /* Perl_write_to_stderr() is calling |
1f4fbd3b | 1080 | Perl_magic_methcall(). */ |
66ff4fb5 TC |
1081 | #define G_RE_REPARSING 0x800 /* compiling a run-time /(?{..})/ */ |
1082 | #define G_METHOD_NAMED 0x1000 /* calling named method, eg without :: or ' */ | |
1083 | #define G_RETHROW 0x2000 /* eval_sv(): re-throw any error */ | |
e336de0d | 1084 | |
faef0170 HS |
1085 | /* flag bits for PL_in_eval */ |
1086 | #define EVAL_NULL 0 /* not in an eval */ | |
1087 | #define EVAL_INEVAL 1 /* some enclosing scope is an eval */ | |
1088 | #define EVAL_WARNONLY 2 /* used by yywarn() when calling yyerror() */ | |
864dbfa3 | 1089 | #define EVAL_KEEPERR 4 /* set by Perl_call_sv if G_KEEPERR */ |
6dc8a9e4 | 1090 | #define EVAL_INREQUIRE 8 /* The code is being required. */ |
a1941760 | 1091 | #define EVAL_RE_REPARSING 0x10 /* eval_sv() called with G_RE_REPARSING */ |
4c57ced5 | 1092 | /* if adding extra bits, make sure they can fit in CxOLD_OP_TYPE() */ |
faef0170 | 1093 | |
e336de0d GS |
1094 | /* Support for switching (stack and block) contexts. |
1095 | * This ensures magic doesn't invalidate local stack and cx pointers. | |
ec834f46 KW |
1096 | * Which one to use (or add) is mostly, but not completely arbitrary: See |
1097 | * http://nntp.perl.org/group/perl.perl5.porters/257169 | |
e336de0d GS |
1098 | */ |
1099 | ||
e788e7d3 GS |
1100 | #define PERLSI_UNKNOWN -1 |
1101 | #define PERLSI_UNDEF 0 | |
1102 | #define PERLSI_MAIN 1 | |
1103 | #define PERLSI_MAGIC 2 | |
1104 | #define PERLSI_SORT 3 | |
1105 | #define PERLSI_SIGNAL 4 | |
1106 | #define PERLSI_OVERLOAD 5 | |
1107 | #define PERLSI_DESTROY 6 | |
1108 | #define PERLSI_WARNHOOK 7 | |
1109 | #define PERLSI_DIEHOOK 8 | |
1110 | #define PERLSI_REQUIRE 9 | |
e1a10f35 | 1111 | #define PERLSI_MULTICALL 10 |
b6d9446c | 1112 | #define PERLSI_REGCOMP 11 |
e336de0d GS |
1113 | |
1114 | struct stackinfo { | |
1115 | AV * si_stack; /* stack for current runlevel */ | |
1116 | PERL_CONTEXT * si_cxstack; /* context stack for runlevel */ | |
9bd87817 NC |
1117 | struct stackinfo * si_prev; |
1118 | struct stackinfo * si_next; | |
e336de0d GS |
1119 | I32 si_cxix; /* current context index */ |
1120 | I32 si_cxmax; /* maximum allocated index */ | |
5b6f7443 | 1121 | I32 si_cxsubix; /* topmost sub/eval/format */ |
e336de0d | 1122 | I32 si_type; /* type of runlevel */ |
ce2f7c3b | 1123 | I32 si_markoff; /* offset where markstack begins for us. |
1f4fbd3b MS |
1124 | * currently used only with DEBUGGING, |
1125 | * but not #ifdef-ed for bincompat */ | |
1fced1a2 | 1126 | #if defined DEBUGGING && !defined DEBUGGING_RE_ONLY |
87058c31 DM |
1127 | /* high water mark: for checking if the stack was correctly extended / |
1128 | * tested for extension by each pp function */ | |
1129 | SSize_t si_stack_hwm; | |
1130 | #endif | |
1131 | ||
e336de0d GS |
1132 | }; |
1133 | ||
55d39ade KW |
1134 | /* |
1135 | =for apidoc Ay||PERL_SI | |
1136 | Use this typedef to declare variables that are to hold C<struct stackinfo>. | |
1137 | ||
1138 | =cut | |
1139 | */ | |
e336de0d GS |
1140 | typedef struct stackinfo PERL_SI; |
1141 | ||
3280af22 NIS |
1142 | #define cxstack (PL_curstackinfo->si_cxstack) |
1143 | #define cxstack_ix (PL_curstackinfo->si_cxix) | |
1144 | #define cxstack_max (PL_curstackinfo->si_cxmax) | |
e336de0d GS |
1145 | |
1146 | #ifdef DEBUGGING | |
ce2f7c3b GS |
1147 | # define SET_MARK_OFFSET \ |
1148 | PL_curstackinfo->si_markoff = PL_markstack_ptr - PL_markstack | |
e336de0d | 1149 | #else |
ce2f7c3b | 1150 | # define SET_MARK_OFFSET NOOP |
e336de0d GS |
1151 | #endif |
1152 | ||
87058c31 | 1153 | #if defined DEBUGGING && !defined DEBUGGING_RE_ONLY |
45d6bfc0 | 1154 | # define PUSHSTACK_INIT_HWM(si) ((si)->si_stack_hwm = 0) |
87058c31 DM |
1155 | #else |
1156 | # define PUSHSTACK_INIT_HWM(si) NOOP | |
1157 | #endif | |
1158 | ||
d3acc0f7 | 1159 | #define PUSHSTACKi(type) \ |
e336de0d | 1160 | STMT_START { \ |
1f4fbd3b MS |
1161 | PERL_SI *next = PL_curstackinfo->si_next; \ |
1162 | DEBUG_l({ \ | |
1163 | int i = 0; PERL_SI *p = PL_curstackinfo; \ | |
1164 | while (p) { i++; p = p->si_prev; } \ | |
f31da5f4 YO |
1165 | Perl_deb(aTHX_ "push STACKINFO %d in %s at %s:%d\n", \ |
1166 | i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \ | |
1f4fbd3b MS |
1167 | if (!next) { \ |
1168 | next = new_stackinfo(32, 2048/sizeof(PERL_CONTEXT) - 1); \ | |
1169 | next->si_prev = PL_curstackinfo; \ | |
1170 | PL_curstackinfo->si_next = next; \ | |
1171 | } \ | |
1172 | next->si_type = type; \ | |
1173 | next->si_cxix = -1; \ | |
1174 | next->si_cxsubix = -1; \ | |
87058c31 | 1175 | PUSHSTACK_INIT_HWM(next); \ |
1f4fbd3b MS |
1176 | AvFILLp(next->si_stack) = 0; \ |
1177 | SWITCHSTACK(PL_curstack,next->si_stack); \ | |
1178 | PL_curstackinfo = next; \ | |
1179 | SET_MARK_OFFSET; \ | |
e336de0d GS |
1180 | } STMT_END |
1181 | ||
e788e7d3 | 1182 | #define PUSHSTACK PUSHSTACKi(PERLSI_UNKNOWN) |
d3acc0f7 | 1183 | |
3095d977 GS |
1184 | /* POPSTACK works with PL_stack_sp, so it may need to be bracketed by |
1185 | * PUTBACK/SPAGAIN to flush/refresh any local SP that may be active */ | |
d3acc0f7 | 1186 | #define POPSTACK \ |
e336de0d | 1187 | STMT_START { \ |
1f4fbd3b MS |
1188 | dSP; \ |
1189 | PERL_SI * const prev = PL_curstackinfo->si_prev; \ | |
1190 | DEBUG_l({ \ | |
1191 | int i = -1; PERL_SI *p = PL_curstackinfo; \ | |
1192 | while (p) { i++; p = p->si_prev; } \ | |
f31da5f4 YO |
1193 | Perl_deb(aTHX_ "pop STACKINFO %d in %s at %s:%d\n", \ |
1194 | i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \ | |
1f4fbd3b MS |
1195 | if (!prev) { \ |
1196 | Perl_croak_popstack(); \ | |
1197 | } \ | |
1198 | SWITCHSTACK(PL_curstack,prev->si_stack); \ | |
1199 | /* don't free prev here, free them all at the END{} */ \ | |
1200 | PL_curstackinfo = prev; \ | |
e336de0d GS |
1201 | } STMT_END |
1202 | ||
1203 | #define POPSTACK_TO(s) \ | |
1204 | STMT_START { \ | |
1f4fbd3b MS |
1205 | while (PL_curstack != s) { \ |
1206 | dounwind(-1); \ | |
1207 | POPSTACK; \ | |
1208 | } \ | |
e336de0d | 1209 | } STMT_END |
923e4eb5 | 1210 | |
d57dfc83 | 1211 | /* |
3f620621 | 1212 | =for apidoc_section $utility |
d57dfc83 KW |
1213 | =for apidoc Amn|bool|IN_PERL_COMPILETIME |
1214 | Returns 1 if this macro is being called during the compilation phase of the | |
1215 | program; otherwise 0; | |
ed8ff0f3 | 1216 | |
d57dfc83 KW |
1217 | =for apidoc Amn|bool|IN_PERL_RUNTIME |
1218 | Returns 1 if this macro is being called during the execution phase of the | |
1219 | program; otherwise 0; | |
ed8ff0f3 | 1220 | |
d57dfc83 KW |
1221 | =cut |
1222 | */ | |
1223 | #define IN_PERL_COMPILETIME cBOOL(PL_curcop == &PL_compiling) | |
1224 | #define IN_PERL_RUNTIME cBOOL(PL_curcop != &PL_compiling) | |
ed8ff0f3 | 1225 | |
9850bf21 | 1226 | /* |
3f620621 | 1227 | =for apidoc_section $multicall |
9850bf21 | 1228 | |
3734d2f5 | 1229 | =for apidoc Amn;||dMULTICALL |
72d33970 | 1230 | Declare local variables for a multicall. See L<perlcall/LIGHTWEIGHT CALLBACKS>. |
9850bf21 | 1231 | |
3734d2f5 | 1232 | =for apidoc Am;||PUSH_MULTICALL|CV* the_cv |
9850bf21 | 1233 | Opening bracket for a lightweight callback. |
0eda4409 | 1234 | See L<perlcall/LIGHTWEIGHT CALLBACKS>. |
9850bf21 | 1235 | |
3734d2f5 | 1236 | =for apidoc Amn;||MULTICALL |
72d33970 | 1237 | Make a lightweight callback. See L<perlcall/LIGHTWEIGHT CALLBACKS>. |
9850bf21 | 1238 | |
3734d2f5 | 1239 | =for apidoc Amn;||POP_MULTICALL |
9850bf21 | 1240 | Closing bracket for a lightweight callback. |
0eda4409 | 1241 | See L<perlcall/LIGHTWEIGHT CALLBACKS>. |
9850bf21 RH |
1242 | |
1243 | =cut | |
1244 | */ | |
1245 | ||
1246 | #define dMULTICALL \ | |
79503099 | 1247 | OP *multicall_cop; \ |
35095fd0 | 1248 | bool multicall_oldcatch |
9850bf21 | 1249 | |
82f35e8b | 1250 | #define PUSH_MULTICALL(the_cv) \ |
b0065247 | 1251 | PUSH_MULTICALL_FLAGS(the_cv, 0) |
81ed78b2 | 1252 | |
b0065247 DM |
1253 | /* Like PUSH_MULTICALL, but allows you to specify extra flags |
1254 | * for the CX stack entry (this isn't part of the public API) */ | |
81ed78b2 | 1255 | |
b0065247 | 1256 | #define PUSH_MULTICALL_FLAGS(the_cv, flags) \ |
9850bf21 | 1257 | STMT_START { \ |
79503099 | 1258 | PERL_CONTEXT *cx; \ |
1f4fbd3b MS |
1259 | CV * const _nOnclAshIngNamE_ = the_cv; \ |
1260 | CV * const cv = _nOnclAshIngNamE_; \ | |
1261 | PADLIST * const padlist = CvPADLIST(cv); \ | |
1262 | multicall_oldcatch = CATCH_GET; \ | |
1263 | CATCH_SET(TRUE); \ | |
1264 | PUSHSTACKi(PERLSI_MULTICALL); \ | |
1265 | cx = cx_pushblock((CXt_SUB|CXp_MULTICALL|flags), (U8)gimme, \ | |
fd9b7244 | 1266 | PL_stack_sp, PL_savestack_ix); \ |
79503099 | 1267 | cx_pushsub(cx, cv, NULL, 0); \ |
1f4fbd3b | 1268 | SAVEOP(); \ |
b0065247 DM |
1269 | if (!(flags & CXp_SUB_RE_FAKE)) \ |
1270 | CvDEPTH(cv)++; \ | |
1f4fbd3b MS |
1271 | if (CvDEPTH(cv) >= 2) \ |
1272 | Perl_pad_push(aTHX_ padlist, CvDEPTH(cv)); \ | |
1273 | PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv)); \ | |
1274 | multicall_cop = CvSTART(cv); \ | |
9850bf21 RH |
1275 | } STMT_END |
1276 | ||
1277 | #define MULTICALL \ | |
1278 | STMT_START { \ | |
1f4fbd3b MS |
1279 | PL_op = multicall_cop; \ |
1280 | CALLRUNOPS(aTHX); \ | |
9850bf21 RH |
1281 | } STMT_END |
1282 | ||
1283 | #define POP_MULTICALL \ | |
1284 | STMT_START { \ | |
79503099 | 1285 | PERL_CONTEXT *cx; \ |
1f4fbd3b MS |
1286 | cx = CX_CUR(); \ |
1287 | CX_LEAVE_SCOPE(cx); \ | |
a73d8813 | 1288 | cx_popsub_common(cx); \ |
4df352a8 | 1289 | gimme = cx->blk_gimme; \ |
7e27c4a5 | 1290 | PERL_UNUSED_VAR(gimme); /* for API */ \ |
1f4fbd3b MS |
1291 | cx_popblock(cx); \ |
1292 | CX_POP(cx); \ | |
1293 | POPSTACK; \ | |
1294 | CATCH_SET(multicall_oldcatch); \ | |
1295 | SPAGAIN; \ | |
9850bf21 | 1296 | } STMT_END |
b3ca2e83 | 1297 | |
81ed78b2 DM |
1298 | /* Change the CV of an already-pushed MULTICALL CxSUB block. |
1299 | * (this isn't part of the public API) */ | |
1300 | ||
b0065247 | 1301 | #define CHANGE_MULTICALL_FLAGS(the_cv, flags) \ |
81ed78b2 | 1302 | STMT_START { \ |
1f4fbd3b MS |
1303 | CV * const _nOnclAshIngNamE_ = the_cv; \ |
1304 | CV * const cv = _nOnclAshIngNamE_; \ | |
1305 | PADLIST * const padlist = CvPADLIST(cv); \ | |
79503099 | 1306 | PERL_CONTEXT *cx = CX_CUR(); \ |
1f4fbd3b | 1307 | assert(CxMULTICALL(cx)); \ |
a73d8813 | 1308 | cx_popsub_common(cx); \ |
1f4fbd3b | 1309 | cx->cx_type = (CXt_SUB|CXp_MULTICALL|flags); \ |
79503099 | 1310 | cx_pushsub(cx, cv, NULL, 0); \ |
b0065247 DM |
1311 | if (!(flags & CXp_SUB_RE_FAKE)) \ |
1312 | CvDEPTH(cv)++; \ | |
1f4fbd3b MS |
1313 | if (CvDEPTH(cv) >= 2) \ |
1314 | Perl_pad_push(aTHX_ padlist, CvDEPTH(cv)); \ | |
1315 | PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv)); \ | |
1316 | multicall_cop = CvSTART(cv); \ | |
81ed78b2 | 1317 | } STMT_END |
b3ca2e83 | 1318 | /* |
14d04a33 | 1319 | * ex: set ts=8 sts=4 sw=4 et: |
b3ca2e83 | 1320 | */ |