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