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