This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #113812] Always use find_runcv when cloning a sub
[perl5.git] / pp.h
CommitLineData
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
GS
16=for apidoc AmU||SP
17Stack pointer. This is usually handled by C<xsubpp>. See C<dSP> and
18C<SPAGAIN>.
19
20=for apidoc AmU||MARK
21Stack marker variable for the XSUB. See C<dMARK>.
22
c578083c 23=for apidoc Am|void|PUSHMARK|SP
954c1994
GS
24Opening bracket for arguments on a callback. See C<PUTBACK> and
25L<perlcall>.
26
27=for apidoc Ams||dSP
28Declares a local copy of perl's stack pointer for the XSUB, available via
29the C<SP> macro. See C<SP>.
30
fac3506f
MS
31=for apidoc ms||djSP
32
33Declare Just C<SP>. This is actually identical to C<dSP>, and declares
34a local copy of perl's stack pointer, available via the C<SP> macro.
35See C<SP>. (Available for backward source code compatibility with the
36old (Perl 5.005) thread model.)
37
954c1994
GS
38=for apidoc Ams||dMARK
39Declare a stack marker variable, C<mark>, for the XSUB. See C<MARK> and
40C<dORIGMARK>.
41
42=for apidoc Ams||dORIGMARK
43Saves the original stack mark for the XSUB. See C<ORIGMARK>.
44
45=for apidoc AmU||ORIGMARK
46The original stack mark for the XSUB. See C<dORIGMARK>.
47
48=for apidoc Ams||SPAGAIN
49Refetch 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
16e7e110
TH
58#define PUSHMARK(p) \
59 STMT_START { \
60 if (++PL_markstack_ptr == PL_markstack_max) \
61 markstack_grow(); \
514696af 62 *PL_markstack_ptr = (I32)((p) - PL_stack_base);\
16e7e110 63 } STMT_END
a0d0e21e 64
3280af22
NIS
65#define TOPMARK (*PL_markstack_ptr)
66#define POPMARK (*PL_markstack_ptr--)
a0d0e21e 67
bc0d193f 68#define dSP SV **sp = PL_stack_sp
39644a26 69#define djSP dSP
3280af22 70#define dMARK register SV **mark = PL_stack_base + POPMARK
514696af 71#define dORIGMARK const I32 origmark = (I32)(mark - PL_stack_base)
3280af22 72#define ORIGMARK (PL_stack_base + origmark)
79072805 73
3280af22 74#define SPAGAIN sp = PL_stack_sp
16e7e110 75#define MSPAGAIN STMT_START { sp = PL_stack_sp; mark = ORIGMARK; } STMT_END
79072805 76
533c011a 77#define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
79072805
LW
78#define dTARGETSTACKED SV * GETTARGETSTACKED
79
533c011a 80#define GETTARGET targ = PAD_SV(PL_op->op_targ)
79072805
LW
81#define dTARGET SV * GETTARGET
82
533c011a 83#define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
79072805
LW
84#define dATARGET SV * GETATARGET
85
86#define dTARG SV *targ
87
533c011a 88#define NORMAL PL_op->op_next
9fed9930 89#define DIE return Perl_die
79072805 90
954c1994
GS
91/*
92=for apidoc Ams||PUTBACK
93Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
94See C<PUSHMARK> and L<perlcall> for other uses.
95
96=for apidoc Amn|SV*|POPs
97Pops an SV off the stack.
98
99=for apidoc Amn|char*|POPp
8c074e2a 100Pops a string off the stack. Deprecated. New code should use POPpx.
595ae481
NIS
101
102=for apidoc Amn|char*|POPpx
954c1994 103Pops a string off the stack.
595ae481
NIS
104
105=for apidoc Amn|char*|POPpbytex
106Pops a string off the stack which must consist of bytes i.e. characters < 256.
954c1994
GS
107
108=for apidoc Amn|NV|POPn
109Pops a double off the stack.
110
111=for apidoc Amn|IV|POPi
112Pops an integer off the stack.
113
114=for apidoc Amn|long|POPl
115Pops a long off the stack.
116
117=cut
118*/
119
3280af22 120#define PUTBACK PL_stack_sp = sp
8a67133a
NC
121#define RETURN return (PUTBACK, NORMAL)
122#define RETURNOP(o) return (PUTBACK, o)
123#define RETURNX(x) return (x, PUTBACK, NORMAL)
79072805
LW
124
125#define POPs (*sp--)
2d8e6c8d 126#define POPp (SvPVx(POPs, PL_na)) /* deprecated */
8c074e2a
NC
127#define POPpx (SvPVx_nolen(POPs))
128#define POPpconstx (SvPVx_nolen_const(POPs))
129#define POPpbytex (SvPVbytex_nolen(POPs))
463ee0b2 130#define POPn (SvNVx(POPs))
a0d0e21e 131#define POPi ((IV)SvIVx(POPs))
ff68c719 132#define POPu ((UV)SvUVx(POPs))
463ee0b2 133#define POPl ((long)SvIVx(POPs))
d9b3e12d 134#define POPul ((unsigned long)SvIVx(POPs))
1b8cd678 135#ifdef HAS_QUAD
d9b3e12d 136#define POPq ((Quad_t)SvIVx(POPs))
c5a0f51a 137#define POPuq ((Uquad_t)SvUVx(POPs))
d9b3e12d 138#endif
79072805
LW
139
140#define TOPs (*sp)
56370e9f 141#define TOPm1s (*(sp-1))
7dca457a 142#define TOPp1s (*(sp+1))
2d8e6c8d 143#define TOPp (SvPV(TOPs, PL_na)) /* deprecated */
95fad918 144#define TOPpx (SvPV_nolen(TOPs))
463ee0b2 145#define TOPn (SvNV(TOPs))
a0d0e21e 146#define TOPi ((IV)SvIV(TOPs))
ff68c719 147#define TOPu ((UV)SvUV(TOPs))
463ee0b2 148#define TOPl ((long)SvIV(TOPs))
c5a0f51a 149#define TOPul ((unsigned long)SvUV(TOPs))
1b8cd678 150#ifdef HAS_QUAD
d9b3e12d 151#define TOPq ((Quad_t)SvIV(TOPs))
c5a0f51a 152#define TOPuq ((Uquad_t)SvUV(TOPs))
d9b3e12d 153#endif
79072805
LW
154
155/* Go to some pains in the rare event that we must extend the stack. */
954c1994
GS
156
157/*
158=for apidoc Am|void|EXTEND|SP|int nitems
159Used to extend the argument stack for an XSUB's return values. Once
4375e838 160used, guarantees that there is room for at least C<nitems> to be pushed
954c1994
GS
161onto the stack.
162
163=for apidoc Am|void|PUSHs|SV* sv
aacdac46 164Push an SV onto the stack. The stack must have room for this element.
d82b684c
SH
165Does not handle 'set' magic. Does not use C<TARG>. See also C<PUSHmortal>,
166C<XPUSHs> and C<XPUSHmortal>.
954c1994
GS
167
168=for apidoc Am|void|PUSHp|char* str|STRLEN len
169Push a string onto the stack. The stack must have room for this element.
d82b684c
SH
170The C<len> indicates the length of the string. Handles 'set' magic. Uses
171C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it. Do not
172call multiple C<TARG>-oriented macros to return lists from XSUB's - see
173C<mPUSHp> instead. See also C<XPUSHp> and C<mXPUSHp>.
954c1994
GS
174
175=for apidoc Am|void|PUSHn|NV nv
176Push a double onto the stack. The stack must have room for this element.
d82b684c
SH
177Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
178called to declare it. Do not call multiple C<TARG>-oriented macros to
179return lists from XSUB's - see C<mPUSHn> instead. See also C<XPUSHn> and
180C<mXPUSHn>.
954c1994
GS
181
182=for apidoc Am|void|PUSHi|IV iv
183Push an integer onto the stack. The stack must have room for this element.
d82b684c
SH
184Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
185called to declare it. Do not call multiple C<TARG>-oriented macros to
186return lists from XSUB's - see C<mPUSHi> instead. See also C<XPUSHi> and
187C<mXPUSHi>.
954c1994
GS
188
189=for apidoc Am|void|PUSHu|UV uv
190Push an unsigned integer onto the stack. The stack must have room for this
d82b684c
SH
191element. Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
192should be called to declare it. Do not call multiple C<TARG>-oriented
193macros to return lists from XSUB's - see C<mPUSHu> instead. See also
194C<XPUSHu> and C<mXPUSHu>.
954c1994
GS
195
196=for apidoc Am|void|XPUSHs|SV* sv
197Push an SV onto the stack, extending the stack if necessary. Does not
d82b684c
SH
198handle 'set' magic. Does not use C<TARG>. See also C<XPUSHmortal>,
199C<PUSHs> and C<PUSHmortal>.
954c1994
GS
200
201=for apidoc Am|void|XPUSHp|char* str|STRLEN len
202Push a string onto the stack, extending the stack if necessary. The C<len>
d82b684c
SH
203indicates the length of the string. Handles 'set' magic. Uses C<TARG>, so
204C<dTARGET> or C<dXSTARG> should be called to declare it. Do not call
205multiple C<TARG>-oriented macros to return lists from XSUB's - see
206C<mXPUSHp> instead. See also C<PUSHp> and C<mPUSHp>.
954c1994
GS
207
208=for apidoc Am|void|XPUSHn|NV nv
209Push a double onto the stack, extending the stack if necessary. Handles
d82b684c
SH
210'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
211declare it. Do not call multiple C<TARG>-oriented macros to return lists
212from XSUB's - see C<mXPUSHn> instead. See also C<PUSHn> and C<mPUSHn>.
954c1994
GS
213
214=for apidoc Am|void|XPUSHi|IV iv
215Push an integer onto the stack, extending the stack if necessary. Handles
d82b684c
SH
216'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
217declare it. Do not call multiple C<TARG>-oriented macros to return lists
218from XSUB's - see C<mXPUSHi> instead. See also C<PUSHi> and C<mPUSHi>.
954c1994
GS
219
220=for apidoc Am|void|XPUSHu|UV uv
aacdac46 221Push an unsigned integer onto the stack, extending the stack if necessary.
d82b684c
SH
222Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
223called to declare it. Do not call multiple C<TARG>-oriented macros to
224return lists from XSUB's - see C<mXPUSHu> instead. See also C<PUSHu> and
225C<mPUSHu>.
226
6e449a3a
MHM
227=for apidoc Am|void|mPUSHs|SV* sv
228Push an SV onto the stack and mortalizes the SV. The stack must have room
121b7712 229for this element. Does not use C<TARG>. See also C<PUSHs> and C<mXPUSHs>.
6e449a3a 230
d82b684c
SH
231=for apidoc Am|void|PUSHmortal
232Push a new mortal SV onto the stack. The stack must have room for this
121b7712 233element. Does not use C<TARG>. See also C<PUSHs>, C<XPUSHmortal> and C<XPUSHs>.
d82b684c
SH
234
235=for apidoc Am|void|mPUSHp|char* str|STRLEN len
236Push a string onto the stack. The stack must have room for this element.
121b7712
MHM
237The C<len> indicates the length of the string. Does not use C<TARG>.
238See also C<PUSHp>, C<mXPUSHp> and C<XPUSHp>.
d82b684c
SH
239
240=for apidoc Am|void|mPUSHn|NV nv
241Push a double onto the stack. The stack must have room for this element.
121b7712 242Does not use C<TARG>. See also C<PUSHn>, C<mXPUSHn> and C<XPUSHn>.
d82b684c
SH
243
244=for apidoc Am|void|mPUSHi|IV iv
245Push an integer onto the stack. The stack must have room for this element.
121b7712 246Does not use C<TARG>. See also C<PUSHi>, C<mXPUSHi> and C<XPUSHi>.
d82b684c
SH
247
248=for apidoc Am|void|mPUSHu|UV uv
249Push an unsigned integer onto the stack. The stack must have room for this
121b7712 250element. Does not use C<TARG>. See also C<PUSHu>, C<mXPUSHu> and C<XPUSHu>.
d82b684c 251
6e449a3a
MHM
252=for apidoc Am|void|mXPUSHs|SV* sv
253Push an SV onto the stack, extending the stack if necessary and mortalizes
121b7712 254the SV. Does not use C<TARG>. See also C<XPUSHs> and C<mPUSHs>.
6e449a3a 255
d82b684c 256=for apidoc Am|void|XPUSHmortal
121b7712
MHM
257Push a new mortal SV onto the stack, extending the stack if necessary.
258Does not use C<TARG>. See also C<XPUSHs>, C<PUSHmortal> and C<PUSHs>.
d82b684c
SH
259
260=for apidoc Am|void|mXPUSHp|char* str|STRLEN len
261Push a string onto the stack, extending the stack if necessary. The C<len>
121b7712
MHM
262indicates the length of the string. Does not use C<TARG>. See also C<XPUSHp>,
263C<mPUSHp> and C<PUSHp>.
d82b684c
SH
264
265=for apidoc Am|void|mXPUSHn|NV nv
121b7712
MHM
266Push a double onto the stack, extending the stack if necessary.
267Does not use C<TARG>. See also C<XPUSHn>, C<mPUSHn> and C<PUSHn>.
d82b684c
SH
268
269=for apidoc Am|void|mXPUSHi|IV iv
121b7712
MHM
270Push an integer onto the stack, extending the stack if necessary.
271Does not use C<TARG>. See also C<XPUSHi>, C<mPUSHi> and C<PUSHi>.
d82b684c
SH
272
273=for apidoc Am|void|mXPUSHu|UV uv
274Push an unsigned integer onto the stack, extending the stack if necessary.
121b7712 275Does not use C<TARG>. See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>.
954c1994
GS
276
277=cut
278*/
279
8d7906e1
FC
280#define EXTEND(p,n) (void)(PL_stack_max - p < (int)(n) && \
281 (sp = stack_grow(sp,p, (int) (n))))
a0d0e21e 282
79072805 283/* Same thing, but update mark register too. */
1b6737cc
AL
284#define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (int)(n)) { \
285 const int markoff = mark - PL_stack_base; \
bbce6d69 286 sp = stack_grow(sp,p,(int) (n)); \
3280af22 287 mark = PL_stack_base + markoff; \
86547924 288 } } STMT_END
79072805
LW
289
290#define PUSHs(s) (*++sp = (s))
86547924
PP
291#define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
292#define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
65202027 293#define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
86547924 294#define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
55497cff 295#define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
79072805 296
8d7906e1 297#define XPUSHs(s) (EXTEND(sp,1), *++sp = (s))
86547924
PP
298#define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
299#define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
65202027 300#define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
86547924 301#define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
55497cff 302#define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
b162f9ea 303#define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
79072805 304
6e449a3a 305#define mPUSHs(s) PUSHs(sv_2mortal(s))
2cc7004b 306#define PUSHmortal PUSHs(sv_newmortal())
8f14ea01 307#define mPUSHp(p,l) PUSHs(newSVpvn_flags((p), (l), SVs_TEMP))
121b7712
MHM
308#define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n))
309#define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i))
310#define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u))
2cc7004b 311
6e449a3a 312#define mXPUSHs(s) XPUSHs(sv_2mortal(s))
2cc7004b 313#define XPUSHmortal XPUSHs(sv_newmortal())
8f14ea01 314#define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); mPUSHp((p), (l)); } STMT_END
121b7712
MHM
315#define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END
316#define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END
317#define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END
d82b684c 318
79072805 319#define SETs(s) (*sp = s)
86547924
PP
320#define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
321#define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
65202027 322#define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
86547924 323#define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
55497cff 324#define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
a0d0e21e 325
79072805
LW
326#define dTOPss SV *sv = TOPs
327#define dPOPss SV *sv = POPs
65202027
DS
328#define dTOPnv NV value = TOPn
329#define dPOPnv NV value = POPn
6f1401dc 330#define dPOPnv_nomg NV value = (sp--, SvNV_nomg(TOPp1s))
a0d0e21e
LW
331#define dTOPiv IV value = TOPi
332#define dPOPiv IV value = POPi
55497cff
PP
333#define dTOPuv UV value = TOPu
334#define dPOPuv UV value = POPu
1b8cd678 335#ifdef HAS_QUAD
2d4389e4
JH
336#define dTOPqv Quad_t value = TOPu
337#define dPOPqv Quad_t value = POPu
338#define dTOPuqv Uquad_t value = TOPuq
339#define dPOPuqv Uquad_t value = POPuq
340#endif
79072805 341
7a4c00b4 342#define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
65202027 343#define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
7a4c00b4
PP
344#define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
345
346#define USE_LEFT(sv) \
6b349a5c 347 (SvOK(sv) || !(PL_op->op_flags & OPf_STACKED))
6f1401dc 348#define dPOPXiirl_ul_nomg(X) \
096c060c 349 IV right = (sp--, SvIV_nomg(TOPp1s)); \
6f1401dc 350 SV *leftsv = CAT2(X,s); \
096c060c 351 IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0
7a4c00b4
PP
352
353#define dPOPPOPssrl dPOPXssrl(POP)
354#define dPOPPOPnnrl dPOPXnnrl(POP)
7a4c00b4 355#define dPOPPOPiirl dPOPXiirl(POP)
7a4c00b4
PP
356
357#define dPOPTOPssrl dPOPXssrl(TOP)
358#define dPOPTOPnnrl dPOPXnnrl(TOP)
6f1401dc
DM
359#define dPOPTOPnnrl_nomg \
360 NV right = SvNV_nomg(TOPs); NV left = (sp--, SvNV_nomg(TOPs))
7a4c00b4 361#define dPOPTOPiirl dPOPXiirl(TOP)
6f1401dc
DM
362#define dPOPTOPiirl_ul_nomg dPOPXiirl_ul_nomg(TOP)
363#define dPOPTOPiirl_nomg \
096c060c 364 IV right = SvIV_nomg(TOPs); IV left = (sp--, SvIV_nomg(TOPs))
79072805 365
3280af22
NIS
366#define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
367#define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
368#define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
79072805 369
3280af22
NIS
370#define RETSETYES RETURNX(SETs(&PL_sv_yes))
371#define RETSETNO RETURNX(SETs(&PL_sv_no))
372#define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
79072805 373
533c011a 374#define ARGTARG PL_op->op_targ
b162f9ea
IZ
375
376 /* See OPpTARGET_MY: */
377#define MAXARG (PL_op->op_private & 15)
79072805 378
e336de0d
GS
379#define SWITCHSTACK(f,t) \
380 STMT_START { \
677b06e3 381 AvFILLp(f) = sp - PL_stack_base; \
3280af22 382 PL_stack_base = AvARRAY(t); \
677b06e3 383 PL_stack_max = PL_stack_base + AvMAX(t); \
3280af22 384 sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
677b06e3 385 PL_curstack = t; \
e336de0d 386 } STMT_END
79072805 387
bbce6d69 388#define EXTEND_MORTAL(n) \
677b06e3
GS
389 STMT_START { \
390 if (PL_tmps_ix + (n) >= PL_tmps_max) \
391 tmps_grow(n); \
392 } STMT_END
bbce6d69 393
a0d0e21e
LW
394#define AMGf_noright 1
395#define AMGf_noleft 2
396#define AMGf_assign 4
397#define AMGf_unary 8
6f1401dc
DM
398#define AMGf_numeric 0x10 /* for Perl_try_amagic_bin */
399#define AMGf_set 0x20 /* for Perl_try_amagic_bin */
67288365 400#define AMGf_want_list 0x40
6f1401dc
DM
401
402
403/* do SvGETMAGIC on the stack args before checking for overload */
404
405#define tryAMAGICun_MG(method, flags) STMT_START { \
406 if ( (SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG)) \
407 && Perl_try_amagic_un(aTHX_ method, flags)) \
408 return NORMAL; \
409 } STMT_END
410#define tryAMAGICbin_MG(method, flags) STMT_START { \
411 if ( ((SvFLAGS(TOPm1s)|SvFLAGS(TOPs)) & (SVf_ROK|SVs_GMG)) \
412 && Perl_try_amagic_bin(aTHX_ method, flags)) \
413 return NORMAL; \
414 } STMT_END
415
31d632c3
DM
416#define AMG_CALLunary(sv,meth) \
417 amagic_call(sv,&PL_sv_undef, meth, AMGf_noright | AMGf_unary)
418
419/* No longer used in core. Use AMG_CALLunary instead */
420#define AMG_CALLun(sv,meth) AMG_CALLunary(sv, CAT2(meth,_amg))
a0d0e21e 421
67288365
JL
422#define tryAMAGICunTARGET(meth, shift, jump) \
423 tryAMAGICunTARGET_flags(meth, shift, jump, 0)
424#define tryAMAGICunTARGETlist(meth, shift, jump) \
425 tryAMAGICunTARGET_flags(meth, shift, jump, AMGf_want_list)
426#define tryAMAGICunTARGET_flags(meth, shift, jump, flags) \
9f39b4f1 427 STMT_START { \
b5c08826
DM
428 dSP; \
429 SV *tmpsv; \
430 SV *arg= sp[shift]; \
67288365 431 int gimme = GIMME_V; \
b5c08826
DM
432 if (SvAMAGIC(arg) && \
433 (tmpsv = amagic_call(arg, &PL_sv_undef, meth, \
67288365 434 flags | AMGf_noright | AMGf_unary))) { \
b5c08826
DM
435 SPAGAIN; \
436 sp += shift; \
67288365
JL
437 if (gimme == G_VOID) { \
438 (void)POPs; /* XXX ??? */ \
439 } \
440 else if ((flags & AMGf_want_list) && gimme == G_ARRAY) { \
441 int i; \
442 I32 len; \
443 assert(SvTYPE(tmpsv) == SVt_PVAV); \
444 len = av_len((AV *)tmpsv) + 1; \
445 (void)POPs; /* get rid of the arg */ \
446 EXTEND(sp, len); \
447 for (i = 0; i < len; ++i) \
448 PUSHs(av_shift((AV *)tmpsv)); \
449 } \
450 else { /* AMGf_want_scalar */ \
451 dATARGET; /* just use the arg's location */ \
452 sv_setsv(TARG, tmpsv); \
453 if (opASSIGN) \
454 sp--; \
455 SETTARG; \
456 } \
b5c08826
DM
457 PUTBACK; \
458 if (jump) { \
86e5639b
GG
459 OP *jump_o = NORMAL->op_next; \
460 while (jump_o->op_type == OP_NULL) \
461 jump_o = jump_o->op_next; \
462 assert(jump_o->op_type == OP_ENTERSUB); \
b5c08826 463 PL_markstack_ptr--; \
86e5639b 464 return jump_o->op_next; \
9f39b4f1 465 } \
b5c08826
DM
466 return NORMAL; \
467 } \
9f39b4f1
NC
468 } STMT_END
469
8897dcaa
NC
470/* This is no longer used anywhere in the core. You might wish to consider
471 calling amagic_deref_call() directly, as it has a cleaner interface. */
472#define tryAMAGICunDEREF(meth) \
9f39b4f1 473 STMT_START { \
e89bfaa6 474 sv = amagic_deref_call(*sp, CAT2(meth,_amg)); \
25a9ffce 475 SPAGAIN; \
16e7e110 476 } STMT_END
e8c20960 477
180b7b9b 478
533c011a 479#define opASSIGN (PL_op->op_flags & OPf_STACKED)
e9905555 480#define SETsv(sv) STMT_START { \
b162f9ea
IZ
481 if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY)) \
482 { sv_setsv(TARG, (sv)); SETTARG; } \
483 else SETs(sv); } STMT_END
484
485#define SETsvUN(sv) STMT_START { \
486 if (SvFLAGS(TARG) & SVs_PADMY) \
487 { sv_setsv(TARG, (sv)); SETTARG; } \
e9905555 488 else SETs(sv); } STMT_END
a0d0e21e 489
78f9721b
SM
490/*
491=for apidoc mU||LVRET
492True if this op will be the return value of an lvalue subroutine
493
494=cut */
9d96b2e7 495#define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
1b6737cc 496
d30e492c
VP
497#define SvCANEXISTDELETE(sv) \
498 (!SvRMAGICAL(sv) \
2c5f48c2
FC
499 || !(mg = mg_find((const SV *) sv, PERL_MAGIC_tied)) \
500 || ( (stash = SvSTASH(SvRV(SvTIED_obj(MUTABLE_SV(sv), mg)))) \
d30e492c
VP
501 && gv_fetchmethod_autoload(stash, "EXISTS", TRUE) \
502 && gv_fetchmethod_autoload(stash, "DELETE", TRUE) \
503 ) \
504 )
505
d682515d 506#ifdef PERL_CORE
557fbd17 507
d682515d
NC
508/* These are just for Perl_tied_method(), which is not part of the public API.
509 Use 0x04 rather than the next available bit, to help the compiler if the
510 architecture can generate more efficient instructions. */
511# define TIED_METHOD_MORTALIZE_NOT_NEEDED 0x04
512# define TIED_METHOD_ARGUMENTS_ON_STACK 0x08
94bc412f 513# define TIED_METHOD_SAY 0x10
557fbd17
FC
514
515/* Used in various places that need to dereference a glob or globref */
094a3eec 516# define MAYBE_DEREF_GV_flags(sv,phlags) \
557fbd17 517 ( \
094a3eec 518 (void)(phlags & SV_GMAGIC && (SvGETMAGIC(sv),0)), \
557fbd17 519 isGV_with_GP(sv) \
4e794a06 520 ? (GV *)(sv) \
f8afbfa6
FC
521 : SvROK(sv) && SvTYPE(SvRV(sv)) <= SVt_PVLV && \
522 (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv))) \
557fbd17
FC
523 ? (GV *)SvRV(sv) \
524 : NULL \
525 )
094a3eec
FC
526# define MAYBE_DEREF_GV(sv) MAYBE_DEREF_GV_flags(sv,SV_GMAGIC)
527# define MAYBE_DEREF_GV_nomg(sv) MAYBE_DEREF_GV_flags(sv,0)
557fbd17 528
d682515d
NC
529#endif
530
1b6737cc
AL
531/*
532 * Local variables:
533 * c-indentation-style: bsd
534 * c-basic-offset: 4
14d04a33 535 * indent-tabs-mode: nil
1b6737cc
AL
536 * End:
537 *
14d04a33 538 * ex: set ts=8 sts=4 sw=4 et:
1b6737cc 539 */