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