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