3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Larry Wall and others
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.
9 * Control ops (cops) are one of the two ops OP_NEXTSTATE and OP_DBSTATE,
10 * that (loosely speaking) are statement separators.
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,
13 * and thus can be used to determine our current state.
16 /* A jmpenv packages the state required to perform a proper non-local jump.
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
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
23 * null to ensure this).
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.
33 struct jmpenv * je_prev;
34 Sigjmp_buf je_buf; /* uninit if je_prev is NULL */
35 int je_ret; /* last exception thrown */
36 bool je_mustcatch; /* longjmp()s must be caught locally */
37 U16 je_old_delaymagic; /* saved PL_delaymagic */
38 SSize_t je_old_stack_hwm;
41 typedef struct jmpenv JMPENV;
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) \
48 if (PL_curstackinfo->si_stack_hwm < (je).je_old_stack_hwm) \
49 PL_curstackinfo->si_stack_hwm = (je).je_old_stack_hwm
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
57 * How to build the first jmpenv.
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 {}!
66 #define JMPENV_BOOTSTRAP \
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; \
74 JE_OLD_STACK_HWM_zero; \
78 * PERL_FLEXIBLE_EXCEPTIONS
80 * All the flexible exceptions code has been removed.
81 * See the following threads for details:
83 * Message-Id: 20040713143217.GB1424@plum.flirble.org
84 * https://www.nntp.perl.org/group/perl.perl5.porters/2004/07/msg93041.html
86 * Joshua's original patches (which weren't applied) and discussion:
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
95 * Chip's reworked patch and discussion:
97 * http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-03/msg00520.html
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().
104 * The original patches that introduces flexible exceptions were:
106 * https://github.com/Perl/perl5/commit/312caa8e97f1c7ee342a9895c2f0e749625b4929
107 * https://github.com/Perl/perl5/commit/14dd3ad8c9bf82cf09798a22cc89a9862dfd6d1a
111 #define dJMPENV JMPENV cur_env
113 #define JMPENV_PUSH(v) \
117 JMPENV *p = PL_top_env; \
118 while (p) { i++; p = p->je_prev; } \
119 Perl_deb(aTHX_ "JMPENV_PUSH pre level=%d in %s at %s:%d\n", \
120 i, SAFE_FUNCTION__, __FILE__, __LINE__); \
122 cur_env.je_prev = PL_top_env; \
123 JE_OLD_STACK_HWM_save(cur_env); \
124 /* setjmp() is callable in limited contexts which does not */ \
125 /* include assignment, so switch() instead */ \
126 switch (PerlProc_setjmp(cur_env.je_buf, SCOPE_SAVES_SIGNAL_MASK)) { \
127 case 0: cur_env.je_ret = 0; break; \
128 case 1: cur_env.je_ret = 1; break; \
129 case 2: cur_env.je_ret = 2; break; \
130 case 3: cur_env.je_ret = 3; break; \
131 default: Perl_croak(aTHX_ "panic: unexpected setjmp() result\n"); \
133 JE_OLD_STACK_HWM_restore(cur_env); \
134 PL_top_env = &cur_env; \
135 cur_env.je_mustcatch = FALSE; \
136 cur_env.je_old_delaymagic = PL_delaymagic; \
139 JMPENV *p = PL_top_env; \
140 while (p) { i++; p = p->je_prev; } \
141 Perl_deb(aTHX_ "JMPENV_PUSH level=%d ret=%d in %s at %s:%d\n", \
142 i, cur_env.je_ret, SAFE_FUNCTION__, __FILE__, __LINE__); \
144 (v) = cur_env.je_ret; \
150 int i = -1; JMPENV *p = PL_top_env; \
151 while (p) { i++; p = p->je_prev; } \
152 Perl_deb(aTHX_ "JMPENV_POP level=%d in %s at %s:%d\n", \
153 i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \
154 assert(PL_top_env == &cur_env); \
155 PL_delaymagic = cur_env.je_old_delaymagic; \
156 PL_top_env = cur_env.je_prev; \
159 #define JMPENV_JUMP(v) \
162 int i = -1; JMPENV *p = PL_top_env; \
163 while (p) { i++; p = p->je_prev; } \
164 Perl_deb(aTHX_ "JMPENV_JUMP(%d) level=%d in %s at %s:%d\n", \
165 (int)(v), i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \
166 if (PL_top_env->je_prev) { \
167 assert((v) >= 0 && (v) <= 3); \
168 PerlProc_longjmp(PL_top_env->je_buf, (v)); \
171 PerlProc_exit(STATUS_EXIT); \
172 PerlIO_printf(PerlIO_stderr(), "panic: top_env, v=%d\n", (int)(v)); \
176 #define CATCH_GET (PL_top_env->je_mustcatch)
177 #define CATCH_SET(v) \
181 "JUMPLEVEL set catch %d => %d (for %p) in %s at %s:%d\n", \
182 PL_top_env->je_mustcatch, (v), (void*)PL_top_env, \
183 SAFE_FUNCTION__, __FILE__, __LINE__);) \
184 PL_top_env->je_mustcatch = (v); \
188 =for apidoc_section $COP
191 typedef struct refcounted_he COPHH;
193 #define COPHH_KEY_UTF8 REFCOUNTED_HE_KEY_UTF8
194 #define COPHH_EXISTS REFCOUNTED_HE_EXISTS
197 =for apidoc Amx|SV *|cophh_fetch_pv |const COPHH *cophh|const char *key |U32 hash|U32 flags
198 =for apidoc_item|SV *|cophh_fetch_pvn|const COPHH *cophh|const char *key|STRLEN keylen|U32 hash|U32 flags
199 =for apidoc_item|SV *|cophh_fetch_pvs|const COPHH *cophh| "key" |U32 flags
200 =for apidoc_item|SV *|cophh_fetch_sv |const COPHH *cophh| SV *key |U32 hash|U32 flags
202 These look up the entry in the cop hints hash C<cophh> with the key specified by
203 C<key> (and C<keylen> in the C<pvn> form), returning that value as a mortal
204 scalar copy, or C<&PL_sv_placeholder> if there is no value associated with the
207 The forms differ in how the key is specified.
208 In the plain C<pv> form, the key is a C language NUL-terminated string.
209 In the C<pvs> form, the key is a C language string literal.
210 In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of
211 the string, which hence, may contain embedded-NUL characters.
212 In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that.
213 using C<L</SvPV_const>>.
215 C<hash> is a precomputed hash of the key string, or zero if it has not been
216 precomputed. This parameter is omitted from the C<pvs> form, as it is computed
217 automatically at compile time.
219 The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>.
220 It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies
221 whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if
222 cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of
225 =for apidoc Amnh||COPHH_KEY_UTF8
231 #define cophh_fetch_pvn(cophh, key, keylen, hash, flags) \
232 Perl_refcounted_he_fetch_pvn(aTHX_ cophh, key, keylen, hash, \
233 (flags & COPHH_KEY_UTF8))
235 #define cophh_fetch_pvs(cophh, key, flags) \
236 Perl_refcounted_he_fetch_pvn(aTHX_ cophh, STR_WITH_LEN(key), 0, \
237 (flags & COPHH_KEY_UTF8))
239 #define cophh_fetch_pv(cophh, key, hash, flags) \
240 Perl_refcounted_he_fetch_pv(aTHX_ cophh, key, hash, \
241 (flags & COPHH_KEY_UTF8))
243 #define cophh_fetch_sv(cophh, key, hash, flags) \
244 Perl_refcounted_he_fetch_sv(aTHX_ cophh, key, hash, \
245 (flags & COPHH_KEY_UTF8))
248 =for apidoc Amx|bool|cophh_exists_pvn|const COPHH *cophh|const char *key|STRLEN keylen|U32 hash|U32 flags
250 These look up the hint entry in the cop C<cop> with the key specified by
251 C<key> (and C<keylen> in the C<pvn> form), returning true if a value exists,
254 The forms differ in how the key is specified.
255 In the plain C<pv> form, the key is a C language NUL-terminated string.
256 In the C<pvs> form, the key is a C language string literal.
257 In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of
258 the string, which hence, may contain embedded-NUL characters.
259 In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that.
260 using C<L</SvPV_const>>.
262 C<hash> is a precomputed hash of the key string, or zero if it has not been
263 precomputed. This parameter is omitted from the C<pvs> form, as it is computed
264 automatically at compile time.
266 The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>.
267 It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies
268 whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if
269 cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of
275 #define cophh_exists_pvn(cophh, key, keylen, hash, flags) \
276 cBOOL(Perl_refcounted_he_fetch_pvn(aTHX_ cophh, key, keylen, hash, flags | COPHH_EXISTS))
278 #define cophh_exists_pvs(cophh, key, flags) \
279 cBOOL(Perl_refcounted_he_fetch_pvn(aTHX_ cophh, STR_WITH_LEN(key), 0, flags | COPHH_EXISTS))
281 #define cophh_exists_pv(cophh, key, hash, flags) \
282 cBOOL(Perl_refcounted_he_fetch_pv(aTHX_ cophh, key, hash, flags | COPHH_EXISTS))
284 #define cophh_exists_sv(cophh, key, hash, flags) \
285 cBOOL(Perl_refcounted_he_fetch_sv(aTHX_ cophh, key, hash, flags | COPHH_EXISTS))
288 =for apidoc Amx|HV *|cophh_2hv|const COPHH *cophh|U32 flags
290 Generates and returns a standard Perl hash representing the full set of
291 key/value pairs in the cop hints hash C<cophh>. C<flags> is currently
292 unused and must be zero.
297 #define cophh_2hv(cophh, flags) \
298 Perl_refcounted_he_chain_2hv(aTHX_ cophh, flags)
301 =for apidoc Amx|COPHH *|cophh_copy|COPHH *cophh
303 Make and return a complete copy of the cop hints hash C<cophh>.
308 #define cophh_copy(cophh) Perl_refcounted_he_inc(aTHX_ cophh)
311 =for apidoc Amx|void|cophh_free|COPHH *cophh
313 Discard the cop hints hash C<cophh>, freeing all resources associated
319 #define cophh_free(cophh) Perl_refcounted_he_free(aTHX_ cophh)
322 =for apidoc Amx|COPHH *|cophh_new_empty
324 Generate and return a fresh cop hints hash containing no entries.
329 #define cophh_new_empty() ((COPHH *)NULL)
332 =for apidoc Amx|COPHH *|cophh_store_pv |COPHH *cophh|const char *key |U32 hash|SV *value|U32 flags
333 =for apidoc_item|COPHH *|cophh_store_pvn|COPHH *cophh|const char *key|STRLEN keylen|U32 hash|SV *value|U32 flags
334 =for apidoc_item|COPHH *|cophh_store_pvs|COPHH *cophh| "key" |SV *value|U32 flags
335 =for apidoc_item|COPHH *|cophh_store_sv |COPHH *cophh| SV *key |U32 hash|SV *value|U32 flags
337 These store a value, associated with a key, in the cop hints hash C<cophh>,
338 and return the modified hash. The returned hash pointer is in general
339 not the same as the hash pointer that was passed in. The input hash is
340 consumed by the function, and the pointer to it must not be subsequently
341 used. Use L</cophh_copy> if you need both hashes.
343 C<value> is the scalar value to store for this key. C<value> is copied
344 by these functions, which thus do not take ownership of any reference
345 to it, and hence later changes to the scalar will not be reflected in the value
346 visible in the cop hints hash. Complex types of scalar will not be stored with
347 referential integrity, but will be coerced to strings.
349 The forms differ in how the key is specified. In all forms, the key is pointed
351 In the plain C<pv> form, the key is a C language NUL-terminated string.
352 In the C<pvs> form, the key is a C language string literal.
353 In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of
354 the string, which hence, may contain embedded-NUL characters.
355 In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that.
356 using C<L</SvPV_const>>.
358 C<hash> is a precomputed hash of the key string, or zero if it has not been
359 precomputed. This parameter is omitted from the C<pvs> form, as it is computed
360 automatically at compile time.
362 The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>.
363 It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies
364 whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if
365 cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of
371 #define cophh_store_pvn(cophh, key, keylen, hash, value, flags) \
372 Perl_refcounted_he_new_pvn(aTHX_ cophh, key, keylen, hash, value, flags)
374 #define cophh_store_pvs(cophh, key, value, flags) \
375 Perl_refcounted_he_new_pvn(aTHX_ cophh, STR_WITH_LEN(key), 0, value, flags)
377 #define cophh_store_pv(cophh, key, hash, value, flags) \
378 Perl_refcounted_he_new_pv(aTHX_ cophh, key, hash, value, flags)
380 #define cophh_store_sv(cophh, key, hash, value, flags) \
381 Perl_refcounted_he_new_sv(aTHX_ cophh, key, hash, value, flags)
384 =for apidoc Amx|COPHH *|cophh_delete_pv |COPHH *cophh|const char *key |U32 hash|U32 flags
385 =for apidoc_item|COPHH *|cophh_delete_pvn|COPHH *cophh|const char *key|STRLEN keylen|U32 hash|U32 flags
386 =for apidoc_item|COPHH *|cophh_delete_pvs|COPHH *cophh| "key" |U32 flags
387 =for apidoc_item|COPHH *|cophh_delete_sv |COPHH *cophh| SV *key |U32 hash|U32 flags
389 These delete a key and its associated value from the cop hints hash C<cophh>,
390 and return the modified hash. The returned hash pointer is in general
391 not the same as the hash pointer that was passed in. The input hash is
392 consumed by the function, and the pointer to it must not be subsequently
393 used. Use L</cophh_copy> if you need both hashes.
395 The forms differ in how the key is specified. In all forms, the key is pointed
397 In the plain C<pv> form, the key is a C language NUL-terminated string.
398 In the C<pvs> form, the key is a C language string literal.
399 In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of
400 the string, which hence, may contain embedded-NUL characters.
401 In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that.
402 using C<L</SvPV_const>>.
404 C<hash> is a precomputed hash of the key string, or zero if it has not been
405 precomputed. This parameter is omitted from the C<pvs> form, as it is computed
406 automatically at compile time.
408 The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>.
409 It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies
410 whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if
411 cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of
417 #define cophh_delete_pvn(cophh, key, keylen, hash, flags) \
418 Perl_refcounted_he_new_pvn(aTHX_ cophh, key, keylen, hash, \
421 #define cophh_delete_pvs(cophh, key, flags) \
422 Perl_refcounted_he_new_pvn(aTHX_ cophh, STR_WITH_LEN(key), 0, \
425 #define cophh_delete_pv(cophh, key, hash, flags) \
426 Perl_refcounted_he_new_pv(aTHX_ cophh, key, hash, (SV *)NULL, flags)
428 #define cophh_delete_sv(cophh, key, hash, flags) \
429 Perl_refcounted_he_new_sv(aTHX_ cophh, key, hash, (SV *)NULL, flags)
431 #include "mydtrace.h"
435 /* On LP64 putting this here takes advantage of the fact that BASEOP isn't
436 an exact multiple of 8 bytes to save structure padding. */
437 line_t cop_line; /* line # of this command */
438 /* label for this construct is now stored in cop_hints_hash */
440 PADOFFSET cop_stashoff; /* offset into PL_stashpad, for the
441 package the line was compiled in */
442 char * cop_file; /* name of file this command is from */
444 HV * cop_stash; /* package line was compiled in */
445 GV * cop_filegv; /* name of GV file this command is from */
447 U32 cop_hints; /* hints bits from pragmata */
448 U32 cop_seq; /* parse sequence number */
449 /* Beware. mg.c and warnings.pl assume the type of this is STRLEN *: */
450 STRLEN * cop_warnings; /* lexical warnings bitmask */
451 /* compile time state of %^H. See the comment in op.c for how this is
452 used to recreate a hash to return from caller. */
453 COPHH * cop_hints_hash;
454 /* for now just a bitmask stored here.
455 If we get sufficient features this may become a pointer.
456 How these flags are stored is subject to change without
457 notice. Use the macros to test for features.
463 =for apidoc Am|const char *|CopFILE|const COP * c
464 Returns the name of the file associated with the C<COP> C<c>
466 =for apidoc Am|line_t|CopLINE|const COP * c
467 Returns the line number in the source code associated with the C<COP> C<c>
469 =for apidoc Am|AV *|CopFILEAV|const COP * c
470 Returns the AV associated with the C<COP> C<c>, creating it if necessary.
472 =for apidoc Am|AV *|CopFILEAVn|const COP * c
473 Returns the AV associated with the C<COP> C<c>, returning NULL if it
474 doesn't already exist.
476 =for apidoc Am|SV *|CopFILESV|const COP * c
477 Returns the SV associated with the C<COP> C<c>
479 =for apidoc Am|void|CopFILE_set|COP * c|const char * pv
480 Makes C<pv> the name of the file associated with the C<COP> C<c>
482 =for apidoc Am|GV *|CopFILEGV|const COP * c
483 Returns the GV associated with the C<COP> C<c>
485 =for apidoc CopFILEGV_set
486 Available only on unthreaded perls. Makes C<pv> the name of the file
487 associated with the C<COP> C<c>
489 =for apidoc Am|HV *|CopSTASH|const COP * c
490 Returns the stash associated with C<c>.
492 =for apidoc Am|bool|CopSTASH_eq|const COP * c|const HV * hv
493 Returns a boolean as to whether or not C<hv> is the stash associated with C<c>.
495 =for apidoc Am|bool|CopSTASH_set|COP * c|HV * hv
496 Set the stash associated with C<c> to C<hv>.
498 =for apidoc Am|char *|CopSTASHPV|const COP * c
499 Returns the package name of the stash associated with C<c>, or C<NULL> if no
502 =for apidoc Am|void|CopSTASHPV_set|COP * c|const char * pv
503 Set the package name of the stash associated with C<c>, to the NUL-terminated C
504 string C<p>, creating the package if necessary.
511 # define CopFILE(c) ((c)->cop_file)
512 # define CopFILEGV(c) (CopFILE(c) \
513 ? gv_fetchfile(CopFILE(c)) : NULL)
515 # define CopFILE_set(c,pv) ((c)->cop_file = savesharedpv(pv))
516 # define CopFILE_setn(c,pv,l) ((c)->cop_file = savesharedpvn((pv),(l)))
518 # define CopFILESV(c) (CopFILE(c) \
519 ? GvSV(gv_fetchfile(CopFILE(c))) : NULL)
520 # define CopFILEAV(c) (CopFILE(c) \
521 ? GvAV(gv_fetchfile(CopFILE(c))) : NULL)
522 # define CopFILEAVx(c) (assert_(CopFILE(c)) \
523 GvAV(gv_fetchfile(CopFILE(c))))
524 # define CopFILEAVn(c) (cop_file_avn(c))
525 # define CopSTASH(c) PL_stashpad[(c)->cop_stashoff]
526 # define CopSTASH_set(c,hv) ((c)->cop_stashoff = (hv) \
527 ? alloccopstash(hv) \
529 # define CopFILE_free(c) (PerlMemShared_free(CopFILE(c)),(CopFILE(c) = NULL))
531 #else /* Above: yes threads; Below no threads */
533 # define CopFILEGV(c) ((c)->cop_filegv)
534 # define CopFILEGV_set(c,gv) ((c)->cop_filegv = (GV*)SvREFCNT_inc(gv))
535 # define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv))
536 # define CopFILE_setn(c,pv,l) CopFILEGV_set((c), gv_fetchfile_flags((pv),(l),0))
537 # define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : NULL)
538 # define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : NULL)
540 # define CopFILEAVx(c) (assert(CopFILEGV(c)), GvAV(CopFILEGV(c)))
542 # define CopFILEAVx(c) (GvAV(CopFILEGV(c)))
544 # define CopFILEAVn(c) (CopFILEGV(c) ? GvAVn(CopFILEGV(c)) : NULL)
545 # define CopFILE(c) (CopFILEGV(c) /* +2 for '_<' */ \
546 ? GvNAME(CopFILEGV(c))+2 : NULL)
547 # define CopSTASH(c) ((c)->cop_stash)
548 # define CopSTASH_set(c,hv) ((c)->cop_stash = (hv))
549 # define CopFILE_free(c) (SvREFCNT_dec(CopFILEGV(c)),(CopFILEGV(c) = NULL))
551 #endif /* USE_ITHREADS */
553 #define CopSTASHPV(c) (CopSTASH(c) ? HvNAME_get(CopSTASH(c)) : NULL)
554 /* cop_stash is not refcounted */
555 #define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD))
556 #define CopSTASH_eq(c,hv) (CopSTASH(c) == (hv))
558 #define CopHINTHASH_get(c) ((COPHH*)((c)->cop_hints_hash))
559 #define CopHINTHASH_set(c,h) ((c)->cop_hints_hash = (h))
562 =for apidoc Am|SV *|cop_hints_fetch_pv |const COP *cop|const char *key |U32 hash|U32 flags
563 =for apidoc_item|SV *|cop_hints_fetch_pvn|const COP *cop|const char *key|STRLEN keylen|U32 hash|U32 flags
564 =for apidoc_item|SV *|cop_hints_fetch_pvs|const COP *cop| "key" |U32 flags
565 =for apidoc_item|SV *|cop_hints_fetch_sv |const COP *cop| SV *key |U32 hash|U32 flags
567 These look up the hint entry in the cop C<cop> with the key specified by
568 C<key> (and C<keylen> in the C<pvn> form), returning that value as a mortal
569 scalar copy, or C<&PL_sv_placeholder> if there is no value associated with the
572 The forms differ in how the key is specified.
573 In the plain C<pv> form, the key is a C language NUL-terminated string.
574 In the C<pvs> form, the key is a C language string literal.
575 In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of
576 the string, which hence, may contain embedded-NUL characters.
577 In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that.
578 using C<L</SvPV_const>>.
580 C<hash> is a precomputed hash of the key string, or zero if it has not been
581 precomputed. This parameter is omitted from the C<pvs> form, as it is computed
582 automatically at compile time.
584 The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>.
585 It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies
586 whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if
587 cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of
593 #define cop_hints_fetch_pvn(cop, key, keylen, hash, flags) \
594 cophh_fetch_pvn(CopHINTHASH_get(cop), key, keylen, hash, flags)
596 #define cop_hints_fetch_pvs(cop, key, flags) \
597 cophh_fetch_pvs(CopHINTHASH_get(cop), key, flags)
599 #define cop_hints_fetch_pv(cop, key, hash, flags) \
600 cophh_fetch_pv(CopHINTHASH_get(cop), key, hash, flags)
602 #define cop_hints_fetch_sv(cop, key, hash, flags) \
603 cophh_fetch_sv(CopHINTHASH_get(cop), key, hash, flags)
606 =for apidoc Am|bool|cop_hints_exists_pv |const COP *cop|const char *key|U32 hash |U32 flags
607 =for apidoc_item|bool|cop_hints_exists_pvn|const COP *cop|const char *key|STRLEN keylen|U32 hash|U32 flags
608 =for apidoc_item|bool|cop_hints_exists_pvs|const COP *cop| "key" |U32 flags
609 =for apidoc_item|bool|cop_hints_exists_sv |const COP *cop| SV *key |U32 hash|U32 flags
611 These look up the hint entry in the cop C<cop> with the key specified by
612 C<key> (and C<keylen> in the C<pvn> form), returning true if a value exists,
615 The forms differ in how the key is specified. In all forms, the key is pointed
617 In the plain C<pv> form, the key is a C language NUL-terminated string.
618 In the C<pvs> form, the key is a C language string literal.
619 In the C<pvn> form, an additional parameter, C<keylen>, specifies the length of
620 the string, which hence, may contain embedded-NUL characters.
621 In the C<sv> form, C<*key> is an SV, and the key is the PV extracted from that.
622 using C<L</SvPV_const>>.
624 C<hash> is a precomputed hash of the key string, or zero if it has not been
625 precomputed. This parameter is omitted from the C<pvs> form, as it is computed
626 automatically at compile time.
628 The only flag currently used from the C<flags> parameter is C<COPHH_KEY_UTF8>.
629 It is illegal to set this in the C<sv> form. In the C<pv*> forms, it specifies
630 whether the key octets are interpreted as UTF-8 (if set) or as Latin-1 (if
631 cleared). The C<sv> form uses the underlying SV to determine the UTF-8ness of
637 #define cop_hints_exists_pvn(cop, key, keylen, hash, flags) \
638 cophh_exists_pvn(CopHINTHASH_get(cop), key, keylen, hash, flags)
640 #define cop_hints_exists_pvs(cop, key, flags) \
641 cophh_exists_pvs(CopHINTHASH_get(cop), key, flags)
643 #define cop_hints_exists_pv(cop, key, hash, flags) \
644 cophh_exists_pv(CopHINTHASH_get(cop), key, hash, flags)
646 #define cop_hints_exists_sv(cop, key, hash, flags) \
647 cophh_exists_sv(CopHINTHASH_get(cop), key, hash, flags)
650 =for apidoc Am|HV *|cop_hints_2hv|const COP *cop|U32 flags
652 Generates and returns a standard Perl hash representing the full set of
653 hint entries in the cop C<cop>. C<flags> is currently unused and must
659 #define cop_hints_2hv(cop, flags) \
660 cophh_2hv(CopHINTHASH_get(cop), flags)
663 =for apidoc Am|const char *|CopLABEL |COP *const cop
664 =for apidoc_item|const char *|CopLABEL_len |COP *const cop|STRLEN *len
665 =for apidoc_item|const char *|CopLABEL_len_flags|COP *const cop|STRLEN *len|U32 *flags
667 These return the label attached to a cop.
669 C<CopLABEL_len> and C<CopLABEL_len_flags> additionally store the number of
670 bytes comprising the returned label into C<*len>.
672 C<CopLABEL_len_flags> additionally returns the UTF-8ness of the returned label,
673 by setting C<*flags> to 0 or C<SVf_UTF8>.
678 #define CopLABEL(c) Perl_cop_fetch_label(aTHX_ (c), NULL, NULL)
679 #define CopLABEL_len(c,len) Perl_cop_fetch_label(aTHX_ (c), len, NULL)
680 #define CopLABEL_len_flags(c,len,flags) Perl_cop_fetch_label(aTHX_ (c), len, flags)
681 #define CopLABEL_alloc(pv) ((pv)?savepv(pv):NULL)
683 #define CopSTASH_ne(c,hv) (!CopSTASH_eq(c,hv))
684 #define CopLINE(c) ((c)->cop_line)
685 #define CopLINE_inc(c) (++CopLINE(c))
686 #define CopLINE_dec(c) (--CopLINE(c))
687 #define CopLINE_set(c,l) (CopLINE(c) = (l))
689 /* OutCopFILE() is CopFILE for output (caller, die, warn, etc.) */
690 #define OutCopFILE(c) CopFILE(c)
692 #define CopHINTS_get(c) ((c)->cop_hints + 0)
693 #define CopHINTS_set(c, h) STMT_START { \
694 (c)->cop_hints = (h); \
698 * Here we have some enormously heavy (or at least ponderous) wizardry.
701 /* subroutine context */
703 OP * retop; /* op to execute on exit from sub */
704 I32 old_cxsubix; /* previous value of si_cxsubix */
705 /* Above here is the same for sub, format and eval. */
706 PAD *prevcomppad; /* the caller's PL_comppad */
708 /* Above here is the same for sub and format. */
715 struct block_format {
716 OP * retop; /* op to execute on exit from sub */
717 I32 old_cxsubix; /* previous value of si_cxsubix */
718 /* Above here is the same for sub, format and eval. */
719 PAD *prevcomppad; /* the caller's PL_comppad */
721 /* Above here is the same for sub and format. */
726 /* return a pointer to the current context */
728 #define CX_CUR() (&cxstack[cxstack_ix])
730 /* free all savestack items back to the watermark of the specified context */
732 #define CX_LEAVE_SCOPE(cx) LEAVE_SCOPE(cx->blk_oldsaveix)
735 /* on debugging builds, poison cx afterwards so we know no code
736 * uses it - because after doing cxstack_ix--, any ties, exceptions etc
737 * may overwrite the current stack frame */
738 # define CX_POP(cx) \
739 assert(CX_CUR() == cx); \
743 # define CX_POP(cx) cxstack_ix--;
746 #define CX_PUSHSUB_GET_LVALUE_MASK(func) \
747 /* If the context is indeterminate, then only the lvalue */ \
748 /* flags that the caller also has are applicable. */ \
750 (PL_op->op_flags & OPf_WANT) \
751 ? OPpENTERSUB_LVAL_MASK \
752 : !(PL_op->op_private & OPpENTERSUB_LVAL_MASK) \
753 ? 0 : (U8)func(aTHX) \
757 #define CX_POP_SAVEARRAY(cx) \
759 AV *cx_pop_savearray_av = GvAV(PL_defgv); \
760 GvAV(PL_defgv) = cx->blk_sub.savearray; \
761 cx->blk_sub.savearray = NULL; \
762 SvREFCNT_dec(cx_pop_savearray_av); \
765 /* junk in @_ spells trouble when cloning CVs and in pp_caller(), so don't
766 * leave any (a fast av_clear(ary), basically) */
767 #define CLEAR_ARGARRAY(ary) \
769 AvMAX(ary) += AvARRAY(ary) - AvALLOC(ary); \
770 AvARRAY(ary) = AvALLOC(ary); \
777 OP * retop; /* op to execute on exit from eval */
778 I32 old_cxsubix; /* previous value of si_cxsubix */
779 /* Above here is the same for sub, format and eval. */
784 JMPENV * cur_top_env; /* value of PL_top_env when eval CX created */
787 /* If we ever need more than 512 op types, change the shift from 7.
788 blku_gimme is actually also only 2 bits, so could be merged with something.
791 /* blk_u16 bit usage for eval contexts: */
793 #define CxOLD_IN_EVAL(cx) (((cx)->blk_u16) & 0x3F) /* saved PL in_eval */
794 #define CxEVAL_TXT_REFCNTED(cx) (((cx)->blk_u16) & 0x40) /* cur_text rc++ */
795 #define CxOLD_OP_TYPE(cx) (((cx)->blk_u16) >> 7) /* type of eval op */
799 LOOP * my_op; /* My op, that contains redo, next and last ops. */
800 union { /* different ways of locating the iteration variable */
801 SV **svp; /* for lexicals: address of pad slot */
802 GV *gv; /* for package vars */
804 SV *itersave; /* the original iteration var */
806 struct { /* CXt_LOOP_ARY, C<for (@ary)> */
807 AV *ary; /* array being iterated over */
808 IV ix; /* index relative to base of array */
810 struct { /* CXt_LOOP_LIST, C<for (list)> */
811 I32 basesp; /* first element of list on stack */
812 IV ix; /* index relative to basesp */
814 struct { /* CXt_LOOP_LAZYIV, C<for (1..9)> */
818 struct { /* CXt_LOOP_LAZYSV C<for ('a'..'z')> */
820 SV * end; /* maxiumum value (or minimum in reverse) */
824 PAD *oldcomppad; /* needed to map itervar_u.svp during thread clone */
828 #define CxITERVAR(c) \
830 ? (c)->blk_loop.itervar_u.svp \
831 : ((c)->cx_type & CXp_FOR_GV) \
832 ? &GvSV((c)->blk_loop.itervar_u.gv) \
833 : (SV **)&(c)->blk_loop.itervar_u.gv)
835 #define CxLABEL(c) (CopLABEL((c)->blk_oldcop))
836 #define CxLABEL_len(c,len) (CopLABEL_len((c)->blk_oldcop, len))
837 #define CxLABEL_len_flags(c,len,flags) ((const char *)CopLABEL_len_flags((c)->blk_oldcop, len, flags))
838 #define CxHASARGS(c) (((c)->cx_type & CXp_HASARGS) == CXp_HASARGS)
840 /* CxLVAL(): the lval flags of the call site: the relevant flag bits from
841 * the op_private field of the calling pp_entersub (or its caller's caller
842 * if the caller's lvalue context isn't known):
843 * OPpLVAL_INTRO: sub used in lvalue context, e.g. f() = 1;
844 * OPpENTERSUB_INARGS (in conjunction with OPpLVAL_INTRO): the
845 * function is being used as a sub arg or as a referent, e.g.
846 * g(...,f(),...) or $r = \f()
847 * OPpDEREF: 2-bit mask indicating e.g. f()->[0].
848 * Note the contrast with CvLVALUE(), which is a property of the sub
849 * rather than the call site.
851 #define CxLVAL(c) (0 + ((U8)((c)->blk_u16)))
855 /* given/when context */
856 struct block_givwhen {
858 SV *defsv_save; /* the original $_ */
863 /* context common to subroutines, evals and loops */
865 U8 blku_type; /* what kind of context this is */
866 U8 blku_gimme; /* is this block running in list context? */
867 U16 blku_u16; /* used by block_sub and block_eval (so far) */
868 I32 blku_oldsaveix; /* saved PL_savestack_ix */
869 /* all the fields above must be aligned with same-sized fields as sbu */
870 I32 blku_oldsp; /* current sp floor: where nextstate pops to */
871 I32 blku_oldmarksp; /* mark stack index */
872 COP * blku_oldcop; /* old curcop pointer */
873 PMOP * blku_oldpm; /* values of pattern match vars */
874 SSize_t blku_old_tmpsfloor; /* saved PL_tmps_floor */
875 I32 blku_oldscopesp; /* scope stack index */
878 struct block_sub blku_sub;
879 struct block_format blku_format;
880 struct block_eval blku_eval;
881 struct block_loop blku_loop;
882 struct block_givwhen blku_givwhen;
885 #define blk_oldsp cx_u.cx_blk.blku_oldsp
886 #define blk_oldcop cx_u.cx_blk.blku_oldcop
887 #define blk_oldmarksp cx_u.cx_blk.blku_oldmarksp
888 #define blk_oldscopesp cx_u.cx_blk.blku_oldscopesp
889 #define blk_oldpm cx_u.cx_blk.blku_oldpm
890 #define blk_gimme cx_u.cx_blk.blku_gimme
891 #define blk_u16 cx_u.cx_blk.blku_u16
892 #define blk_oldsaveix cx_u.cx_blk.blku_oldsaveix
893 #define blk_old_tmpsfloor cx_u.cx_blk.blku_old_tmpsfloor
894 #define blk_sub cx_u.cx_blk.blk_u.blku_sub
895 #define blk_format cx_u.cx_blk.blk_u.blku_format
896 #define blk_eval cx_u.cx_blk.blk_u.blku_eval
897 #define blk_loop cx_u.cx_blk.blk_u.blku_loop
898 #define blk_givwhen cx_u.cx_blk.blk_u.blku_givwhen
900 #define CX_DEBUG(cx, action) \
902 Perl_deb(aTHX_ "CX %ld %s %s (scope %ld,%ld) (save %ld,%ld) in %s at %s:%d\n",\
905 PL_block_type[CxTYPE(cx)], \
906 (long)PL_scopestack_ix, \
907 (long)(cx->blk_oldscopesp), \
908 (long)PL_savestack_ix, \
909 (long)(cx->blk_oldsaveix), \
910 SAFE_FUNCTION__, __FILE__, __LINE__));
914 /* substitution context */
916 U8 sbu_type; /* same as blku_type */
919 I32 sbu_oldsaveix; /* same as blku_oldsaveix */
920 /* all the fields above must be aligned with same-sized fields as blk_u */
922 SSize_t sbu_maxiters;
935 #define sb_iters cx_u.cx_subst.sbu_iters
936 #define sb_maxiters cx_u.cx_subst.sbu_maxiters
937 #define sb_rflags cx_u.cx_subst.sbu_rflags
938 #define sb_rxtainted cx_u.cx_subst.sbu_rxtainted
939 #define sb_orig cx_u.cx_subst.sbu_orig
940 #define sb_dstr cx_u.cx_subst.sbu_dstr
941 #define sb_targ cx_u.cx_subst.sbu_targ
942 #define sb_s cx_u.cx_subst.sbu_s
943 #define sb_m cx_u.cx_subst.sbu_m
944 #define sb_strend cx_u.cx_subst.sbu_strend
945 #define sb_rxres cx_u.cx_subst.sbu_rxres
946 #define sb_rx cx_u.cx_subst.sbu_rx
948 # define CX_PUSHSUBST(cx) CXINC, cx = CX_CUR(), \
949 cx->blk_oldsaveix = oldsave, \
950 cx->sb_iters = iters, \
951 cx->sb_maxiters = maxiters, \
952 cx->sb_rflags = r_flags, \
953 cx->sb_rxtainted = rxtainted, \
954 cx->sb_orig = orig, \
955 cx->sb_dstr = dstr, \
956 cx->sb_targ = targ, \
959 cx->sb_strend = strend, \
960 cx->sb_rxres = NULL, \
962 cx->cx_type = CXt_SUBST | (once ? CXp_ONCE : 0); \
963 rxres_save(&cx->sb_rxres, rx); \
964 (void)ReREFCNT_inc(rx); \
965 SvREFCNT_inc_void_NN(targ)
967 # define CX_POPSUBST(cx) \
970 assert(CxTYPE(cx) == CXt_SUBST); \
971 rxres_free(&cx->sb_rxres); \
975 SvREFCNT_dec_NN(cx->sb_targ); \
979 #define CxONCE(cx) ((cx)->cx_type & CXp_ONCE)
984 struct subst cx_subst;
987 #define cx_type cx_u.cx_subst.sbu_type
989 /* If you re-order these, there is also an array of uppercase names in perl.h
990 and a static array of context names in pp_ctl.c */
991 #define CXTYPEMASK 0xf
992 #define CXt_NULL 0 /* currently only used for sort BLOCK */
995 /* When micro-optimising :-) keep GIVEN next to the LOOPs, as these 5 share a
996 jump table in pp_ctl.c
997 The first 4 don't have a 'case' in at least one switch statement in pp_ctl.c
1001 /* be careful of the ordering of these five. Macros like CxTYPE_is_LOOP,
1002 * CxFOREACH compare ranges */
1003 #define CXt_LOOP_ARY 4 /* for (@ary) { ...; } */
1004 #define CXt_LOOP_LAZYSV 5 /* for ('a'..'z') { ...; } */
1005 #define CXt_LOOP_LAZYIV 6 /* for (1..9) { ...; } */
1006 #define CXt_LOOP_LIST 7 /* for (1,2,3) { ...; } */
1007 #define CXt_LOOP_PLAIN 8 /* while (...) { ...; }
1008 or plain block { ...; } */
1010 #define CXt_FORMAT 10
1011 #define CXt_EVAL 11 /* eval'', eval{}, try{} */
1012 #define CXt_SUBST 12
1013 #define CXt_DEFER 13
1014 /* SUBST doesn't feature in all switch statements. */
1016 /* private flags for CXt_SUB and CXt_FORMAT */
1017 #define CXp_MULTICALL 0x10 /* part of a multicall (so don't tear down
1018 context on exit). (not CXt_FORMAT) */
1019 #define CXp_HASARGS 0x20
1020 #define CXp_SUB_RE 0x40 /* code called within regex, i.e. (?{}) */
1021 #define CXp_SUB_RE_FAKE 0x80 /* fake sub CX for (?{}) in current scope */
1023 /* private flags for CXt_EVAL */
1024 #define CXp_REAL 0x20 /* truly eval'', not a lookalike */
1025 #define CXp_EVALBLOCK 0x40 /* eval{}, not eval'' or similar */
1026 #define CXp_TRY 0x80 /* try {} block */
1028 /* private flags for CXt_LOOP */
1030 /* this is only set in conjunction with CXp_FOR_GV */
1031 #define CXp_FOR_DEF 0x10 /* foreach using $_ */
1032 /* these 3 are mutually exclusive */
1033 #define CXp_FOR_LVREF 0x20 /* foreach using \$var */
1034 #define CXp_FOR_GV 0x40 /* foreach using package var */
1035 #define CXp_FOR_PAD 0x80 /* foreach using lexical var */
1037 #define CxPADLOOP(c) ((c)->cx_type & CXp_FOR_PAD)
1039 /* private flags for CXt_SUBST */
1040 #define CXp_ONCE 0x10 /* What was sbu_once in struct subst */
1042 #define CxTYPE(c) ((c)->cx_type & CXTYPEMASK)
1043 #define CxTYPE_is_LOOP(c) ( CxTYPE(cx) >= CXt_LOOP_ARY \
1044 && CxTYPE(cx) <= CXt_LOOP_PLAIN)
1045 #define CxMULTICALL(c) ((c)->cx_type & CXp_MULTICALL)
1046 #define CxREALEVAL(c) (((c)->cx_type & (CXTYPEMASK|CXp_REAL)) \
1047 == (CXt_EVAL|CXp_REAL))
1048 #define CxEVALBLOCK(c) (((c)->cx_type & (CXTYPEMASK|CXp_EVALBLOCK)) \
1049 == (CXt_EVAL|CXp_EVALBLOCK))
1050 #define CxTRY(c) (((c)->cx_type & (CXTYPEMASK|CXp_TRY)) \
1051 == (CXt_EVAL|CXp_TRY))
1052 #define CxFOREACH(c) ( CxTYPE(cx) >= CXt_LOOP_ARY \
1053 && CxTYPE(cx) <= CXt_LOOP_LIST)
1055 /* private flags for CXt_DEFER */
1056 #define CXp_FINALLY 0x20 /* `finally` block; semantically identical
1057 * but matters for diagnostic messages */
1059 /* deprecated old name before real try/catch was added */
1060 #define CXp_TRYBLOCK CXp_EVALBLOCK
1061 #define CxTRYBLOCK(c) CxEVALBLOCK(c)
1063 #define CXINC (cxstack_ix < cxstack_max ? ++cxstack_ix : (cxstack_ix = cxinc()))
1071 /* name prior to 5.31.1 */
1072 # define G_ARRAY G_LIST
1075 /* extra flags for Perl_call_* routines */
1076 #define G_DISCARD 0x4 /* Call FREETMPS.
1077 Don't change this without consulting the
1078 hash actions codes defined in hv.h */
1079 #define G_EVAL 0x8 /* Assume eval {} around subroutine call. */
1080 #define G_NOARGS 0x10 /* Don't construct a @_ array. */
1081 #define G_KEEPERR 0x20 /* Warn for errors, don't overwrite $@ */
1082 #define G_NODEBUG 0x40 /* Disable debugging at toplevel. */
1083 #define G_METHOD 0x80 /* Calling method. */
1084 #define G_FAKINGEVAL 0x100 /* Faking an eval context for call_sv or
1086 #define G_UNDEF_FILL 0x200 /* Fill the stack with &PL_sv_undef
1087 A special case for UNSHIFT in
1088 Perl_magic_methcall(). */
1089 #define G_WRITING_TO_STDERR 0x400 /* Perl_write_to_stderr() is calling
1090 Perl_magic_methcall(). */
1091 #define G_RE_REPARSING 0x800 /* compiling a run-time /(?{..})/ */
1092 #define G_METHOD_NAMED 0x1000 /* calling named method, eg without :: or ' */
1093 #define G_RETHROW 0x2000 /* eval_sv(): re-throw any error */
1095 /* flag bits for PL_in_eval */
1096 #define EVAL_NULL 0 /* not in an eval */
1097 #define EVAL_INEVAL 1 /* some enclosing scope is an eval */
1098 #define EVAL_WARNONLY 2 /* used by yywarn() when calling yyerror() */
1099 #define EVAL_KEEPERR 4 /* set by Perl_call_sv if G_KEEPERR */
1100 #define EVAL_INREQUIRE 8 /* The code is being required. */
1101 #define EVAL_RE_REPARSING 0x10 /* eval_sv() called with G_RE_REPARSING */
1102 /* if adding extra bits, make sure they can fit in CxOLD_OP_TYPE() */
1104 /* Support for switching (stack and block) contexts.
1105 * This ensures magic doesn't invalidate local stack and cx pointers.
1106 * Which one to use (or add) is mostly, but not completely arbitrary: See
1107 * http://nntp.perl.org/group/perl.perl5.porters/257169
1110 #define PERLSI_UNKNOWN -1
1111 #define PERLSI_UNDEF 0
1112 #define PERLSI_MAIN 1
1113 #define PERLSI_MAGIC 2
1114 #define PERLSI_SORT 3
1115 #define PERLSI_SIGNAL 4
1116 #define PERLSI_OVERLOAD 5
1117 #define PERLSI_DESTROY 6
1118 #define PERLSI_WARNHOOK 7
1119 #define PERLSI_DIEHOOK 8
1120 #define PERLSI_REQUIRE 9
1121 #define PERLSI_MULTICALL 10
1122 #define PERLSI_REGCOMP 11
1125 AV * si_stack; /* stack for current runlevel */
1126 PERL_CONTEXT * si_cxstack; /* context stack for runlevel */
1127 struct stackinfo * si_prev;
1128 struct stackinfo * si_next;
1129 I32 si_cxix; /* current context index */
1130 I32 si_cxmax; /* maximum allocated index */
1131 I32 si_cxsubix; /* topmost sub/eval/format */
1132 I32 si_type; /* type of runlevel */
1133 I32 si_markoff; /* offset where markstack begins for us.
1134 * currently used only with DEBUGGING,
1135 * but not #ifdef-ed for bincompat */
1136 #if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
1137 /* high water mark: for checking if the stack was correctly extended /
1138 * tested for extension by each pp function */
1139 SSize_t si_stack_hwm;
1145 =for apidoc Ay||PERL_SI
1146 Use this typedef to declare variables that are to hold C<struct stackinfo>.
1150 typedef struct stackinfo PERL_SI;
1152 #define cxstack (PL_curstackinfo->si_cxstack)
1153 #define cxstack_ix (PL_curstackinfo->si_cxix)
1154 #define cxstack_max (PL_curstackinfo->si_cxmax)
1157 # define SET_MARK_OFFSET \
1158 PL_curstackinfo->si_markoff = PL_markstack_ptr - PL_markstack
1160 # define SET_MARK_OFFSET NOOP
1163 #if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
1164 # define PUSHSTACK_INIT_HWM(si) ((si)->si_stack_hwm = 0)
1166 # define PUSHSTACK_INIT_HWM(si) NOOP
1169 #define PUSHSTACKi(type) \
1171 PERL_SI *next = PL_curstackinfo->si_next; \
1173 int i = 0; PERL_SI *p = PL_curstackinfo; \
1174 while (p) { i++; p = p->si_prev; } \
1175 Perl_deb(aTHX_ "push STACKINFO %d in %s at %s:%d\n", \
1176 i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \
1178 next = new_stackinfo(32, 2048/sizeof(PERL_CONTEXT) - 1); \
1179 next->si_prev = PL_curstackinfo; \
1180 PL_curstackinfo->si_next = next; \
1182 next->si_type = type; \
1183 next->si_cxix = -1; \
1184 next->si_cxsubix = -1; \
1185 PUSHSTACK_INIT_HWM(next); \
1186 AvFILLp(next->si_stack) = 0; \
1187 SWITCHSTACK(PL_curstack,next->si_stack); \
1188 PL_curstackinfo = next; \
1192 #define PUSHSTACK PUSHSTACKi(PERLSI_UNKNOWN)
1194 /* POPSTACK works with PL_stack_sp, so it may need to be bracketed by
1195 * PUTBACK/SPAGAIN to flush/refresh any local SP that may be active */
1199 PERL_SI * const prev = PL_curstackinfo->si_prev; \
1201 int i = -1; PERL_SI *p = PL_curstackinfo; \
1202 while (p) { i++; p = p->si_prev; } \
1203 Perl_deb(aTHX_ "pop STACKINFO %d in %s at %s:%d\n", \
1204 i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \
1206 Perl_croak_popstack(); \
1208 SWITCHSTACK(PL_curstack,prev->si_stack); \
1209 /* don't free prev here, free them all at the END{} */ \
1210 PL_curstackinfo = prev; \
1213 #define POPSTACK_TO(s) \
1215 while (PL_curstack != s) { \
1222 =for apidoc_section $utility
1223 =for apidoc Amn|bool|IN_PERL_COMPILETIME
1224 Returns 1 if this macro is being called during the compilation phase of the
1225 program; otherwise 0;
1227 =for apidoc Amn|bool|IN_PERL_RUNTIME
1228 Returns 1 if this macro is being called during the execution phase of the
1229 program; otherwise 0;
1233 #define IN_PERL_COMPILETIME cBOOL(PL_curcop == &PL_compiling)
1234 #define IN_PERL_RUNTIME cBOOL(PL_curcop != &PL_compiling)
1237 =for apidoc_section $multicall
1239 =for apidoc Amn;||dMULTICALL
1240 Declare local variables for a multicall. See L<perlcall/LIGHTWEIGHT CALLBACKS>.
1242 =for apidoc Am;||PUSH_MULTICALL|CV* the_cv
1243 Opening bracket for a lightweight callback.
1244 See L<perlcall/LIGHTWEIGHT CALLBACKS>.
1246 =for apidoc Amn;||MULTICALL
1247 Make a lightweight callback. See L<perlcall/LIGHTWEIGHT CALLBACKS>.
1249 =for apidoc Amn;||POP_MULTICALL
1250 Closing bracket for a lightweight callback.
1251 See L<perlcall/LIGHTWEIGHT CALLBACKS>.
1256 #define dMULTICALL \
1257 OP *multicall_cop; \
1258 bool multicall_oldcatch
1260 #define PUSH_MULTICALL(the_cv) \
1261 PUSH_MULTICALL_FLAGS(the_cv, 0)
1263 /* Like PUSH_MULTICALL, but allows you to specify extra flags
1264 * for the CX stack entry (this isn't part of the public API) */
1266 #define PUSH_MULTICALL_FLAGS(the_cv, flags) \
1269 CV * const _nOnclAshIngNamE_ = the_cv; \
1270 CV * const cv = _nOnclAshIngNamE_; \
1271 PADLIST * const padlist = CvPADLIST(cv); \
1272 multicall_oldcatch = CATCH_GET; \
1274 PUSHSTACKi(PERLSI_MULTICALL); \
1275 cx = cx_pushblock((CXt_SUB|CXp_MULTICALL|flags), (U8)gimme, \
1276 PL_stack_sp, PL_savestack_ix); \
1277 cx_pushsub(cx, cv, NULL, 0); \
1279 if (!(flags & CXp_SUB_RE_FAKE)) \
1281 if (CvDEPTH(cv) >= 2) \
1282 Perl_pad_push(aTHX_ padlist, CvDEPTH(cv)); \
1283 PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv)); \
1284 multicall_cop = CvSTART(cv); \
1289 PL_op = multicall_cop; \
1293 #define POP_MULTICALL \
1297 CX_LEAVE_SCOPE(cx); \
1298 cx_popsub_common(cx); \
1299 gimme = cx->blk_gimme; \
1300 PERL_UNUSED_VAR(gimme); /* for API */ \
1304 CATCH_SET(multicall_oldcatch); \
1308 /* Change the CV of an already-pushed MULTICALL CxSUB block.
1309 * (this isn't part of the public API) */
1311 #define CHANGE_MULTICALL_FLAGS(the_cv, flags) \
1313 CV * const _nOnclAshIngNamE_ = the_cv; \
1314 CV * const cv = _nOnclAshIngNamE_; \
1315 PADLIST * const padlist = CvPADLIST(cv); \
1316 PERL_CONTEXT *cx = CX_CUR(); \
1317 assert(CxMULTICALL(cx)); \
1318 cx_popsub_common(cx); \
1319 cx->cx_type = (CXt_SUB|CXp_MULTICALL|flags); \
1320 cx_pushsub(cx, cv, NULL, 0); \
1321 if (!(flags & CXp_SUB_RE_FAKE)) \
1323 if (CvDEPTH(cv) >= 2) \
1324 Perl_pad_push(aTHX_ padlist, CvDEPTH(cv)); \
1325 PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv)); \
1326 multicall_cop = CvSTART(cv); \
1329 * ex: set ts=8 sts=4 sw=4 et: