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