1 /* multicall.h (version 1.0)
3 * Implements a poor-man's MULTICALL interface for old versions
4 * of perl that don't offer a proper one. Intended to be compatible
5 * with 5.6.0 and later.
10 #define REAL_MULTICALL
14 /* In versions of perl where MULTICALL is not defined (i.e. prior
15 * to 5.9.4), Perl_pad_push is not exported either. It also has
16 * an extra argument in older versions; certainly in the 5.8 series.
17 * So we redefine it here.
22 # define AVf_REIFY SVpav_REIFY
24 # error Neither AVf_REIFY nor SVpav_REIFY is defined
29 # define AvFLAGS SvFLAGS
33 multicall_pad_push(pTHX_ AV *padlist, int depth)
35 if (depth <= AvFILLp(padlist))
39 SV** const svp = AvARRAY(padlist);
40 AV* const newpad = newAV();
41 SV** const oldpad = AvARRAY(svp[depth-1]);
42 I32 ix = AvFILLp((AV*)svp[1]);
43 const I32 names_fill = AvFILLp((AV*)svp[0]);
44 SV** const names = AvARRAY(svp[0]);
47 for ( ;ix > 0; ix--) {
48 if (names_fill >= ix && names[ix] != &PL_sv_undef) {
49 const char sigil = SvPVX(names[ix])[0];
50 if ((SvFLAGS(names[ix]) & SVf_FAKE) || sigil == '&') {
51 /* outer lexical or anon code */
52 av_store(newpad, ix, SvREFCNT_inc(oldpad[ix]));
54 else { /* our own lexical */
58 else if (sigil == '%')
62 av_store(newpad, ix, sv);
66 else if (IS_PADGV(oldpad[ix]) || IS_PADCONST(oldpad[ix])) {
67 av_store(newpad, ix, SvREFCNT_inc(oldpad[ix]));
70 /* save temporaries on recursion? */
71 SV * const sv = NEWSV(0, 0);
72 av_store(newpad, ix, sv);
78 av_store(newpad, 0, (SV*)av);
79 AvFLAGS(av) = AVf_REIFY;
81 av_store(padlist, depth, (SV*)newpad);
82 AvFILLp(padlist) = depth;
87 SV **newsp; /* set by POPBLOCK */ \
91 bool multicall_oldcatch; \
94 /* Between 5.9.1 and 5.9.2 the retstack was removed, and the
95 return op is now stored on the cxstack. */
96 #define HAS_RETSTACK (\
97 PERL_REVISION < 5 || \
98 (PERL_REVISION == 5 && PERL_VERSION < 9) || \
99 (PERL_REVISION == 5 && PERL_VERSION == 9 && PERL_SUBVERSION < 2) \
103 /* PUSHSUB is defined so differently on different versions of perl
104 * that it's easier to define our own version than code for all the
105 * different possibilities.
108 # define PUSHSUB_RETSTACK(cx)
110 # define PUSHSUB_RETSTACK(cx) cx->blk_sub.retop = Nullop;
113 #define PUSHSUB(cx) \
114 cx->blk_sub.cv = cv; \
115 cx->blk_sub.olddepth = CvDEPTH(cv); \
116 cx->blk_sub.hasargs = hasargs; \
117 cx->blk_sub.lval = PL_op->op_private & \
118 (OPpLVAL_INTRO|OPpENTERSUB_INARGS); \
119 PUSHSUB_RETSTACK(cx) \
120 if (!CvDEPTH(cv)) { \
121 (void)SvREFCNT_inc(cv); \
122 (void)SvREFCNT_inc(cv); \
126 #define PUSH_MULTICALL \
128 AV* padlist = CvPADLIST(cv); \
130 multicall_oldcatch = CATCH_GET; \
131 SAVESPTR(CvROOT(cv)->op_ppaddr); \
132 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL]; \
133 SAVETMPS; SAVEVPTR(PL_op); \
135 PUSHSTACKi(PERLSI_SORT); \
136 PUSHBLOCK(cx, CXt_SUB, PL_stack_sp); \
138 if (++CvDEPTH(cv) >= 2) { \
139 PERL_STACK_OVERFLOW_CHECK(); \
140 multicall_pad_push(aTHX_ padlist, CvDEPTH(cv)); \
143 PL_comppad = (AV*) (AvARRAY(padlist)[CvDEPTH(cv)]); \
144 PL_curpad = AvARRAY(PL_comppad); \
145 multicall_cop = CvSTART(cv); \
150 PL_op = multicall_cop; \
154 #define POP_MULTICALL \
158 POPBLOCK(cx,PL_curpm); \
160 CATCH_SET(multicall_oldcatch); \