3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 * 2002, 2003, 2004, 2005, 2006, 2007, 2008 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.
12 =for apidoc_section $rpp
14 =for apidoc Amux||XSPP_wrapped|xsppw_name|I32 xsppw_nargs|I32 xsppw_nlists
15 Declare and wrap a non-reference-counted PP-style function.
16 On traditional perl builds where the stack isn't reference-counted, this
17 just produces a function declaration like
21 Conversely, in ref-counted builds it creates xsppw_name() as a small
22 wrapper function which calls the real function via a wrapper which
23 processes the args and return values to ensure that reference counts are
24 properly handled for code which uses old-style dSP, PUSHs(), POPs() etc,
25 which don't adjust the reference counts of the items they manipulate.
27 xsppw_nargs indicates how many arguments the function consumes off the
28 stack. It can be a constant value or an expression, such as
30 ((PL_op->op_flags & OPf_STACKED) ? 2 : 1)
32 Alternatively if xsppw_nlists is 1, it indicates that the PP function
33 consumes a list (or - rarely - if 2, consumes two lists, like
34 pp_aassign()), as indicated by the top markstack position.
36 This is intended as a temporary fix when converting XS code to run under
37 PERL_RC_STACK builds. In the longer term, the PP function should be
38 rewritten to replace PUSHs() etc with rpp_push_1() etc.
44 # define XSPP_wrapped(xsppw_name, xsppw_nargs, xsppw_nlists) \
46 STATIC OP* S_##xsppw_name##_norc(pTHX); \
47 OP* xsppw_name(pTHX) \
49 return Perl_pp_wrap(aTHX_ S_##xsppw_name##_norc, \
50 (xsppw_nargs), (xsppw_nlists)); \
52 STATIC OP* S_##xsppw_name##_norc(pTHX)
55 # define XSPP_wrapped(xsppw_name, xsppw_nargs, xsppw_nlists) \
59 #define PP_wrapped(ppw_name, ppw_nargs, ppw_nlists) \
60 XSPP_wrapped(Perl_##ppw_name, ppw_nargs, ppw_nlists)
62 #define PP(s) OP * Perl_##s(pTHX)
65 =for apidoc_section $stack
68 Stack pointer. This is usually handled by C<xsubpp>. See C<L</dSP>> and
71 =for apidoc AmnU||MARK
72 Stack marker variable for the XSUB. See C<L</dMARK>>.
74 =for apidoc Am|void|PUSHMARK|SP
75 Opening bracket for arguments on a callback. See C<L</PUTBACK>> and
79 Declares a local copy of perl's stack pointer for the XSUB, available via
80 the C<SP> macro. See C<L</SP>>.
84 Declare Just C<SP>. This is actually identical to C<dSP>, and declares
85 a local copy of perl's stack pointer, available via the C<SP> macro.
86 See C<L<perlapi/SP>>. (Available for backward source code compatibility with
87 the old (Perl 5.005) thread model.)
89 =for apidoc Amn;||dMARK
90 Declare a stack marker variable, C<mark>, for the XSUB. See C<L</MARK>> and
93 =for apidoc Amn;||dORIGMARK
94 Saves the original stack mark for the XSUB. See C<L</ORIGMARK>>.
96 =for apidoc AmnU||ORIGMARK
97 The original stack mark for the XSUB. See C<L</dORIGMARK>>.
99 =for apidoc Amn;||SPAGAIN
100 Refetch the stack pointer. Used after a callback. See L<perlcall>.
104 #undef SP /* Solaris 2.7 i386 has this in /usr/include/sys/reg.h */
109 =for apidoc Amn;||TARG
111 C<TARG> is short for "target". It is an entry in the pad that an OPs
112 C<op_targ> refers to. It is scratchpad space, often used as a return
113 value for the OP, but some use it for other purposes.
119 #define PUSHMARK(p) \
121 Stack_off_t * mark_stack_entry; \
122 if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) \
123 == PL_markstack_max)) \
124 mark_stack_entry = markstack_grow(); \
125 *mark_stack_entry = (Stack_off_t)((p) - PL_stack_base); \
126 DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log, \
127 "MARK push %p %" IVdf "\n", \
128 PL_markstack_ptr, (IV)*mark_stack_entry))); \
131 #define TOPMARK Perl_TOPMARK(aTHX)
132 #define POPMARK Perl_POPMARK(aTHX)
136 DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log, \
137 "MARK inc %p %" IVdf "\n", \
138 (PL_markstack_ptr+1), (IV)*(PL_markstack_ptr+1)))); \
139 PL_markstack_ptr++; \
142 #define dSP SV **sp = PL_stack_sp
144 #define dMARK SV **mark = PL_stack_base + POPMARK
145 #define dORIGMARK const SSize_t origmark = (SSize_t)(mark - PL_stack_base)
146 #define ORIGMARK (PL_stack_base + origmark)
148 #define SPAGAIN sp = PL_stack_sp
149 #define MSPAGAIN STMT_START { sp = PL_stack_sp; mark = ORIGMARK; } STMT_END
151 #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
152 #define dTARGETSTACKED SV * GETTARGETSTACKED
154 #define GETTARGET targ = PAD_SV(PL_op->op_targ)
157 =for apidoc Amn;||dTARGET
158 Declare that this function uses C<TARG>, and initializes it
162 #define dTARGET SV * GETTARGET
164 #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
165 #define dATARGET SV * GETATARGET
167 #define dTARG SV *targ
169 #define NORMAL PL_op->op_next
170 #define DIE return Perl_die
173 =for apidoc Amn;||PUTBACK
174 Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
175 See C<L</PUSHMARK>> and L<perlcall> for other uses.
177 =for apidoc Amn|SV*|POPs
178 Pops an SV off the stack.
180 =for apidoc Amn|char*|POPp
181 Pops a string off the stack.
183 =for apidoc Amn|char*|POPpx
184 Pops a string off the stack. Identical to POPp. There are two names for
187 =for apidoc Amn|char*|POPpbytex
188 Pops a string off the stack which must consist of bytes i.e. characters < 256.
190 =for apidoc Amn|NV|POPn
191 Pops a double off the stack.
193 =for apidoc Amn|IV|POPi
194 Pops an integer off the stack.
196 =for apidoc Amn|UV|POPu
197 Pops an unsigned integer off the stack.
199 =for apidoc Amn|long|POPl
200 Pops a long off the stack.
202 =for apidoc Amn|long|POPul
203 Pops an unsigned long off the stack.
208 #define PUTBACK PL_stack_sp = sp
209 #define RETURN return (PUTBACK, NORMAL)
210 #define RETURNOP(o) return (PUTBACK, o)
211 #define RETURNX(x) return (x, PUTBACK, NORMAL)
214 # define POPs (assert(!rpp_stack_is_rc()), *sp--)
216 # define POPs (*sp--)
220 #define POPpx (SvPVx_nolen(POPs))
221 #define POPpconstx (SvPVx_nolen_const(POPs))
222 #define POPpbytex (SvPVbytex_nolen(POPs))
223 #define POPn (SvNVx(POPs))
224 #define POPi ((IV)SvIVx(POPs))
225 #define POPu ((UV)SvUVx(POPs))
226 #define POPl ((long)SvIVx(POPs))
227 #define POPul ((unsigned long)SvIVx(POPs))
230 #define TOPm1s (*(sp-1))
231 #define TOPp1s (*(sp+1))
233 #define TOPpx (SvPV_nolen(TOPs))
234 #define TOPn (SvNV(TOPs))
235 #define TOPi ((IV)SvIV(TOPs))
236 #define TOPu ((UV)SvUV(TOPs))
237 #define TOPl ((long)SvIV(TOPs))
238 #define TOPul ((unsigned long)SvUV(TOPs))
240 /* Go to some pains in the rare event that we must extend the stack. */
243 =for apidoc Am|void|EXTEND|SP|SSize_t nitems
244 Used to extend the argument stack for an XSUB's return values. Once
245 used, guarantees that there is room for at least C<nitems> to be pushed
248 =for apidoc Am|void|PUSHs|SV* sv
249 Push an SV onto the stack. The stack must have room for this element.
250 Does not handle 'set' magic. Does not use C<TARG>. See also
251 C<L</PUSHmortal>>, C<L</XPUSHs>>, and C<L</XPUSHmortal>>.
253 =for apidoc Am|void|PUSHp|char* str|STRLEN len
254 Push a string onto the stack. The stack must have room for this element.
255 The C<len> indicates the length of the string. Handles 'set' magic. Uses
256 C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it. Do not
257 call multiple C<TARG>-oriented macros to return lists from XSUB's - see
258 C<L</mPUSHp>> instead. See also C<L</XPUSHp>> and C<L</mXPUSHp>>.
260 =for apidoc Am|void|PUSHpvs|"literal string"
261 A variation on C<PUSHp> that takes a literal string and calculates its size
264 =for apidoc Am|void|PUSHn|NV nv
265 Push a double onto the stack. The stack must have room for this element.
266 Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
267 called to declare it. Do not call multiple C<TARG>-oriented macros to
268 return lists from XSUB's - see C<L</mPUSHn>> instead. See also C<L</XPUSHn>>
271 =for apidoc Am|void|PUSHi|IV iv
272 Push an integer onto the stack. The stack must have room for this element.
273 Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
274 called to declare it. Do not call multiple C<TARG>-oriented macros to
275 return lists from XSUB's - see C<L</mPUSHi>> instead. See also C<L</XPUSHi>>
278 =for apidoc Am|void|PUSHu|UV uv
279 Push an unsigned integer onto the stack. The stack must have room for this
280 element. Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
281 should be called to declare it. Do not call multiple C<TARG>-oriented
282 macros to return lists from XSUB's - see C<L</mPUSHu>> instead. See also
283 C<L</XPUSHu>> and C<L</mXPUSHu>>.
285 =for apidoc Am|void|XPUSHs|SV* sv
286 Push an SV onto the stack, extending the stack if necessary. Does not
287 handle 'set' magic. Does not use C<TARG>. See also C<L</XPUSHmortal>>,
288 C<PUSHs> and C<PUSHmortal>.
290 =for apidoc Am|void|XPUSHp|char* str|STRLEN len
291 Push a string onto the stack, extending the stack if necessary. The C<len>
292 indicates the length of the string. Handles 'set' magic. Uses C<TARG>, so
293 C<dTARGET> or C<dXSTARG> should be called to declare it. Do not call
294 multiple C<TARG>-oriented macros to return lists from XSUB's - see
295 C<L</mXPUSHp>> instead. See also C<L</PUSHp>> and C<L</mPUSHp>>.
297 =for apidoc Am|void|XPUSHpvs|"literal string"
298 A variation on C<XPUSHp> that takes a literal string and calculates its size
301 =for apidoc Am|void|XPUSHn|NV nv
302 Push a double onto the stack, extending the stack if necessary. Handles
303 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
304 declare it. Do not call multiple C<TARG>-oriented macros to return lists
305 from XSUB's - see C<L</mXPUSHn>> instead. See also C<L</PUSHn>> and
308 =for apidoc Am|void|XPUSHi|IV iv
309 Push an integer onto the stack, extending the stack if necessary. Handles
310 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
311 declare it. Do not call multiple C<TARG>-oriented macros to return lists
312 from XSUB's - see C<L</mXPUSHi>> instead. See also C<L</PUSHi>> and
315 =for apidoc Am|void|XPUSHu|UV uv
316 Push an unsigned integer onto the stack, extending the stack if necessary.
317 Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
318 called to declare it. Do not call multiple C<TARG>-oriented macros to
319 return lists from XSUB's - see C<L</mXPUSHu>> instead. See also C<L</PUSHu>> and
322 =for apidoc Am|void|mPUSHs|SV* sv
323 Push an SV onto the stack and mortalizes the SV. The stack must have room
324 for this element. Does not use C<TARG>. See also C<L</PUSHs>> and
327 =for apidoc Amn|void|PUSHmortal
328 Push a new mortal SV onto the stack. The stack must have room for this
329 element. Does not use C<TARG>. See also C<L</PUSHs>>, C<L</XPUSHmortal>> and
332 =for apidoc Am|void|mPUSHp|char* str|STRLEN len
333 Push a string onto the stack. The stack must have room for this element.
334 The C<len> indicates the length of the string. Does not use C<TARG>.
335 See also C<L</PUSHp>>, C<L</mXPUSHp>> and C<L</XPUSHp>>.
337 =for apidoc Am|void|mPUSHpvs|"literal string"
338 A variation on C<mPUSHp> that takes a literal string and calculates its size
341 =for apidoc Am|void|mPUSHn|NV nv
342 Push a double onto the stack. The stack must have room for this element.
343 Does not use C<TARG>. See also C<L</PUSHn>>, C<L</mXPUSHn>> and C<L</XPUSHn>>.
345 =for apidoc Am|void|mPUSHi|IV iv
346 Push an integer onto the stack. The stack must have room for this element.
347 Does not use C<TARG>. See also C<L</PUSHi>>, C<L</mXPUSHi>> and C<L</XPUSHi>>.
349 =for apidoc Am|void|mPUSHu|UV uv
350 Push an unsigned integer onto the stack. The stack must have room for this
351 element. Does not use C<TARG>. See also C<L</PUSHu>>, C<L</mXPUSHu>> and
354 =for apidoc Am|void|mXPUSHs|SV* sv
355 Push an SV onto the stack, extending the stack if necessary and mortalizes
356 the SV. Does not use C<TARG>. See also C<L</XPUSHs>> and C<L</mPUSHs>>.
358 =for apidoc Amn|void|XPUSHmortal
359 Push a new mortal SV onto the stack, extending the stack if necessary.
360 Does not use C<TARG>. See also C<L</XPUSHs>>, C<L</PUSHmortal>> and
363 =for apidoc Am|void|mXPUSHp|char* str|STRLEN len
364 Push a string onto the stack, extending the stack if necessary. The C<len>
365 indicates the length of the string. Does not use C<TARG>. See also
366 C<L</XPUSHp>>, C<mPUSHp> and C<PUSHp>.
368 =for apidoc Am|void|mXPUSHpvs|"literal string"
369 A variation on C<mXPUSHp> that takes a literal string and calculates its size
372 =for apidoc Am|void|mXPUSHn|NV nv
373 Push a double onto the stack, extending the stack if necessary.
374 Does not use C<TARG>. See also C<L</XPUSHn>>, C<L</mPUSHn>> and C<L</PUSHn>>.
376 =for apidoc Am|void|mXPUSHi|IV iv
377 Push an integer onto the stack, extending the stack if necessary.
378 Does not use C<TARG>. See also C<L</XPUSHi>>, C<L</mPUSHi>> and C<L</PUSHi>>.
380 =for apidoc Am|void|mXPUSHu|UV uv
381 Push an unsigned integer onto the stack, extending the stack if necessary.
382 Does not use C<TARG>. See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
387 /* EXTEND_HWM_SET: note the high-water-mark to which the stack has been
388 * requested to be extended (which is likely to be less than PL_stack_max)
390 #if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
391 # define EXTEND_HWM_SET(p, n) \
393 SSize_t extend_hwm_set_ix = (p) - PL_stack_base + (n); \
394 if (extend_hwm_set_ix > PL_curstackinfo->si_stack_hwm) \
395 PL_curstackinfo->si_stack_hwm = extend_hwm_set_ix; \
398 # define EXTEND_HWM_SET(p, n) NOOP
401 /* _EXTEND_SAFE_N(n): private helper macro for EXTEND().
402 * Tests whether the value of n would be truncated when implicitly cast to
403 * SSize_t as an arg to stack_grow(). If so, sets it to -1 instead to
404 * trigger a panic. It will be constant folded on platforms where this
408 #define _EXTEND_SAFE_N(n) \
409 (sizeof(n) > sizeof(SSize_t) && ((SSize_t)(n) != (n)) ? -1 : (n))
411 #ifdef STRESS_REALLOC
412 # define EXTEND_SKIP(p, n) EXTEND_HWM_SET(p, n)
414 # define EXTEND(p,n) STMT_START { \
415 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
416 PERL_UNUSED_VAR(sp); \
418 /* Same thing, but update mark register too. */
419 # define MEXTEND(p,n) STMT_START { \
420 const SSize_t markoff = mark - PL_stack_base; \
421 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
422 mark = PL_stack_base + markoff; \
423 PERL_UNUSED_VAR(sp); \
427 /* _EXTEND_NEEDS_GROW(p,n): private helper macro for EXTEND().
428 * Tests to see whether n is too big and we need to grow the stack. Be
429 * very careful if modifying this. There are many ways to get things wrong
430 * (wrapping, truncating etc) that could cause a false negative and cause
431 * the call to stack_grow() to be skipped. On the other hand, false
432 * positives are safe.
433 * Bear in mind that sizeof(p) may be less than, equal to, or greater
434 * than sizeof(n), and while n is documented to be signed, someone might
435 * pass an unsigned value or expression. In general don't use casts to
436 * avoid warnings; instead expect the caller to fix their code.
437 * It is legal for p to be greater than PL_stack_max.
438 * If the allocated stack is already very large but current usage is
439 * small, then PL_stack_max - p might wrap round to a negative value, but
440 * this just gives a safe false positive
443 # define _EXTEND_NEEDS_GROW(p,n) ((n) < 0 || PL_stack_max - (p) < (n))
446 /* EXTEND_SKIP(): used for where you would normally call EXTEND(), but
447 * you know for sure that a previous op will have already extended the
448 * stack sufficiently. For example pp_enteriter ensures that there
449 * is always at least 1 free slot, so pp_iter can return &PL_sv_yes/no
450 * without checking each time. Calling EXTEND_SKIP() defeats the HWM
451 * debugging mechanism which would otherwise whine
454 # define EXTEND_SKIP(p, n) STMT_START { \
455 EXTEND_HWM_SET(p, n); \
456 assert(!_EXTEND_NEEDS_GROW(p,n)); \
460 # define EXTEND(p,n) STMT_START { \
461 EXTEND_HWM_SET(p, n); \
462 if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) { \
463 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
464 PERL_UNUSED_VAR(sp); \
467 /* Same thing, but update mark register too. */
468 # define MEXTEND(p,n) STMT_START { \
469 EXTEND_HWM_SET(p, n); \
470 if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) { \
471 const SSize_t markoff = mark - PL_stack_base;\
472 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
473 mark = PL_stack_base + markoff; \
474 PERL_UNUSED_VAR(sp); \
480 /* set TARG to the IV value i. If do_taint is false,
481 * assume that PL_tainted can never be true */
482 #define TARGi(i, do_taint) \
486 ((SvFLAGS(TARG) & (SVTYPEMASK|SVf_THINKFIRST|SVf_IVisUV)) == SVt_IV) \
487 & (do_taint ? !TAINT_get : 1))) \
489 /* Cheap SvIOK_only(). \
490 * Assert that flags which SvIOK_only() would test or \
491 * clear can't be set, because we're SVt_IV */ \
492 assert(!(SvFLAGS(TARG) & \
493 (SVf_OOK|SVf_UTF8|(SVf_OK & ~(SVf_IOK|SVp_IOK))))); \
494 SvFLAGS(TARG) |= (SVf_IOK|SVp_IOK); \
495 /* SvIV_set() where sv_any points to head */ \
496 TARG->sv_u.svu_iv = TARGi_iv; \
499 sv_setiv_mg(targ, TARGi_iv); \
502 /* set TARG to the UV value u. If do_taint is false,
503 * assume that PL_tainted can never be true */
504 #define TARGu(u, do_taint) \
508 ((SvFLAGS(TARG) & (SVTYPEMASK|SVf_THINKFIRST|SVf_IVisUV)) == SVt_IV) \
509 & (do_taint ? !TAINT_get : 1) \
510 & (TARGu_uv <= (UV)IV_MAX))) \
512 /* Cheap SvIOK_only(). \
513 * Assert that flags which SvIOK_only() would test or \
514 * clear can't be set, because we're SVt_IV */ \
515 assert(!(SvFLAGS(TARG) & \
516 (SVf_OOK|SVf_UTF8|(SVf_OK & ~(SVf_IOK|SVp_IOK))))); \
517 SvFLAGS(TARG) |= (SVf_IOK|SVp_IOK); \
518 /* SvIV_set() where sv_any points to head */ \
519 TARG->sv_u.svu_iv = TARGu_uv; \
522 sv_setuv_mg(targ, TARGu_uv); \
525 /* set TARG to the NV value n. If do_taint is false,
526 * assume that PL_tainted can never be true */
527 #define TARGn(n, do_taint) \
531 ((SvFLAGS(TARG) & (SVTYPEMASK|SVf_THINKFIRST)) == SVt_NV) \
532 & (do_taint ? !TAINT_get : 1))) \
534 /* Cheap SvNOK_only(). \
535 * Assert that flags which SvNOK_only() would test or \
536 * clear can't be set, because we're SVt_NV */ \
537 assert(!(SvFLAGS(TARG) & \
538 (SVf_OOK|SVf_UTF8|(SVf_OK & ~(SVf_NOK|SVp_NOK))))); \
539 SvFLAGS(TARG) |= (SVf_NOK|SVp_NOK); \
540 SvNV_set(TARG, TARGn_nv); \
543 sv_setnv_mg(targ, TARGn_nv); \
547 # define PUSHs(s) (assert(!rpp_stack_is_rc()), *++sp = (s))
549 # define PUSHs(s) (*++sp = (s))
552 #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
553 #define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
554 #define PUSHpvs(s) PUSHp("" s "", sizeof(s)-1)
555 #define PUSHn(n) STMT_START { TARGn(n,1); PUSHs(TARG); } STMT_END
556 #define PUSHi(i) STMT_START { TARGi(i,1); PUSHs(TARG); } STMT_END
557 #define PUSHu(u) STMT_START { TARGu(u,1); PUSHs(TARG); } STMT_END
559 #define XPUSHs(s) STMT_START { EXTEND(sp,1); PUSHs(s); } STMT_END
560 #define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
561 #define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
562 #define XPUSHpvs(s) XPUSHp("" s "", sizeof(s)-1)
563 #define XPUSHn(n) STMT_START { TARGn(n,1); XPUSHs(TARG); } STMT_END
564 #define XPUSHi(i) STMT_START { TARGi(i,1); XPUSHs(TARG); } STMT_END
565 #define XPUSHu(u) STMT_START { TARGu(u,1); XPUSHs(TARG); } STMT_END
566 #define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
568 #define mPUSHs(s) PUSHs(sv_2mortal(s))
569 #define PUSHmortal PUSHs(sv_newmortal())
570 #define mPUSHp(p,l) PUSHs(newSVpvn_flags((p), (l), SVs_TEMP))
571 #define mPUSHpvs(s) mPUSHp("" s "", sizeof(s)-1)
572 #define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n))
573 #define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i))
574 #define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u))
576 #define mXPUSHs(s) XPUSHs(sv_2mortal(s))
577 #define XPUSHmortal XPUSHs(sv_newmortal())
578 #define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); mPUSHp((p), (l)); } STMT_END
579 #define mXPUSHpvs(s) mXPUSHp("" s "", sizeof(s)-1)
580 #define mXPUSHn(n) STMT_START { EXTEND(sp,1); mPUSHn(n); } STMT_END
581 #define mXPUSHi(i) STMT_START { EXTEND(sp,1); mPUSHi(i); } STMT_END
582 #define mXPUSHu(u) STMT_START { EXTEND(sp,1); mPUSHu(u); } STMT_END
584 #define SETs(s) (*sp = s)
585 #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
586 #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
587 #define SETn(n) STMT_START { TARGn(n,1); SETs(TARG); } STMT_END
588 #define SETi(i) STMT_START { TARGi(i,1); SETs(TARG); } STMT_END
589 #define SETu(u) STMT_START { TARGu(u,1); SETs(TARG); } STMT_END
591 #define dTOPss SV *sv = TOPs
592 #define dPOPss SV *sv = POPs
593 #define dTOPnv NV value = TOPn
594 #define dPOPnv NV value = POPn
595 #define dPOPnv_nomg NV value = (sp--, SvNV_nomg(TOPp1s))
596 #define dTOPiv IV value = TOPi
597 #define dPOPiv IV value = POPi
598 #define dTOPuv UV value = TOPu
599 #define dPOPuv UV value = POPu
601 #define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
602 #define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
603 #define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
605 #define USE_LEFT(sv) \
606 (SvOK(sv) || !(PL_op->op_flags & OPf_STACKED))
607 #define dPOPXiirl_ul_nomg(X) \
608 IV right = (sp--, SvIV_nomg(TOPp1s)); \
609 SV *leftsv = CAT2(X,s); \
610 IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0
612 #define dPOPPOPssrl dPOPXssrl(POP)
613 #define dPOPPOPnnrl dPOPXnnrl(POP)
614 #define dPOPPOPiirl dPOPXiirl(POP)
616 #define dPOPTOPssrl dPOPXssrl(TOP)
617 #define dPOPTOPnnrl dPOPXnnrl(TOP)
618 #define dPOPTOPnnrl_nomg \
619 NV right = SvNV_nomg(TOPs); NV left = (sp--, SvNV_nomg(TOPs))
620 #define dPOPTOPiirl dPOPXiirl(TOP)
621 #define dPOPTOPiirl_ul_nomg dPOPXiirl_ul_nomg(TOP)
622 #define dPOPTOPiirl_nomg \
623 IV right = SvIV_nomg(TOPs); IV left = (sp--, SvIV_nomg(TOPs))
625 #define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
626 #define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
627 #define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
629 #define RETSETYES RETURNX(SETs(&PL_sv_yes))
630 #define RETSETNO RETURNX(SETs(&PL_sv_no))
631 #define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
632 #define RETSETTARG STMT_START { SETTARG; RETURN; } STMT_END
634 #define ARGTARG PL_op->op_targ
636 #define MAXARG (PL_op->op_private & OPpARG4_MASK)
638 /* for backcompat - use switch_argstack() instead */
640 #define SWITCHSTACK(f,t) \
644 switch_argstack(t); \
648 #define EXTEND_MORTAL(n) \
650 SSize_t eMiX = PL_tmps_ix + (n); \
651 if (UNLIKELY(eMiX >= PL_tmps_max)) \
652 (void)Perl_tmps_grow_p(aTHX_ eMiX); \
655 #define AMGf_noright 1
656 #define AMGf_noleft 2
657 #define AMGf_assign 4 /* op supports mutator variant, e.g. $x += 1 */
659 #define AMGf_numeric 0x10 /* for Perl_try_amagic_bin */
661 #define AMGf_want_list 0x40
662 #define AMGf_numarg 0x80
665 /* do SvGETMAGIC on the stack args before checking for overload */
667 #define tryAMAGICun_MG(method, flags) STMT_START { \
668 if ( UNLIKELY((SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG))) \
669 && Perl_try_amagic_un(aTHX_ method, flags)) \
672 #define tryAMAGICbin_MG(method, flags) STMT_START { \
673 if ( UNLIKELY(((SvFLAGS(TOPm1s)|SvFLAGS(TOPs)) & (SVf_ROK|SVs_GMG))) \
674 && Perl_try_amagic_bin(aTHX_ method, flags)) \
678 #define AMG_CALLunary(sv,meth) \
679 amagic_call(sv,&PL_sv_undef, meth, AMGf_noright | AMGf_unary)
681 /* No longer used in core. Use AMG_CALLunary instead */
682 #define AMG_CALLun(sv,meth) AMG_CALLunary(sv, CAT2(meth,_amg))
684 #define tryAMAGICunTARGETlist(meth, jump) \
689 U8 gimme = GIMME_V; \
690 if (UNLIKELY(SvAMAGIC(arg) && \
691 (tmpsv = amagic_call(arg, &PL_sv_undef, meth, \
692 AMGf_want_list | AMGf_noright \
696 if (gimme == G_VOID) { \
699 else if (gimme == G_LIST) { \
702 assert(SvTYPE(tmpsv) == SVt_PVAV); \
703 len = av_count((AV *)tmpsv); \
704 (void)POPs; /* get rid of the arg */ \
706 for (i = 0; i < len; ++i) \
707 PUSHs(av_shift((AV *)tmpsv)); \
709 else { /* AMGf_want_scalar */ \
710 dATARGET; /* just use the arg's location */ \
711 sv_setsv(TARG, tmpsv); \
712 if (PL_op->op_flags & OPf_STACKED) \
718 OP *jump_o = NORMAL->op_next; \
719 while (jump_o->op_type == OP_NULL) \
720 jump_o = jump_o->op_next; \
721 assert(jump_o->op_type == OP_ENTERSUB); \
723 return jump_o->op_next; \
729 /* This is no longer used anywhere in the core. You might wish to consider
730 calling amagic_deref_call() directly, as it has a cleaner interface. */
731 #define tryAMAGICunDEREF(meth) \
733 sv = amagic_deref_call(*sp, CAT2(meth,_amg)); \
738 /* 2019: no longer used in core */
739 #define opASSIGN (PL_op->op_flags & OPf_STACKED)
742 =for apidoc mnU||LVRET
743 True if this op will be the return value of an lvalue subroutine
746 #define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
748 #define SvCANEXISTDELETE(sv) \
750 || !(mg = mg_find((const SV *) sv, PERL_MAGIC_tied)) \
751 || ( (stash = SvSTASH(SvRV(SvTIED_obj(MUTABLE_SV(sv), mg)))) \
752 && gv_fetchmethod_autoload(stash, "EXISTS", TRUE) \
753 && gv_fetchmethod_autoload(stash, "DELETE", TRUE) \
759 /* These are just for Perl_tied_method(), which is not part of the public API.
760 Use 0x04 rather than the next available bit, to help the compiler if the
761 architecture can generate more efficient instructions. */
762 # define TIED_METHOD_MORTALIZE_NOT_NEEDED 0x04
763 # define TIED_METHOD_ARGUMENTS_ON_STACK 0x08
764 # define TIED_METHOD_SAY 0x10
766 /* Used in various places that need to dereference a glob or globref */
767 # define MAYBE_DEREF_GV_flags(sv,phlags) \
769 (void)(((phlags) & SV_GMAGIC) && (SvGETMAGIC(sv),0)), \
772 : SvROK(sv) && SvTYPE(SvRV(sv)) <= SVt_PVLV && \
773 (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv))) \
777 # define MAYBE_DEREF_GV(sv) MAYBE_DEREF_GV_flags(sv,SV_GMAGIC)
778 # define MAYBE_DEREF_GV_nomg(sv) MAYBE_DEREF_GV_flags(sv,0)
780 # define FIND_RUNCV_padid_eq 1
781 # define FIND_RUNCV_level_eq 2
786 * ex: set ts=8 sts=4 sw=4 et: