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