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 =for apidoc_item |char*|POPpx
183 These each pop a string off the stack.
184 There are two names for historical reasons.
186 =for apidoc Amn|char*|POPpbytex
187 Pops a string off the stack which must consist of bytes i.e. characters < 256.
189 =for apidoc Amn|NV|POPn
190 Pops a double off the stack.
192 =for apidoc Amn|IV|POPi
193 Pops an integer off the stack.
195 =for apidoc Amn|UV|POPu
196 Pops an unsigned integer off the stack.
198 =for apidoc Amn|long|POPl
199 Pops a long off the stack.
201 =for apidoc Amn|long|POPul
202 Pops an unsigned long off the stack.
207 #define PUTBACK PL_stack_sp = sp
208 #define RETURN return (PUTBACK, NORMAL)
209 #define RETURNOP(o) return (PUTBACK, o)
210 #define RETURNX(x) return (x, PUTBACK, NORMAL)
213 # define POPs (assert(!rpp_stack_is_rc()), *sp--)
215 # define POPs (*sp--)
219 #define POPpx (SvPVx_nolen(POPs))
220 #define POPpconstx (SvPVx_nolen_const(POPs))
221 #define POPpbytex (SvPVbytex_nolen(POPs))
222 #define POPn (SvNVx(POPs))
223 #define POPi ((IV)SvIVx(POPs))
224 #define POPu ((UV)SvUVx(POPs))
225 #define POPl ((long)SvIVx(POPs))
226 #define POPul ((unsigned long)SvIVx(POPs))
229 #define TOPm1s (*(sp-1))
230 #define TOPp1s (*(sp+1))
232 #define TOPpx (SvPV_nolen(TOPs))
233 #define TOPn (SvNV(TOPs))
234 #define TOPi ((IV)SvIV(TOPs))
235 #define TOPu ((UV)SvUV(TOPs))
236 #define TOPl ((long)SvIV(TOPs))
237 #define TOPul ((unsigned long)SvUV(TOPs))
239 /* Go to some pains in the rare event that we must extend the stack. */
242 =for apidoc Am|void|EXTEND|SP|SSize_t nitems
243 Used to extend the argument stack for an XSUB's return values. Once
244 used, guarantees that there is room for at least C<nitems> to be pushed
247 =for apidoc Am|void|PUSHs|SV* sv
248 Push an SV onto the stack. The stack must have room for this element.
249 Does not handle 'set' magic. Does not use C<TARG>. See also
250 C<L</PUSHmortal>>, C<L</XPUSHs>>, and C<L</XPUSHmortal>>.
252 =for apidoc Am|void|PUSHp|char* str|STRLEN len
253 Push a string onto the stack. The stack must have room for this element.
254 The C<len> indicates the length of the string. Handles 'set' magic. Uses
255 C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it. Do not
256 call multiple C<TARG>-oriented macros to return lists from XSUB's - see
257 C<L</mPUSHp>> instead. See also C<L</XPUSHp>> and C<L</mXPUSHp>>.
259 =for apidoc Am|void|PUSHpvs|"literal string"
260 A variation on C<PUSHp> that takes a literal string and calculates its size
263 =for apidoc Am|void|PUSHn|NV nv
264 Push a double onto the stack. The stack must have room for this element.
265 Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
266 called to declare it. Do not call multiple C<TARG>-oriented macros to
267 return lists from XSUB's - see C<L</mPUSHn>> instead. See also C<L</XPUSHn>>
270 =for apidoc Am|void|PUSHi|IV iv
271 Push an integer onto the stack. The stack must have room for this element.
272 Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
273 called to declare it. Do not call multiple C<TARG>-oriented macros to
274 return lists from XSUB's - see C<L</mPUSHi>> instead. See also C<L</XPUSHi>>
277 =for apidoc Am|void|PUSHu|UV uv
278 Push an unsigned integer onto the stack. The stack must have room for this
279 element. Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
280 should be called to declare it. Do not call multiple C<TARG>-oriented
281 macros to return lists from XSUB's - see C<L</mPUSHu>> instead. See also
282 C<L</XPUSHu>> and C<L</mXPUSHu>>.
284 =for apidoc Am|void|XPUSHs|SV* sv
285 Push an SV onto the stack, extending the stack if necessary. Does not
286 handle 'set' magic. Does not use C<TARG>. See also C<L</XPUSHmortal>>,
287 C<PUSHs> and C<PUSHmortal>.
289 =for apidoc Am|void|XPUSHp|char* str|STRLEN len
290 Push a string onto the stack, extending the stack if necessary. The C<len>
291 indicates the length of the string. Handles 'set' magic. Uses C<TARG>, so
292 C<dTARGET> or C<dXSTARG> should be called to declare it. Do not call
293 multiple C<TARG>-oriented macros to return lists from XSUB's - see
294 C<L</mXPUSHp>> instead. See also C<L</PUSHp>> and C<L</mPUSHp>>.
296 =for apidoc Am|void|XPUSHpvs|"literal string"
297 A variation on C<XPUSHp> that takes a literal string and calculates its size
300 =for apidoc Am|void|XPUSHn|NV nv
301 Push a double onto the stack, extending the stack if necessary. Handles
302 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
303 declare it. Do not call multiple C<TARG>-oriented macros to return lists
304 from XSUB's - see C<L</mXPUSHn>> instead. See also C<L</PUSHn>> and
307 =for apidoc Am|void|XPUSHi|IV iv
308 Push an integer onto the stack, extending the stack if necessary. Handles
309 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
310 declare it. Do not call multiple C<TARG>-oriented macros to return lists
311 from XSUB's - see C<L</mXPUSHi>> instead. See also C<L</PUSHi>> and
314 =for apidoc Am|void|XPUSHu|UV uv
315 Push an unsigned integer onto the stack, extending the stack if necessary.
316 Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
317 called to declare it. Do not call multiple C<TARG>-oriented macros to
318 return lists from XSUB's - see C<L</mXPUSHu>> instead. See also C<L</PUSHu>> and
321 =for apidoc Am|void|mPUSHs|SV* sv
322 Push an SV onto the stack and mortalizes the SV. The stack must have room
323 for this element. Does not use C<TARG>. See also C<L</PUSHs>> and
326 =for apidoc Amn|void|PUSHmortal
327 Push a new mortal SV onto the stack. The stack must have room for this
328 element. Does not use C<TARG>. See also C<L</PUSHs>>, C<L</XPUSHmortal>> and
331 =for apidoc Am|void|mPUSHp|char* str|STRLEN len
332 Push a string onto the stack. The stack must have room for this element.
333 The C<len> indicates the length of the string. Does not use C<TARG>.
334 See also C<L</PUSHp>>, C<L</mXPUSHp>> and C<L</XPUSHp>>.
336 =for apidoc Am|void|mPUSHpvs|"literal string"
337 A variation on C<mPUSHp> that takes a literal string and calculates its size
340 =for apidoc Am|void|mPUSHn|NV nv
341 Push a double onto the stack. The stack must have room for this element.
342 Does not use C<TARG>. See also C<L</PUSHn>>, C<L</mXPUSHn>> and C<L</XPUSHn>>.
344 =for apidoc Am|void|mPUSHi|IV iv
345 Push an integer onto the stack. The stack must have room for this element.
346 Does not use C<TARG>. See also C<L</PUSHi>>, C<L</mXPUSHi>> and C<L</XPUSHi>>.
348 =for apidoc Am|void|mPUSHu|UV uv
349 Push an unsigned integer onto the stack. The stack must have room for this
350 element. Does not use C<TARG>. See also C<L</PUSHu>>, C<L</mXPUSHu>> and
353 =for apidoc Am|void|mXPUSHs|SV* sv
354 Push an SV onto the stack, extending the stack if necessary and mortalizes
355 the SV. Does not use C<TARG>. See also C<L</XPUSHs>> and C<L</mPUSHs>>.
357 =for apidoc Amn|void|XPUSHmortal
358 Push a new mortal SV onto the stack, extending the stack if necessary.
359 Does not use C<TARG>. See also C<L</XPUSHs>>, C<L</PUSHmortal>> and
362 =for apidoc Am|void|mXPUSHp|char* str|STRLEN len
363 Push a string onto the stack, extending the stack if necessary. The C<len>
364 indicates the length of the string. Does not use C<TARG>. See also
365 C<L</XPUSHp>>, C<mPUSHp> and C<PUSHp>.
367 =for apidoc Am|void|mXPUSHpvs|"literal string"
368 A variation on C<mXPUSHp> that takes a literal string and calculates its size
371 =for apidoc Am|void|mXPUSHn|NV nv
372 Push a double onto the stack, extending the stack if necessary.
373 Does not use C<TARG>. See also C<L</XPUSHn>>, C<L</mPUSHn>> and C<L</PUSHn>>.
375 =for apidoc Am|void|mXPUSHi|IV iv
376 Push an integer onto the stack, extending the stack if necessary.
377 Does not use C<TARG>. See also C<L</XPUSHi>>, C<L</mPUSHi>> and C<L</PUSHi>>.
379 =for apidoc Am|void|mXPUSHu|UV uv
380 Push an unsigned integer onto the stack, extending the stack if necessary.
381 Does not use C<TARG>. See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
386 /* EXTEND_HWM_SET: note the high-water-mark to which the stack has been
387 * requested to be extended (which is likely to be less than PL_stack_max)
390 # define EXTEND_HWM_SET(p, n) \
392 SSize_t extend_hwm_set_ix = (p) - PL_stack_base + (n); \
393 if (extend_hwm_set_ix > PL_curstackinfo->si_stack_hwm) \
394 PL_curstackinfo->si_stack_hwm = extend_hwm_set_ix; \
397 # define EXTEND_HWM_SET(p, n) NOOP
400 /* _EXTEND_SAFE_N(n): private helper macro for EXTEND().
401 * Tests whether the value of n would be truncated when implicitly cast to
402 * SSize_t as an arg to stack_grow(). If so, sets it to -1 instead to
403 * trigger a panic. It will be constant folded on platforms where this
407 #define _EXTEND_SAFE_N(n) \
408 (sizeof(n) > sizeof(SSize_t) && ((SSize_t)(n) != (n)) ? -1 : (n))
410 #ifdef STRESS_REALLOC
411 # define EXTEND_SKIP(p, n) EXTEND_HWM_SET(p, n)
413 # define EXTEND(p,n) STMT_START { \
414 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
415 PERL_UNUSED_VAR(sp); \
417 /* Same thing, but update mark register too. */
418 # define MEXTEND(p,n) STMT_START { \
419 const SSize_t markoff = mark - PL_stack_base; \
420 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
421 mark = PL_stack_base + markoff; \
422 PERL_UNUSED_VAR(sp); \
426 /* _EXTEND_NEEDS_GROW(p,n): private helper macro for EXTEND().
427 * Tests to see whether n is too big and we need to grow the stack. Be
428 * very careful if modifying this. There are many ways to get things wrong
429 * (wrapping, truncating etc) that could cause a false negative and cause
430 * the call to stack_grow() to be skipped. On the other hand, false
431 * positives are safe.
432 * Bear in mind that sizeof(p) may be less than, equal to, or greater
433 * than sizeof(n), and while n is documented to be signed, someone might
434 * pass an unsigned value or expression. In general don't use casts to
435 * avoid warnings; instead expect the caller to fix their code.
436 * It is legal for p to be greater than PL_stack_max.
437 * If the allocated stack is already very large but current usage is
438 * small, then PL_stack_max - p might wrap round to a negative value, but
439 * this just gives a safe false positive
442 # define _EXTEND_NEEDS_GROW(p,n) ((n) < 0 || PL_stack_max - (p) < (n))
445 /* EXTEND_SKIP(): used for where you would normally call EXTEND(), but
446 * you know for sure that a previous op will have already extended the
447 * stack sufficiently. For example pp_enteriter ensures that there
448 * is always at least 1 free slot, so pp_iter can return &PL_sv_yes/no
449 * without checking each time. Calling EXTEND_SKIP() defeats the HWM
450 * debugging mechanism which would otherwise whine
453 # define EXTEND_SKIP(p, n) STMT_START { \
454 EXTEND_HWM_SET(p, n); \
455 assert(!_EXTEND_NEEDS_GROW(p,n)); \
459 # define EXTEND(p,n) STMT_START { \
460 EXTEND_HWM_SET(p, n); \
461 if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) { \
462 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
463 PERL_UNUSED_VAR(sp); \
466 /* Same thing, but update mark register too. */
467 # define MEXTEND(p,n) STMT_START { \
468 EXTEND_HWM_SET(p, n); \
469 if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) { \
470 const SSize_t markoff = mark - PL_stack_base;\
471 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
472 mark = PL_stack_base + markoff; \
473 PERL_UNUSED_VAR(sp); \
479 /* set TARG to the IV value i. If do_taint is false,
480 * assume that PL_tainted can never be true */
481 #define TARGi(i, do_taint) \
485 ((SvFLAGS(TARG) & (SVTYPEMASK|SVf_THINKFIRST|SVf_IVisUV)) == SVt_IV) \
486 & (do_taint ? !TAINT_get : 1))) \
488 /* Cheap SvIOK_only(). \
489 * Assert that flags which SvIOK_only() would test or \
490 * clear can't be set, because we're SVt_IV */ \
491 assert(!(SvFLAGS(TARG) & \
492 (SVf_OOK|SVf_UTF8|(SVf_OK & ~(SVf_IOK|SVp_IOK))))); \
493 SvFLAGS(TARG) |= (SVf_IOK|SVp_IOK); \
494 /* SvIV_set() where sv_any points to head */ \
495 TARG->sv_u.svu_iv = TARGi_iv; \
498 sv_setiv_mg(targ, TARGi_iv); \
501 /* set TARG to the UV value u. If do_taint is false,
502 * assume that PL_tainted can never be true */
503 #define TARGu(u, do_taint) \
507 ((SvFLAGS(TARG) & (SVTYPEMASK|SVf_THINKFIRST|SVf_IVisUV)) == SVt_IV) \
508 & (do_taint ? !TAINT_get : 1) \
509 & (TARGu_uv <= (UV)IV_MAX))) \
511 /* Cheap SvIOK_only(). \
512 * Assert that flags which SvIOK_only() would test or \
513 * clear can't be set, because we're SVt_IV */ \
514 assert(!(SvFLAGS(TARG) & \
515 (SVf_OOK|SVf_UTF8|(SVf_OK & ~(SVf_IOK|SVp_IOK))))); \
516 SvFLAGS(TARG) |= (SVf_IOK|SVp_IOK); \
517 /* SvIV_set() where sv_any points to head */ \
518 TARG->sv_u.svu_iv = TARGu_uv; \
521 sv_setuv_mg(targ, TARGu_uv); \
524 /* set TARG to the NV value n. If do_taint is false,
525 * assume that PL_tainted can never be true */
526 #define TARGn(n, do_taint) \
530 ((SvFLAGS(TARG) & (SVTYPEMASK|SVf_THINKFIRST)) == SVt_NV) \
531 & (do_taint ? !TAINT_get : 1))) \
533 /* Cheap SvNOK_only(). \
534 * Assert that flags which SvNOK_only() would test or \
535 * clear can't be set, because we're SVt_NV */ \
536 assert(!(SvFLAGS(TARG) & \
537 (SVf_OOK|SVf_UTF8|(SVf_OK & ~(SVf_NOK|SVp_NOK))))); \
538 SvFLAGS(TARG) |= (SVf_NOK|SVp_NOK); \
539 SvNV_set(TARG, TARGn_nv); \
542 sv_setnv_mg(targ, TARGn_nv); \
546 # define PUSHs(s) (assert(!rpp_stack_is_rc()), *++sp = (s))
548 # define PUSHs(s) (*++sp = (s))
551 #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
552 #define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
553 #define PUSHpvs(s) PUSHp("" s "", sizeof(s)-1)
554 #define PUSHn(n) STMT_START { TARGn(n,1); PUSHs(TARG); } STMT_END
555 #define PUSHi(i) STMT_START { TARGi(i,1); PUSHs(TARG); } STMT_END
556 #define PUSHu(u) STMT_START { TARGu(u,1); PUSHs(TARG); } STMT_END
558 #define XPUSHs(s) STMT_START { EXTEND(sp,1); PUSHs(s); } STMT_END
559 #define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
560 #define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
561 #define XPUSHpvs(s) XPUSHp("" s "", sizeof(s)-1)
562 #define XPUSHn(n) STMT_START { TARGn(n,1); XPUSHs(TARG); } STMT_END
563 #define XPUSHi(i) STMT_START { TARGi(i,1); XPUSHs(TARG); } STMT_END
564 #define XPUSHu(u) STMT_START { TARGu(u,1); XPUSHs(TARG); } STMT_END
565 #define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
567 #define mPUSHs(s) PUSHs(sv_2mortal(s))
568 #define PUSHmortal PUSHs(sv_newmortal())
569 #define mPUSHp(p,l) PUSHs(newSVpvn_flags((p), (l), SVs_TEMP))
570 #define mPUSHpvs(s) mPUSHp("" s "", sizeof(s)-1)
571 #define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n))
572 #define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i))
573 #define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u))
575 #define mXPUSHs(s) XPUSHs(sv_2mortal(s))
576 #define XPUSHmortal XPUSHs(sv_newmortal())
577 #define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); mPUSHp((p), (l)); } STMT_END
578 #define mXPUSHpvs(s) mXPUSHp("" s "", sizeof(s)-1)
579 #define mXPUSHn(n) STMT_START { EXTEND(sp,1); mPUSHn(n); } STMT_END
580 #define mXPUSHi(i) STMT_START { EXTEND(sp,1); mPUSHi(i); } STMT_END
581 #define mXPUSHu(u) STMT_START { EXTEND(sp,1); mPUSHu(u); } STMT_END
583 #define SETs(s) (*sp = s)
584 #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
585 #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
586 #define SETn(n) STMT_START { TARGn(n,1); SETs(TARG); } STMT_END
587 #define SETi(i) STMT_START { TARGi(i,1); SETs(TARG); } STMT_END
588 #define SETu(u) STMT_START { TARGu(u,1); SETs(TARG); } STMT_END
590 #define dTOPss SV *sv = TOPs
591 #define dPOPss SV *sv = POPs
592 #define dTOPnv NV value = TOPn
593 #define dPOPnv NV value = POPn
594 #define dPOPnv_nomg NV value = (sp--, SvNV_nomg(TOPp1s))
595 #define dTOPiv IV value = TOPi
596 #define dPOPiv IV value = POPi
597 #define dTOPuv UV value = TOPu
598 #define dPOPuv UV value = POPu
600 #define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
601 #define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
602 #define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
604 #define USE_LEFT(sv) \
605 (SvOK(sv) || !(PL_op->op_flags & OPf_STACKED))
606 #define dPOPXiirl_ul_nomg(X) \
607 IV right = (sp--, SvIV_nomg(TOPp1s)); \
608 SV *leftsv = CAT2(X,s); \
609 IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0
611 #define dPOPPOPssrl dPOPXssrl(POP)
612 #define dPOPPOPnnrl dPOPXnnrl(POP)
613 #define dPOPPOPiirl dPOPXiirl(POP)
615 #define dPOPTOPssrl dPOPXssrl(TOP)
616 #define dPOPTOPnnrl dPOPXnnrl(TOP)
617 #define dPOPTOPnnrl_nomg \
618 NV right = SvNV_nomg(TOPs); NV left = (sp--, SvNV_nomg(TOPs))
619 #define dPOPTOPiirl dPOPXiirl(TOP)
620 #define dPOPTOPiirl_ul_nomg dPOPXiirl_ul_nomg(TOP)
621 #define dPOPTOPiirl_nomg \
622 IV right = SvIV_nomg(TOPs); IV left = (sp--, SvIV_nomg(TOPs))
624 #define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
625 #define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
626 #define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
628 #define RETSETYES RETURNX(SETs(&PL_sv_yes))
629 #define RETSETNO RETURNX(SETs(&PL_sv_no))
630 #define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
631 #define RETSETTARG STMT_START { SETTARG; RETURN; } STMT_END
633 #define ARGTARG PL_op->op_targ
635 #define MAXARG (PL_op->op_private & OPpARG4_MASK)
636 #define MAXARG3 (PL_op->op_private & OPpARG3_MASK)
639 /* for backcompat - use switch_argstack() instead */
641 #define SWITCHSTACK(f,t) \
645 switch_argstack(t); \
649 #define EXTEND_MORTAL(n) \
651 SSize_t eMiX = PL_tmps_ix + (n); \
652 if (UNLIKELY(eMiX >= PL_tmps_max)) \
653 (void)Perl_tmps_grow_p(aTHX_ eMiX); \
656 #define AMGf_noright 1
657 #define AMGf_noleft 2
658 #define AMGf_assign 4 /* op supports mutator variant, e.g. $x += 1 */
660 #define AMGf_numeric 0x10 /* for Perl_try_amagic_bin */
662 #define AMGf_want_list 0x40
663 #define AMGf_numarg 0x80
666 /* do SvGETMAGIC on the stack args before checking for overload */
668 #define tryAMAGICun_MG(method, flags) STMT_START { \
669 if ( UNLIKELY((SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG))) \
670 && Perl_try_amagic_un(aTHX_ method, flags)) \
673 #define tryAMAGICbin_MG(method, flags) STMT_START { \
674 if ( UNLIKELY(((SvFLAGS(TOPm1s)|SvFLAGS(TOPs)) & (SVf_ROK|SVs_GMG))) \
675 && Perl_try_amagic_bin(aTHX_ method, flags)) \
679 #define AMG_CALLunary(sv,meth) \
680 amagic_call(sv,&PL_sv_undef, meth, AMGf_noright | AMGf_unary)
682 /* No longer used in core. Use AMG_CALLunary instead */
683 #define AMG_CALLun(sv,meth) AMG_CALLunary(sv, CAT2(meth,_amg))
685 /* This is no longer used anywhere in the core. You might wish to consider
686 calling amagic_deref_call() directly, as it has a cleaner interface. */
687 #define tryAMAGICunDEREF(meth) \
689 sv = amagic_deref_call(*sp, CAT2(meth,_amg)); \
694 /* 2019: no longer used in core */
695 #define opASSIGN (PL_op->op_flags & OPf_STACKED)
698 =for apidoc mnU||LVRET
699 True if this op will be the return value of an lvalue subroutine
702 #define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
704 #define SvCANEXISTDELETE(sv) Perl_sv_can_existdelete(aTHX_ MUTABLE_SV(sv))
708 /* These are just for Perl_tied_method(), which is not part of the public API.
709 Use 0x04 rather than the next available bit, to help the compiler if the
710 architecture can generate more efficient instructions. */
711 # define TIED_METHOD_MORTALIZE_NOT_NEEDED 0x04
712 # define TIED_METHOD_ARGUMENTS_ON_STACK 0x08
713 # define TIED_METHOD_SAY 0x10
715 /* Used in various places that need to dereference a glob or globref */
716 # define MAYBE_DEREF_GV_flags(sv,phlags) \
718 (void)(((phlags) & SV_GMAGIC) && (SvGETMAGIC(sv),0)), \
721 : SvROK(sv) && SvTYPE(SvRV(sv)) <= SVt_PVLV && \
722 (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv))) \
726 # define MAYBE_DEREF_GV(sv) MAYBE_DEREF_GV_flags(sv,SV_GMAGIC)
727 # define MAYBE_DEREF_GV_nomg(sv) MAYBE_DEREF_GV_flags(sv,0)
729 # define FIND_RUNCV_padid_eq 1
730 # define FIND_RUNCV_level_eq 2
735 * ex: set ts=8 sts=4 sw=4 et: