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