This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid (TAINTING_get && TAINT_get)
[perl5.git] / pp.h
CommitLineData
a0d0e21e 1/* pp.h
79072805 2 *
1129b882
NC
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
79072805 5 *
a0d0e21e
LW
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.
79072805 8 *
a0d0e21e 9 */
79072805 10
cea2e8a9 11#define PP(s) OP * Perl_##s(pTHX)
79072805 12
954c1994 13/*
ccfc67b7
JH
14=head1 Stack Manipulation Macros
15
954c1994 16=for apidoc AmU||SP
fbe13c60 17Stack pointer. This is usually handled by C<xsubpp>. See C<L</dSP>> and
954c1994
GS
18C<SPAGAIN>.
19
20=for apidoc AmU||MARK
fbe13c60 21Stack marker variable for the XSUB. See C<L</dMARK>>.
954c1994 22
c578083c 23=for apidoc Am|void|PUSHMARK|SP
fbe13c60 24Opening bracket for arguments on a callback. See C<L</PUTBACK>> and
954c1994
GS
25L<perlcall>.
26
27=for apidoc Ams||dSP
28Declares a local copy of perl's stack pointer for the XSUB, available via
fbe13c60 29the C<SP> macro. See C<L</SP>>.
954c1994 30
fac3506f
MS
31=for apidoc ms||djSP
32
154e47c8 33Declare Just C<SP>. This is actually identical to C<dSP>, and declares
fac3506f 34a local copy of perl's stack pointer, available via the C<SP> macro.
fbe13c60
KW
35See C<L<perlapi/SP>>. (Available for backward source code compatibility with
36the old (Perl 5.005) thread model.)
fac3506f 37
954c1994 38=for apidoc Ams||dMARK
fbe13c60
KW
39Declare a stack marker variable, C<mark>, for the XSUB. See C<L</MARK>> and
40C<L</dORIGMARK>>.
954c1994
GS
41
42=for apidoc Ams||dORIGMARK
fbe13c60 43Saves the original stack mark for the XSUB. See C<L</ORIGMARK>>.
954c1994
GS
44
45=for apidoc AmU||ORIGMARK
fbe13c60 46The original stack mark for the XSUB. See C<L</dORIGMARK>>.
954c1994
GS
47
48=for apidoc Ams||SPAGAIN
49Refetch the stack pointer. Used after a callback. See L<perlcall>.
50
fac3506f 51=cut */
954c1994 52
ac634a9a 53#undef SP /* Solaris 2.7 i386 has this in /usr/include/sys/reg.h */
79072805
LW
54#define SP sp
55#define MARK mark
56#define TARG targ
57
6cae08a8
RU
58#if defined(DEBUGGING) && defined(PERL_USE_GCC_BRACE_GROUPS)
59#define PUSHMARK(p) \
60 STMT_START { \
61 I32 * mark_stack_entry; \
62 if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max)) \
63 mark_stack_entry = markstack_grow(); \
64 *mark_stack_entry = (I32)((p) - PL_stack_base); \
65 DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK push %p %d\n", \
66 PL_markstack_ptr, *mark_stack_entry)); \
67 } STMT_END
68#define TOPMARK \
69 ({ \
70 DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK top %p %d\n", \
71 PL_markstack_ptr, *PL_markstack_ptr)); \
72 *PL_markstack_ptr; \
73 })
74#define POPMARK \
75 ({ \
76 DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK pop %p %d\n", \
77 (PL_markstack_ptr-1), *(PL_markstack_ptr-1))); \
78 assert((PL_markstack_ptr > PL_markstack) || !"MARK underflow");\
79 *PL_markstack_ptr--; \
80 })
81#define INCMARK \
82 ({ \
83 DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK inc %p %d\n", \
84 (PL_markstack_ptr+1), *(PL_markstack_ptr+1))); \
85 *PL_markstack_ptr++; \
86 })
87#else
88#define PUSHMARK(p) \
89 STMT_START { \
90 I32 * mark_stack_entry; \
91 if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max)) \
92 mark_stack_entry = markstack_grow(); \
93 *mark_stack_entry = (I32)((p) - PL_stack_base); \
94 } STMT_END
95#define TOPMARK (*PL_markstack_ptr)
96#define POPMARK (*PL_markstack_ptr--)
97#define INCMARK (*PL_markstack_ptr++)
98#endif
a0d0e21e 99
bc0d193f 100#define dSP SV **sp = PL_stack_sp
39644a26 101#define djSP dSP
5aaab254 102#define dMARK SV **mark = PL_stack_base + POPMARK
514696af 103#define dORIGMARK const I32 origmark = (I32)(mark - PL_stack_base)
3280af22 104#define ORIGMARK (PL_stack_base + origmark)
79072805 105
3280af22 106#define SPAGAIN sp = PL_stack_sp
16e7e110 107#define MSPAGAIN STMT_START { sp = PL_stack_sp; mark = ORIGMARK; } STMT_END
79072805 108
533c011a 109#define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
79072805
LW
110#define dTARGETSTACKED SV * GETTARGETSTACKED
111
533c011a 112#define GETTARGET targ = PAD_SV(PL_op->op_targ)
79072805
LW
113#define dTARGET SV * GETTARGET
114
533c011a 115#define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
79072805
LW
116#define dATARGET SV * GETATARGET
117
118#define dTARG SV *targ
119
533c011a 120#define NORMAL PL_op->op_next
9fed9930 121#define DIE return Perl_die
79072805 122
954c1994
GS
123/*
124=for apidoc Ams||PUTBACK
125Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
fbe13c60 126See C<L</PUSHMARK>> and L<perlcall> for other uses.
954c1994
GS
127
128=for apidoc Amn|SV*|POPs
129Pops an SV off the stack.
130
131=for apidoc Amn|char*|POPp
4b7c0884 132Pops a string off the stack.
595ae481
NIS
133
134=for apidoc Amn|char*|POPpx
4b7c0884
FC
135Pops a string off the stack. Identical to POPp. There are two names for
136historical reasons.
595ae481
NIS
137
138=for apidoc Amn|char*|POPpbytex
139Pops a string off the stack which must consist of bytes i.e. characters < 256.
954c1994
GS
140
141=for apidoc Amn|NV|POPn
142Pops a double off the stack.
143
144=for apidoc Amn|IV|POPi
145Pops an integer off the stack.
146
d0554719
TC
147=for apidoc Amn|UV|POPu
148Pops an unsigned integer off the stack.
149
954c1994
GS
150=for apidoc Amn|long|POPl
151Pops a long off the stack.
152
d0554719
TC
153=for apidoc Amn|long|POPul
154Pops an unsigned long off the stack.
155
954c1994
GS
156=cut
157*/
158
3280af22 159#define PUTBACK PL_stack_sp = sp
8a67133a
NC
160#define RETURN return (PUTBACK, NORMAL)
161#define RETURNOP(o) return (PUTBACK, o)
162#define RETURNX(x) return (x, PUTBACK, NORMAL)
79072805
LW
163
164#define POPs (*sp--)
4b7c0884 165#define POPp POPpx
8c074e2a
NC
166#define POPpx (SvPVx_nolen(POPs))
167#define POPpconstx (SvPVx_nolen_const(POPs))
168#define POPpbytex (SvPVbytex_nolen(POPs))
463ee0b2 169#define POPn (SvNVx(POPs))
a0d0e21e 170#define POPi ((IV)SvIVx(POPs))
ff68c719 171#define POPu ((UV)SvUVx(POPs))
463ee0b2 172#define POPl ((long)SvIVx(POPs))
d9b3e12d 173#define POPul ((unsigned long)SvIVx(POPs))
79072805
LW
174
175#define TOPs (*sp)
56370e9f 176#define TOPm1s (*(sp-1))
7dca457a 177#define TOPp1s (*(sp+1))
4b7c0884 178#define TOPp TOPpx
95fad918 179#define TOPpx (SvPV_nolen(TOPs))
463ee0b2 180#define TOPn (SvNV(TOPs))
a0d0e21e 181#define TOPi ((IV)SvIV(TOPs))
ff68c719 182#define TOPu ((UV)SvUV(TOPs))
463ee0b2 183#define TOPl ((long)SvIV(TOPs))
c5a0f51a 184#define TOPul ((unsigned long)SvUV(TOPs))
79072805
LW
185
186/* Go to some pains in the rare event that we must extend the stack. */
954c1994
GS
187
188/*
fc16c392 189=for apidoc Am|void|EXTEND|SP|SSize_t nitems
72d33970 190Used to extend the argument stack for an XSUB's return values. Once
4375e838 191used, guarantees that there is room for at least C<nitems> to be pushed
954c1994
GS
192onto the stack.
193
194=for apidoc Am|void|PUSHs|SV* sv
aacdac46 195Push an SV onto the stack. The stack must have room for this element.
fbe13c60
KW
196Does not handle 'set' magic. Does not use C<TARG>. See also
197C<L</PUSHmortal>>, C<L</XPUSHs>>, and C<L</XPUSHmortal>>.
954c1994
GS
198
199=for apidoc Am|void|PUSHp|char* str|STRLEN len
200Push a string onto the stack. The stack must have room for this element.
d82b684c
SH
201The C<len> indicates the length of the string. Handles 'set' magic. Uses
202C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it. Do not
203call multiple C<TARG>-oriented macros to return lists from XSUB's - see
fbe13c60 204C<L</mPUSHp>> instead. See also C<L</XPUSHp>> and C<L</mXPUSHp>>.
954c1994
GS
205
206=for apidoc Am|void|PUSHn|NV nv
207Push a double onto the stack. The stack must have room for this element.
d82b684c
SH
208Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
209called to declare it. Do not call multiple C<TARG>-oriented macros to
fbe13c60
KW
210return lists from XSUB's - see C<L</mPUSHn>> instead. See also C<L</XPUSHn>>
211and C<L</mXPUSHn>>.
954c1994
GS
212
213=for apidoc Am|void|PUSHi|IV iv
214Push an integer onto the stack. The stack must have room for this element.
d82b684c
SH
215Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
216called to declare it. Do not call multiple C<TARG>-oriented macros to
fbe13c60
KW
217return lists from XSUB's - see C<L</mPUSHi>> instead. See also C<L</XPUSHi>>
218and C<L</mXPUSHi>>.
954c1994
GS
219
220=for apidoc Am|void|PUSHu|UV uv
221Push an unsigned integer onto the stack. The stack must have room for this
d82b684c
SH
222element. Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
223should be called to declare it. Do not call multiple C<TARG>-oriented
fbe13c60
KW
224macros to return lists from XSUB's - see C<L</mPUSHu>> instead. See also
225C<L</XPUSHu>> and C<L</mXPUSHu>>.
954c1994
GS
226
227=for apidoc Am|void|XPUSHs|SV* sv
228Push an SV onto the stack, extending the stack if necessary. Does not
fbe13c60 229handle 'set' magic. Does not use C<TARG>. See also C<L</XPUSHmortal>>,
d82b684c 230C<PUSHs> and C<PUSHmortal>.
954c1994
GS
231
232=for apidoc Am|void|XPUSHp|char* str|STRLEN len
233Push a string onto the stack, extending the stack if necessary. The C<len>
d82b684c
SH
234indicates the length of the string. Handles 'set' magic. Uses C<TARG>, so
235C<dTARGET> or C<dXSTARG> should be called to declare it. Do not call
236multiple C<TARG>-oriented macros to return lists from XSUB's - see
fbe13c60 237C<L</mXPUSHp>> instead. See also C<L</PUSHp>> and C<L</mPUSHp>>.
954c1994
GS
238
239=for apidoc Am|void|XPUSHn|NV nv
240Push a double onto the stack, extending the stack if necessary. Handles
d82b684c
SH
241'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
242declare it. Do not call multiple C<TARG>-oriented macros to return lists
fbe13c60
KW
243from XSUB's - see C<L</mXPUSHn>> instead. See also C<L</PUSHn>> and
244C<L</mPUSHn>>.
954c1994
GS
245
246=for apidoc Am|void|XPUSHi|IV iv
247Push an integer onto the stack, extending the stack if necessary. Handles
d82b684c
SH
248'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
249declare it. Do not call multiple C<TARG>-oriented macros to return lists
fbe13c60
KW
250from XSUB's - see C<L</mXPUSHi>> instead. See also C<L</PUSHi>> and
251C<L</mPUSHi>>.
954c1994
GS
252
253=for apidoc Am|void|XPUSHu|UV uv
aacdac46 254Push an unsigned integer onto the stack, extending the stack if necessary.
d82b684c
SH
255Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
256called to declare it. Do not call multiple C<TARG>-oriented macros to
fbe13c60
KW
257return lists from XSUB's - see C<L</mXPUSHu>> instead. See also C<L</PUSHu>> and
258C<L</mPUSHu>>.
d82b684c 259
6e449a3a
MHM
260=for apidoc Am|void|mPUSHs|SV* sv
261Push an SV onto the stack and mortalizes the SV. The stack must have room
fbe13c60
KW
262for this element. Does not use C<TARG>. See also C<L</PUSHs>> and
263C<L</mXPUSHs>>.
6e449a3a 264
d82b684c
SH
265=for apidoc Am|void|PUSHmortal
266Push a new mortal SV onto the stack. The stack must have room for this
fbe13c60
KW
267element. Does not use C<TARG>. See also C<L</PUSHs>>, C<L</XPUSHmortal>> and
268C<L</XPUSHs>>.
d82b684c
SH
269
270=for apidoc Am|void|mPUSHp|char* str|STRLEN len
271Push a string onto the stack. The stack must have room for this element.
121b7712 272The C<len> indicates the length of the string. Does not use C<TARG>.
fbe13c60 273See also C<L</PUSHp>>, C<L</mXPUSHp>> and C<L</XPUSHp>>.
d82b684c
SH
274
275=for apidoc Am|void|mPUSHn|NV nv
276Push a double onto the stack. The stack must have room for this element.
fbe13c60 277Does not use C<TARG>. See also C<L</PUSHn>>, C<L</mXPUSHn>> and C<L</XPUSHn>>.
d82b684c
SH
278
279=for apidoc Am|void|mPUSHi|IV iv
280Push an integer onto the stack. The stack must have room for this element.
fbe13c60 281Does not use C<TARG>. See also C<L</PUSHi>>, C<L</mXPUSHi>> and C<L</XPUSHi>>.
d82b684c
SH
282
283=for apidoc Am|void|mPUSHu|UV uv
284Push an unsigned integer onto the stack. The stack must have room for this
fbe13c60
KW
285element. Does not use C<TARG>. See also C<L</PUSHu>>, C<L</mXPUSHu>> and
286C<L</XPUSHu>>.
d82b684c 287
6e449a3a
MHM
288=for apidoc Am|void|mXPUSHs|SV* sv
289Push an SV onto the stack, extending the stack if necessary and mortalizes
fbe13c60 290the SV. Does not use C<TARG>. See also C<L</XPUSHs>> and C<L</mPUSHs>>.
6e449a3a 291
d82b684c 292=for apidoc Am|void|XPUSHmortal
121b7712 293Push a new mortal SV onto the stack, extending the stack if necessary.
fbe13c60
KW
294Does not use C<TARG>. See also C<L</XPUSHs>>, C<L</PUSHmortal>> and
295C<L</PUSHs>>.
d82b684c
SH
296
297=for apidoc Am|void|mXPUSHp|char* str|STRLEN len
298Push a string onto the stack, extending the stack if necessary. The C<len>
fbe13c60
KW
299indicates the length of the string. Does not use C<TARG>. See also
300C<L</XPUSHp>>, C<mPUSHp> and C<PUSHp>.
d82b684c
SH
301
302=for apidoc Am|void|mXPUSHn|NV nv
121b7712 303Push a double onto the stack, extending the stack if necessary.
fbe13c60 304Does not use C<TARG>. See also C<L</XPUSHn>>, C<L</mPUSHn>> and C<L</PUSHn>>.
d82b684c
SH
305
306=for apidoc Am|void|mXPUSHi|IV iv
121b7712 307Push an integer onto the stack, extending the stack if necessary.
fbe13c60 308Does not use C<TARG>. See also C<L</XPUSHi>>, C<L</mPUSHi>> and C<L</PUSHi>>.
d82b684c
SH
309
310=for apidoc Am|void|mXPUSHu|UV uv
311Push an unsigned integer onto the stack, extending the stack if necessary.
fbe13c60 312Does not use C<TARG>. See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
954c1994
GS
313
314=cut
315*/
316
6768377c
DM
317/* _EXTEND_SAFE_N(n): private helper macro for EXTEND().
318 * Tests whether the value of n would be truncated when implicitly cast to
319 * SSize_t as an arg to stack_grow(). If so, sets it to -1 instead to
320 * trigger a panic. It will be constant folded on platforms where this
321 * can't happen.
322 */
323
324#define _EXTEND_SAFE_N(n) \
325 (sizeof(n) > sizeof(SSize_t) && ((SSize_t)(n) != (n)) ? -1 : (n))
326
865e3ae0 327#ifdef STRESS_REALLOC
aad79b33 328# define EXTEND(p,n) STMT_START { \
6768377c 329 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
aad79b33 330 PERL_UNUSED_VAR(sp); \
8094bfa4 331 } STMT_END
865e3ae0 332/* Same thing, but update mark register too. */
aad79b33 333# define MEXTEND(p,n) STMT_START { \
ff36bb50 334 const SSize_t markoff = mark - PL_stack_base; \
6768377c 335 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
aad79b33
JH
336 mark = PL_stack_base + markoff; \
337 PERL_UNUSED_VAR(sp); \
338 } STMT_END
865e3ae0 339#else
6768377c
DM
340
341/* _EXTEND_NEEDS_GROW(p,n): private helper macro for EXTEND().
342 * Tests to see whether n is too big and we need to grow the stack. Be
343 * very careful if modifying this. There are many ways to get things wrong
344 * (wrapping, truncating etc) that could cause a false negative and cause
345 * the call to stack_grow() to be skipped. On the other hand, false
346 * positives are safe.
347 * Bear in mind that sizeof(p) may be less than, equal to, or greater
348 * than sizeof(n), and while n is documented to be signed, someone might
349 * pass an unsigned value or expression. In general don't use casts to
350 * avoid warnings; instead expect the caller to fix their code.
351 * It is legal for p to be greater than PL_stack_max.
352 * If the allocated stack is already very large but current usage is
353 * small, then PL_stack_max - p might wrap round to a negative value, but
354 * this just gives a safe false positive
355 */
356
357# define _EXTEND_NEEDS_GROW(p,n) ( (n) < 0 || PL_stack_max - p < (n))
358
359# define EXTEND(p,n) STMT_START { \
360 if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) { \
361 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
aad79b33
JH
362 PERL_UNUSED_VAR(sp); \
363 } } STMT_END
79072805 364/* Same thing, but update mark register too. */
6768377c
DM
365# define MEXTEND(p,n) STMT_START { \
366 if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) { \
367 const SSize_t markoff = mark - PL_stack_base;\
368 sp = stack_grow(sp,p,_EXTEND_SAFE_N(n)); \
aad79b33
JH
369 mark = PL_stack_base + markoff; \
370 PERL_UNUSED_VAR(sp); \
371 } } STMT_END
865e3ae0 372#endif
79072805
LW
373
374#define PUSHs(s) (*++sp = (s))
86547924
PP
375#define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
376#define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
65202027 377#define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
86547924 378#define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
55497cff 379#define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
79072805 380
0acfb02f 381#define XPUSHs(s) STMT_START { EXTEND(sp,1); *++sp = (s); } STMT_END
86547924
PP
382#define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
383#define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
65202027 384#define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
86547924 385#define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
55497cff 386#define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
b162f9ea 387#define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
79072805 388
6e449a3a 389#define mPUSHs(s) PUSHs(sv_2mortal(s))
2cc7004b 390#define PUSHmortal PUSHs(sv_newmortal())
8f14ea01 391#define mPUSHp(p,l) PUSHs(newSVpvn_flags((p), (l), SVs_TEMP))
121b7712
MHM
392#define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n))
393#define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i))
394#define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u))
2cc7004b 395
6e449a3a 396#define mXPUSHs(s) XPUSHs(sv_2mortal(s))
2cc7004b 397#define XPUSHmortal XPUSHs(sv_newmortal())
8f14ea01 398#define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); mPUSHp((p), (l)); } STMT_END
121b7712
MHM
399#define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END
400#define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END
401#define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END
d82b684c 402
79072805 403#define SETs(s) (*sp = s)
86547924
PP
404#define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
405#define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
65202027 406#define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
86547924 407#define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
55497cff 408#define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
a0d0e21e 409
79072805
LW
410#define dTOPss SV *sv = TOPs
411#define dPOPss SV *sv = POPs
65202027
DS
412#define dTOPnv NV value = TOPn
413#define dPOPnv NV value = POPn
6f1401dc 414#define dPOPnv_nomg NV value = (sp--, SvNV_nomg(TOPp1s))
a0d0e21e
LW
415#define dTOPiv IV value = TOPi
416#define dPOPiv IV value = POPi
55497cff
PP
417#define dTOPuv UV value = TOPu
418#define dPOPuv UV value = POPu
79072805 419
7a4c00b4 420#define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
65202027 421#define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
7a4c00b4
PP
422#define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
423
424#define USE_LEFT(sv) \
6b349a5c 425 (SvOK(sv) || !(PL_op->op_flags & OPf_STACKED))
6f1401dc 426#define dPOPXiirl_ul_nomg(X) \
096c060c 427 IV right = (sp--, SvIV_nomg(TOPp1s)); \
6f1401dc 428 SV *leftsv = CAT2(X,s); \
096c060c 429 IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0
7a4c00b4
PP
430
431#define dPOPPOPssrl dPOPXssrl(POP)
432#define dPOPPOPnnrl dPOPXnnrl(POP)
7a4c00b4 433#define dPOPPOPiirl dPOPXiirl(POP)
7a4c00b4
PP
434
435#define dPOPTOPssrl dPOPXssrl(TOP)
436#define dPOPTOPnnrl dPOPXnnrl(TOP)
6f1401dc
DM
437#define dPOPTOPnnrl_nomg \
438 NV right = SvNV_nomg(TOPs); NV left = (sp--, SvNV_nomg(TOPs))
7a4c00b4 439#define dPOPTOPiirl dPOPXiirl(TOP)
6f1401dc
DM
440#define dPOPTOPiirl_ul_nomg dPOPXiirl_ul_nomg(TOP)
441#define dPOPTOPiirl_nomg \
096c060c 442 IV right = SvIV_nomg(TOPs); IV left = (sp--, SvIV_nomg(TOPs))
79072805 443
3280af22
NIS
444#define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
445#define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
446#define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
79072805 447
3280af22
NIS
448#define RETSETYES RETURNX(SETs(&PL_sv_yes))
449#define RETSETNO RETURNX(SETs(&PL_sv_no))
450#define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
5d01050a 451#define RETSETTARG STMT_START { SETTARG; RETURN; } STMT_END
79072805 452
533c011a 453#define ARGTARG PL_op->op_targ
b162f9ea 454
f3574cc6 455#define MAXARG (PL_op->op_private & OPpARG4_MASK)
79072805 456
e336de0d
GS
457#define SWITCHSTACK(f,t) \
458 STMT_START { \
677b06e3 459 AvFILLp(f) = sp - PL_stack_base; \
3280af22 460 PL_stack_base = AvARRAY(t); \
677b06e3 461 PL_stack_max = PL_stack_base + AvMAX(t); \
3280af22 462 sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
677b06e3 463 PL_curstack = t; \
e336de0d 464 } STMT_END
79072805 465
bbce6d69 466#define EXTEND_MORTAL(n) \
a953aca5
DD
467 STMT_START { \
468 SSize_t eMiX = PL_tmps_ix + (n); \
469 if (UNLIKELY(eMiX >= PL_tmps_max)) \
dc9a870f 470 (void)Perl_tmps_grow_p(aTHX_ eMiX); \
677b06e3 471 } STMT_END
bbce6d69 472
a0d0e21e
LW
473#define AMGf_noright 1
474#define AMGf_noleft 2
475#define AMGf_assign 4
476#define AMGf_unary 8
6f1401dc
DM
477#define AMGf_numeric 0x10 /* for Perl_try_amagic_bin */
478#define AMGf_set 0x20 /* for Perl_try_amagic_bin */
67288365 479#define AMGf_want_list 0x40
636ac8fc 480#define AMGf_numarg 0x80
6f1401dc
DM
481
482
483/* do SvGETMAGIC on the stack args before checking for overload */
484
485#define tryAMAGICun_MG(method, flags) STMT_START { \
5d9574c1 486 if ( UNLIKELY((SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG))) \
6f1401dc
DM
487 && Perl_try_amagic_un(aTHX_ method, flags)) \
488 return NORMAL; \
489 } STMT_END
490#define tryAMAGICbin_MG(method, flags) STMT_START { \
5d9574c1 491 if ( UNLIKELY(((SvFLAGS(TOPm1s)|SvFLAGS(TOPs)) & (SVf_ROK|SVs_GMG))) \
6f1401dc
DM
492 && Perl_try_amagic_bin(aTHX_ method, flags)) \
493 return NORMAL; \
494 } STMT_END
495
31d632c3
DM
496#define AMG_CALLunary(sv,meth) \
497 amagic_call(sv,&PL_sv_undef, meth, AMGf_noright | AMGf_unary)
498
499/* No longer used in core. Use AMG_CALLunary instead */
500#define AMG_CALLun(sv,meth) AMG_CALLunary(sv, CAT2(meth,_amg))
a0d0e21e 501
fc99edcf 502#define tryAMAGICunTARGETlist(meth, jump) \
9f39b4f1 503 STMT_START { \
b5c08826
DM
504 dSP; \
505 SV *tmpsv; \
fc99edcf 506 SV *arg= *sp; \
67288365 507 int gimme = GIMME_V; \
5d9574c1 508 if (UNLIKELY(SvAMAGIC(arg) && \
b5c08826 509 (tmpsv = amagic_call(arg, &PL_sv_undef, meth, \
05fbd38d 510 AMGf_want_list | AMGf_noright \
5d9574c1
DM
511 |AMGf_unary)))) \
512 { \
b5c08826 513 SPAGAIN; \
67288365 514 if (gimme == G_VOID) { \
898c5644 515 NOOP; \
67288365 516 } \
05fbd38d 517 else if (gimme == G_ARRAY) { \
c70927a6
FC
518 SSize_t i; \
519 SSize_t len; \
67288365 520 assert(SvTYPE(tmpsv) == SVt_PVAV); \
b9f2b683 521 len = av_tindex((AV *)tmpsv) + 1; \
67288365
JL
522 (void)POPs; /* get rid of the arg */ \
523 EXTEND(sp, len); \
524 for (i = 0; i < len; ++i) \
525 PUSHs(av_shift((AV *)tmpsv)); \
526 } \
527 else { /* AMGf_want_scalar */ \
528 dATARGET; /* just use the arg's location */ \
529 sv_setsv(TARG, tmpsv); \
530 if (opASSIGN) \
531 sp--; \
532 SETTARG; \
533 } \
b5c08826
DM
534 PUTBACK; \
535 if (jump) { \
86e5639b
GG
536 OP *jump_o = NORMAL->op_next; \
537 while (jump_o->op_type == OP_NULL) \
538 jump_o = jump_o->op_next; \
539 assert(jump_o->op_type == OP_ENTERSUB); \
6cae08a8 540 POPMARK; \
86e5639b 541 return jump_o->op_next; \
9f39b4f1 542 } \
b5c08826
DM
543 return NORMAL; \
544 } \
9f39b4f1
NC
545 } STMT_END
546
8897dcaa
NC
547/* This is no longer used anywhere in the core. You might wish to consider
548 calling amagic_deref_call() directly, as it has a cleaner interface. */
549#define tryAMAGICunDEREF(meth) \
9f39b4f1 550 STMT_START { \
e89bfaa6 551 sv = amagic_deref_call(*sp, CAT2(meth,_amg)); \
25a9ffce 552 SPAGAIN; \
16e7e110 553 } STMT_END
e8c20960 554
180b7b9b 555
533c011a 556#define opASSIGN (PL_op->op_flags & OPf_STACKED)
a0d0e21e 557
78f9721b
SM
558/*
559=for apidoc mU||LVRET
560True if this op will be the return value of an lvalue subroutine
561
562=cut */
9d96b2e7 563#define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
1b6737cc 564
d30e492c
VP
565#define SvCANEXISTDELETE(sv) \
566 (!SvRMAGICAL(sv) \
2c5f48c2
FC
567 || !(mg = mg_find((const SV *) sv, PERL_MAGIC_tied)) \
568 || ( (stash = SvSTASH(SvRV(SvTIED_obj(MUTABLE_SV(sv), mg)))) \
d30e492c
VP
569 && gv_fetchmethod_autoload(stash, "EXISTS", TRUE) \
570 && gv_fetchmethod_autoload(stash, "DELETE", TRUE) \
571 ) \
572 )
573
d682515d 574#ifdef PERL_CORE
557fbd17 575
d682515d
NC
576/* These are just for Perl_tied_method(), which is not part of the public API.
577 Use 0x04 rather than the next available bit, to help the compiler if the
578 architecture can generate more efficient instructions. */
579# define TIED_METHOD_MORTALIZE_NOT_NEEDED 0x04
580# define TIED_METHOD_ARGUMENTS_ON_STACK 0x08
94bc412f 581# define TIED_METHOD_SAY 0x10
557fbd17
FC
582
583/* Used in various places that need to dereference a glob or globref */
094a3eec 584# define MAYBE_DEREF_GV_flags(sv,phlags) \
557fbd17 585 ( \
094a3eec 586 (void)(phlags & SV_GMAGIC && (SvGETMAGIC(sv),0)), \
557fbd17 587 isGV_with_GP(sv) \
4e794a06 588 ? (GV *)(sv) \
f8afbfa6
FC
589 : SvROK(sv) && SvTYPE(SvRV(sv)) <= SVt_PVLV && \
590 (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv))) \
557fbd17
FC
591 ? (GV *)SvRV(sv) \
592 : NULL \
593 )
094a3eec
FC
594# define MAYBE_DEREF_GV(sv) MAYBE_DEREF_GV_flags(sv,SV_GMAGIC)
595# define MAYBE_DEREF_GV_nomg(sv) MAYBE_DEREF_GV_flags(sv,0)
557fbd17 596
db4cf31d 597# define FIND_RUNCV_padid_eq 1
b4b0692a 598# define FIND_RUNCV_level_eq 2
70794f7b 599
d682515d
NC
600#endif
601
1b6737cc 602/*
14d04a33 603 * ex: set ts=8 sts=4 sw=4 et:
1b6737cc 604 */