include/ex_op_call.h

filter: Statementstmt 92.6% 227 / 245 Branchbran 73.0% 146 / 200 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 83.8% 373 / 445 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Op.xs ↑ Summary include/ex_op_kw.h »
1 #ifndef EX_OP_CALL_H
2 #define EX_OP_CALL_H
3  
4 /* Needs MY_CXT, so it is included after START_MY_CXT. */
5  
6 static XOP eo_xop_call;
7  
8 static CV *
9 1681889 eo_cv_on_stack(pTHX_ SV *sv)
10 {
11 1681889 ▶ if (SvTYPE(sv) == SVt_PVGV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(sv) == SVt_PVGV) 1681889 0 1681889
12 1681889 ▶ return GvCVu((GV *)sv);
Branch: 1 branch
BranchTrueFalseTotal
return GvCVu((GV *)sv); 1681889 0 1681889
13 0 ▶ if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) 0 0 0
if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) 0 0 0
14 0 return (CV *)SvRV(sv);
15 0 ▶ if (SvTYPE(sv) == SVt_PVCV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(sv) == SVt_PVCV) 0 0 0
16 0 return (CV *)sv;
17 0 return NULL;
18 }
19  
20 static I32
21 1260717 eo_ret_push(pTHX_ my_cxt_t *cxt)
22 {
23 1260717 ▶ if (cxt->ret_top >= cxt->ret_max) {
Branch: 1 branch
BranchTrueFalseTotal
if (cxt->ret_top >= cxt->ret_max) { 23 1260694 1260717
24 23 ▶ cxt->ret_max = cxt->ret_max ? cxt->ret_max * 2 : 16;
Branch: 1 branch
BranchTrueFalseTotal
cxt->ret_max = cxt->ret_max ? cxt->ret_max * 2 : 16; 4 19 23
25 23 Renew(cxt->ret, cxt->ret_max, eo_ret_t);
26 }
27 1260717 return cxt->ret_top++;
28 }
29  
30 /* The nearest context block_gimme would read: a sub, an eval or a format,
31 * on the current context stack. */
32 static I32
33 420005 eo_gimme_cx(pTHX)
34 {
35 I32 i;
36 840013 ▶ for (i = cxstack_ix; i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = cxstack_ix; i >= 0; i--) { 840008 5 840013
37 840008 ▶ switch (CxTYPE(&cxstack[i])) {
Branch: 1 branch
BranchTrueFalseTotal
switch (CxTYPE(&cxstack[i])) { 420000 420008 840008
38 420000 case CXt_SUB:
39 case CXt_EVAL:
40 case CXt_FORMAT:
41 420000 return i;
42 420008 default:
43 420008 break;
44 }
45 }
46 5 return -1;
47 }
48  
49 /* The context find_runcv would return the sub of: the first sub or format
50 * that is not a regex code block, or a string eval. -1 when it is an eval or
51 * there is none, and the call is then an ordinary one. */
52 static I32
53 1261069 eo_runcv_cx(pTHX)
54 {
55 I32 i;
56 2524160 ▶ for (i = cxstack_ix; i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = cxstack_ix; i >= 0; i--) { 2523113 1047 2524160
57 2523113 const PERL_CONTEXT *cx = &cxstack[i];
58 2523113 switch (CxTYPE(cx)) {
59 1260022 case CXt_SUB:
60 case CXt_FORMAT:
61 #ifdef CXp_SUB_RE
62 1260022 ▶ if (cx->cx_type & CXp_SUB_RE)
Branch: 1 branch
BranchTrueFalseTotal
if (cx->cx_type & CXp_SUB_RE) 0 1260022 1260022
63 0 continue;
64 #endif
65 1260022 return i;
66 0 case CXt_EVAL:
67 0 ▶ if (!CxTRYBLOCK(cx))
Branch: 1 branch
BranchTrueFalseTotal
if (!CxTRYBLOCK(cx)) 0 0 0
68 0 return -1;
69 0 break;
70 1263091 default:
71 1263091 break;
72 }
73 }
74 1047 return -1;
75 }
76  
77 /* A parameter goes back to the state `my` leaves it in at the end of a
78 * scope: emptied, or replaced when something else holds it. */
79 static void
80 1680820 eo_clear_param(pTHX_ SV **slot)
81 {
82 1680820 SV *sv = *slot;
83 1680820 ▶ if (SvREFCNT(sv) > 1 || SvMAGICAL(sv) || SvREADONLY(sv) || SvTYPE(sv) > SVt_PVMG) {
Branch: 4 branches
BranchTrueFalseTotal
if (SvREFCNT(sv) > 1 || SvMAGICAL(sv) || SvREADONLY(sv) || SvTYPE(sv) > SVt_PVMG) { 1680820 0 1680820
if (SvREFCNT(sv) > 1 || SvMAGICAL(sv) || SvREADONLY(sv) || SvTYPE(sv) > SVt_PVMG) { 1680820 0 1680820
if (SvREFCNT(sv) > 1 || SvMAGICAL(sv) || SvREADONLY(sv) || SvTYPE(sv) > SVt_PVMG) { 1680820 0 1680820
if (SvREFCNT(sv) > 1 || SvMAGICAL(sv) || SvREADONLY(sv) || SvTYPE(sv) > SVt_PVMG) { 0 1680820 1680820
84 0 SvREFCNT_dec(sv);
85 0 *slot = newSV(0);
86 0 SvPADMY_on(*slot);
87 }
88 1680820 ▶ else if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvROK(sv)) { 11 1680809 1680820
89 11 sv_unref_flags(sv, 0);
90 }
91 /* A plain value only the op can see is overwritten by the next call,
92 * and clearing it would keep its string buffer anyway. */
93 1680820 }
94  
95 /* Everything a sub frame would restore, in one save-stack entry. It runs
96 * at the leave op's leave_scope, or when a die unwinds past the call. */
97 static void
98 1260717 eo_unwind(pTHX_ void *p)
99 {
100 dMY_CXT;
101 1260717 const I32 ri = (I32)PTR2IV(p);
102 1260717 const eo_op_t *e = MY_CXT.ret[ri].e;
103 eo_ret_t *rp;
104 U16 i;
105  
106 2941537 ▶ for (i = 0; i < e->nparams; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < e->nparams; i++) 1680820 1260717 2941537
107 1680820 eo_clear_param(aTHX_ &PL_curpad[e->params[i]]);
108  
109 /* A DESTROY run by clearing a parameter can call another op and grow
110 * the records, which moves them: the record is taken again, by index. */
111 1260717 rp = &MY_CXT.ret[ri];
112  
113 /* A context the call changed is put back only while it is still the
114 * same one. Before 5.24 a die pops contexts before the save stack is
115 * run, and its slot may be gone by now. */
116 1260717 ▶ if (rp->cxix >= 0 && rp->cxix <= cxstack_ix)
Branch: 2 branches
BranchTrueFalseTotal
if (rp->cxix >= 0 && rp->cxix <= cxstack_ix) 420377 840340 1260717
if (rp->cxix >= 0 && rp->cxix <= cxstack_ix) 420377 0 420377
117 420377 cxstack[rp->cxix].blk_gimme = rp->oldgimme;
118 1260717 ▶ if (rp->spcx <= cxstack_ix)
Branch: 1 branch
BranchTrueFalseTotal
if (rp->spcx <= cxstack_ix) 1260717 0 1260717
119 1260717 cxstack[rp->spcx].blk_oldsp = rp->oldsp;
120 1260717 ▶ if (rp->runcx >= 0 && rp->runcx <= cxstack_ix
Branch: 2 branches
BranchTrueFalseTotal
if (rp->runcx >= 0 && rp->runcx <= cxstack_ix 1260714 3 1260717
if (rp->runcx >= 0 && rp->runcx <= cxstack_ix 1260714 0 1260714
121 #if PERL_VERSION_GE(5,20,0) && !PERL_VERSION_GE(5,24,0)
122 /* 5.20 and 5.22 run the save stack inside POPSUB, after it has read
123 * the cv: the context is as good as popped. */
124 && !(cxstack[rp->runcx].blk_u16 & CxPOPSUB_DONE)
125 #endif
126 ) {
127 1260714 cxstack[rp->runcx].blk_sub.cv = rp->oldruncv;
128 }
129 #if !PERL_VERSION_GE(5,24,0)
130 else if (rp->runcx >= 0) {
131 /* Before 5.24 a die pops a sub context with POPSUB, and it popped
132 * this one holding the op: it set the op's depth and released the
133 * op instead of the caller, which was not in the sub already. */
134 CvDEPTH(rp->oldruncv) = 0;
135 SvREFCNT_inc_simple_void_NN(rp->cv);
136 SvREFCNT_dec(rp->oldruncv);
137 }
138 #endif
139 1260717 PL_comppad = rp->oldpad;
140 1260717 ▶ PL_curpad = rp->oldpad ? AvARRAY(rp->oldpad) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
PL_curpad = rp->oldpad ? AvARRAY(rp->oldpad) : NULL; 1260717 0 1260717
141 1260717 PL_curcop = rp->oldcop;
142 1260717 PL_curpm = rp->oldpm;
143 1260717 PL_tmps_floor = rp->oldfloor;
144 1260717 CvDEPTH(rp->cv) = 0;
145 1260717 MY_CXT.ret_top = ri;
146 1260717 SvREFCNT_dec(rp->cv);
147 1260717 }
148  
149 /* The call. The ops below it have pushed a mark, the arguments and the
150 * sub, exactly as for entersub, so anything the fast path does not take
151 * goes to pp_entersub with the stack as it found it. */
152 static OP *
153 1681889 eo_pp_call(pTHX)
154 {
155 1681889 dSP;
156 dMY_CXT;
157 1681889 CV *cv = eo_cv_on_stack(aTHX_ TOPs);
158 eo_op_t *e;
159 eo_ret_t *r;
160 1681889 I32 ri, markix, nargs, cxix = -1, runcx;
161 bool top_is_sub;
162 U8 gimme;
163 U16 i;
164  
165 1681889 ▶ if (!cv || CvDEPTH(cv) || !(e = eo_op_live(aTHX_ cv))
Branch: 3 branches
BranchTrueFalseTotal
if (!cv || CvDEPTH(cv) || !(e = eo_op_live(aTHX_ cv)) 1681889 0 1681889
if (!cv || CvDEPTH(cv) || !(e = eo_op_live(aTHX_ cv)) 1681885 4 1681889
if (!cv || CvDEPTH(cv) || !(e = eo_op_live(aTHX_ cv)) 1681883 2 1681885
166 1681883 ▶ || (PERLDB_SUB && PL_DBsub))
Branch: 2 branches
BranchTrueFalseTotal
|| (PERLDB_SUB && PL_DBsub)) 0 1681883 1681883
|| (PERLDB_SUB && PL_DBsub)) 0 0 0
167 6 return PL_ppaddr[OP_ENTERSUB](aTHX);
168  
169 1681883 gimme = GIMME_V;
170  
171 1681883 ▶ if (cxstack_ix < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (cxstack_ix < 0) 0 1681883 1681883
172 0 return PL_ppaddr[OP_ENTERSUB](aTHX);
173  
174 /* The usual caller is a plain sub: then it is the context both searches
175 * below would find, and it is not an eval. */
176 3363766 top_is_sub = CxTYPE(&cxstack[cxstack_ix]) == CXt_SUB
177 #ifdef CXp_SUB_RE
178 1681883 ▶ && !(cxstack[cxstack_ix].cx_type & CXp_SUB_RE)
Branch: 2 branches
BranchTrueFalseTotal
&& !(cxstack[cxstack_ix].cx_type & CXp_SUB_RE) 695 1681188 1681883
&& !(cxstack[cxstack_ix].cx_type & CXp_SUB_RE) 695 0 695
179 #endif
180 ;
181  
182 /* An eval reads its stack base and context in die_unwind before it
183 * runs the save stack, so a call must not change an eval's. */
184 1681883 ▶ if (!top_is_sub && CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL)
Branch: 2 branches
BranchTrueFalseTotal
if (!top_is_sub && CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL) 1681188 695 1681883
if (!top_is_sub && CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL) 420114 1261074 1681188
185 420114 return PL_ppaddr[OP_ENTERSUB](aTHX);
186  
187 1261769 ▶ if (e->ctx_dep) {
Branch: 1 branch
BranchTrueFalseTotal
if (e->ctx_dep) { 420382 841387 1261769
188 420382 ▶ cxix = top_is_sub ? cxstack_ix : eo_gimme_cx(aTHX);
Branch: 1 branch
BranchTrueFalseTotal
cxix = top_is_sub ? cxstack_ix : eo_gimme_cx(aTHX); 377 420005 420382
189 420382 ▶ if (cxix < 0 || CxTYPE(&cxstack[cxix]) == CXt_EVAL)
Branch: 2 branches
BranchTrueFalseTotal
if (cxix < 0 || CxTYPE(&cxstack[cxix]) == CXt_EVAL) 420377 5 420382
if (cxix < 0 || CxTYPE(&cxstack[cxix]) == CXt_EVAL) 0 420377 420377
190 5 return PL_ppaddr[OP_ENTERSUB](aTHX);
191 }
192  
193 /* find_runcv names the variables in an uninitialised warning, and would
194 * find the caller: for a body that could warn, the call lends it the op. */
195 1261764 runcx = -1;
196 1261764 ▶ if (e->need_runcv) {
Branch: 1 branch
BranchTrueFalseTotal
if (e->need_runcv) { 1261761 3 1261764
197 1261761 ▶ runcx = top_is_sub ? cxstack_ix : eo_runcv_cx(aTHX);
Branch: 1 branch
BranchTrueFalseTotal
runcx = top_is_sub ? cxstack_ix : eo_runcv_cx(aTHX); 692 1261069 1261761
198 1261761 ▶ if (runcx < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (runcx < 0) 1047 1260714 1261761
199 1047 return PL_ppaddr[OP_ENTERSUB](aTHX);
200 #if !PERL_VERSION_GE(5,24,0)
201 /* Before 5.24 a die pops a format, or a sub called again inside
202 * itself, by the op it holds, and its depth cannot be put back. */
203 if (CxTYPE(&cxstack[runcx]) != CXt_SUB || cxstack[runcx].blk_sub.olddepth)
204 return PL_ppaddr[OP_ENTERSUB](aTHX);
205 #endif
206 }
207  
208 1260717 markix = POPMARK;
209 1260717 nargs = (I32)(SP - (PL_stack_base + markix + 1));
210  
211 1260717 ri = eo_ret_push(aTHX_ &MY_CXT);
212 1260717 r = &MY_CXT.ret[ri];
213 1260717 r->next = PL_op->op_next;
214 1260717 r->cv = cv;
215 1260717 r->e = e;
216 1260717 r->oldcop = PL_curcop;
217 1260717 r->oldpm = PL_curpm;
218 1260717 r->oldpad = PL_comppad;
219 1260717 r->oldfloor = PL_tmps_floor;
220 1260717 r->markix = markix;
221 1260717 r->gimme = gimme;
222 1260717 r->cxix = cxix;
223 1260717 r->targ = PL_op->op_targ;
224 1260717 ▶ if (cxix >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (cxix >= 0) { 420377 840340 1260717
225 420377 r->oldgimme = cxstack[cxix].blk_gimme;
226 420377 cxstack[cxix].blk_gimme = (cxstack[cxix].blk_gimme & ~G_WANT) | gimme;
227 }
228 1260717 r->runcx = runcx;
229 1260717 ▶ if (runcx >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (runcx >= 0) { 1260714 3 1260717
230 1260714 r->oldruncv = cxstack[runcx].blk_sub.cv;
231 1260714 cxstack[runcx].blk_sub.cv = cv;
232 }
233 1260717 r->spcx = cxstack_ix;
234 1260717 r->oldsp = (I32)cxstack[cxstack_ix].blk_oldsp;
235 1260717 cxstack[cxstack_ix].blk_oldsp = markix;
236  
237 1260717 SvREFCNT_inc_simple_void_NN(cv);
238 1260717 CvDEPTH(cv) = 1;
239 1260717 r->oldsaveix = PL_savestack_ix;
240 1260717 SAVEDESTRUCTOR_X(eo_unwind, INT2PTR(void *, (IV)ri));
241 1260717 r->afterix = PL_savestack_ix;
242 1260717 PL_tmps_floor = PL_tmps_ix;
243  
244 1260717 PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1);
245 /* A tied argument's FETCH may move the Perl stack: by index. */
246 2941537 ▶ for (i = 0; i < e->nparams; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < e->nparams; i++) 1680820 1260717 2941537
247 1680820 ▶ sv_setsv(PL_curpad[e->params[i]],
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(PL_curpad[e->params[i]], 1680791 29 1680820
248 (I32)i < nargs ? PL_stack_base[markix + 1 + i] : &PL_sv_undef);
249  
250 1260717 SP = PL_stack_base + markix;
251 1260717 PUTBACK;
252 1260717 return e->entry;
253 }
254  
255 /* The record of the frameless call this leave or return ends, or NULL for
256 * a real call. A leave or a return in an op runs at the body's top level
257 * (a return inside a loop or a block is declined), where the innermost
258 * context is the one the call found. A real call has pushed its own. */
259 static eo_ret_t *
260 1681604 eo_frameless(pTHX_ my_cxt_t *cxt)
261 {
262 eo_ret_t *r;
263 1681604 ▶ if (!cxt->ret_top)
Branch: 1 branch
BranchTrueFalseTotal
if (!cxt->ret_top) 416920 1264684 1681604
264 416920 return NULL;
265 1264684 r = &cxt->ret[cxt->ret_top - 1];
266 1264684 ▶ return cxstack_ix == r->spcx ? r : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return cxstack_ix == r->spcx ? r : NULL; 1260682 4002 1264684
267 }
268  
269 static bool
270 2100588 eo_passes(SV *sv)
271 {
272 2100588 ▶ return SvTEMP(sv) && SvREFCNT(sv) == 1 && !SvMAGICAL(sv);
Branch: 3 branches
BranchTrueFalseTotal
return SvTEMP(sv) && SvREFCNT(sv) == 1 && !SvMAGICAL(sv); 39 2100549 2100588
return SvTEMP(sv) && SvREFCNT(sv) == 1 && !SvMAGICAL(sv); 39 0 39
return SvTEMP(sv) && SvREFCNT(sv) == 1 && !SvMAGICAL(sv); 39 0 39
273 }
274  
275 /* Leave the call's scope. When the body left nothing on the save stack
276 * above the call's own entry, that entry is taken off and run here, which
277 * is what leave_scope would do, without the dispatch. */
278 static void
279 1260682 eo_leave_call(pTHX_ I32 ri, I32 saveix, I32 afterix)
280 {
281 1260682 ▶ if (PL_savestack_ix == afterix) {
Branch: 1 branch
BranchTrueFalseTotal
if (PL_savestack_ix == afterix) { 1260631 51 1260682
282 1260631 PL_savestack_ix = saveix;
283 1260631 eo_unwind(aTHX_ INT2PTR(void *, (IV)ri));
284 }
285 else {
286 51 leave_scope(saveix);
287 }
288 1260682 }
289  
290 /* The end of a frameless call, with its values from the call's mark up to
291 * sp, copied as leavesub copies them. Anything that runs during
292 * leave_scope (a DESTROY) may move the Perl stack and the records, so
293 * after it only indexes are used. */
294 static OP *
295 1260682 eo_finish(pTHX_ eo_ret_t *r, I32 ri, SV **sp)
296 {
297 1260682 const I32 markix = r->markix;
298 1260682 const I32 saveix = r->oldsaveix;
299 1260682 const I32 afterix = r->afterix;
300 1260682 const U8 gimme = r->gimme;
301 1260682 OP *next = r->next;
302 1260682 SV **mark = PL_stack_base + markix;
303  
304 1260682 ▶ if (gimme == G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (gimme == G_SCALAR) { 840342 420340 1260682
305 840342 ▶ SV *sv = sp > mark ? *sp : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *sv = sp > mark ? *sp : &PL_sv_undef; 840342 0 840342
306 SV *result;
307 840342 bool in_targ = FALSE;
308  
309 840342 ▶ if (SvIMMORTAL(sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (SvIMMORTAL(sv)) { 14 840328 840342
if (SvIMMORTAL(sv)) { 11 3 14
if (SvIMMORTAL(sv)) { 0 11 11
310 3 result = sv;
311 3 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 3 3
312 }
313 840339 ▶ else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) {
Branch: 4 branches
BranchTrueFalseTotal
else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) { 840339 0 840339
else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) { 420336 420003 840339
else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) { 420336 0 420336
else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) { 420297 39 420336
314 420297 result = AvARRAY(r->oldpad)[r->targ];
315 420297 sv_setsv(result, sv);
316 420297 SvPADTMP_on(result);
317 420297 in_targ = TRUE;
318 420297 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 15 420282 420297
319 }
320 else {
321 420042 SvREFCNT_inc_simple_void_NN(sv);
322 420042 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 420042 0 420042
323 420042 ▶ if (eo_passes(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eo_passes(sv)) { 0 420042 420042
324 0 result = sv;
325 }
326 else {
327 420042 result = newSVsv(sv);
328 420042 SvREFCNT_dec(sv);
329 }
330 }
331  
332 840342 PL_stack_sp = mark;
333 840342 eo_leave_call(aTHX_ ri, saveix, afterix);
334  
335 840342 ▶ if (!in_targ && !SvIMMORTAL(result))
Branch: 4 branches
BranchTrueFalseTotal
if (!in_targ && !SvIMMORTAL(result)) 420045 420297 840342
if (!in_targ && !SvIMMORTAL(result)) 3 420042 420045
if (!in_targ && !SvIMMORTAL(result)) 0 3 3
if (!in_targ && !SvIMMORTAL(result)) 0 0 0
336 420042 sv_2mortal(result);
337 840342 sp = PL_stack_sp;
338 840342 ▶ EXTEND(sp, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp, 1); 0 840342 840342
339 840342 *++sp = result;
340 840342 PL_stack_sp = sp;
341 }
342 420340 ▶ else if (gimme == G_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
else if (gimme == G_LIST) { 420162 178 420340
343 420162 const SSize_t n = sp - mark;
344 SSize_t i;
345  
346 /* FREETMPS, a copy of a tied value and leave_scope can all run Perl
347 * code that moves the stack, so the values are found by index. */
348 420162 PL_stack_sp = mark + n;
349 1680375 ▶ for (i = 1; i <= n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= n; i++) 1260213 420162 1680375
350 1260213 ▶ if (!SvIMMORTAL(PL_stack_base[markix + i]))
Branch: 3 branches
BranchTrueFalseTotal
if (!SvIMMORTAL(PL_stack_base[markix + i])) 29 1260184 1260213
if (!SvIMMORTAL(PL_stack_base[markix + i])) 26 3 29
if (!SvIMMORTAL(PL_stack_base[markix + i])) 26 0 26
351 1260210 SvREFCNT_inc_simple_void_NN(PL_stack_base[markix + i]);
352 420162 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 420069 93 420162
353 1680375 ▶ for (i = 1; i <= n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= n; i++) { 1260213 420162 1680375
354 1260213 SV *sv = PL_stack_base[markix + i];
355 SV *copy;
356 1260213 ▶ if (SvIMMORTAL(sv) || eo_passes(sv))
Branch: 4 branches
BranchTrueFalseTotal
if (SvIMMORTAL(sv) || eo_passes(sv)) 29 1260184 1260213
if (SvIMMORTAL(sv) || eo_passes(sv)) 26 3 29
if (SvIMMORTAL(sv) || eo_passes(sv)) 26 0 26
if (SvIMMORTAL(sv) || eo_passes(sv)) 0 1260210 1260210
357 3 continue;
358 1260210 copy = newSVsv(sv);
359 1260210 PL_stack_base[markix + i] = copy;
360 1260210 SvREFCNT_dec(sv);
361 }
362  
363 420162 PL_stack_sp = PL_stack_base + markix + n;
364 420162 eo_leave_call(aTHX_ ri, saveix, afterix);
365  
366 1680375 ▶ for (i = 1; i <= n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= n; i++) 1260213 420162 1680375
367 1260213 ▶ if (!SvIMMORTAL(PL_stack_base[markix + i]))
Branch: 3 branches
BranchTrueFalseTotal
if (!SvIMMORTAL(PL_stack_base[markix + i])) 3 1260210 1260213
if (!SvIMMORTAL(PL_stack_base[markix + i])) 0 3 3
if (!SvIMMORTAL(PL_stack_base[markix + i])) 0 0 0
368 1260210 sv_2mortal(PL_stack_base[markix + i]);
369 420162 PL_stack_sp = PL_stack_base + markix + n;
370 }
371 else {
372 178 PL_stack_sp = mark;
373 178 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 109 69 178
374 178 eo_leave_call(aTHX_ ri, saveix, afterix);
375 178 PL_stack_sp = PL_stack_base + markix;
376 }
377  
378 1260682 return next;
379 }
380  
381 /* The op's leavesub. */
382 static OP *
383 1681601 eo_pp_leave(pTHX)
384 {
385 dMY_CXT;
386 1681601 eo_ret_t *r = eo_frameless(aTHX_ &MY_CXT);
387  
388 1681601 ▶ if (!r || CvROOT(r->cv) != PL_op)
Branch: 2 branches
BranchTrueFalseTotal
if (!r || CvROOT(r->cv) != PL_op) 1260680 420921 1681601
if (!r || CvROOT(r->cv) != PL_op) 0 1260680 1260680
389 420921 return PL_ppaddr[OP_LEAVESUB](aTHX);
390 1260680 return eo_finish(aTHX_ r, MY_CXT.ret_top - 1, PL_stack_sp);
391 }
392  
393 /* A return in an op's body. Its values are above its own mark, and move
394 * down to the call's. */
395 static OP *
396 3 eo_pp_return(pTHX)
397 {
398 dMY_CXT;
399 3 eo_ret_t *r = eo_frameless(aTHX_ &MY_CXT);
400 SV **from, **to, **sp;
401  
402 3 ▶ if (!r)
Branch: 1 branch
BranchTrueFalseTotal
if (!r) 1 2 3
403 1 return PL_ppaddr[OP_RETURN](aTHX);
404  
405 2 from = PL_stack_base + POPMARK;
406 2 to = PL_stack_base + r->markix;
407 2 sp = PL_stack_sp;
408 2 ▶ if (from != to) {
Branch: 1 branch
BranchTrueFalseTotal
if (from != to) { 0 2 2
409 0 ▶ while (from < sp)
Branch: 1 branch
BranchTrueFalseTotal
while (from < sp) 0 0 0
410 0 *++to = *++from;
411 0 sp = to;
412 }
413 2 return eo_finish(aTHX_ r, MY_CXT.ret_top - 1, sp);
414 }
415  
416 static void
417 89 eo_arm_returns(pTHX_ OP *o)
418 {
419 275 ▶ for (; o; o = OpSIBLING(o)) {
Branch: 2 branches
BranchTrueFalseTotal
for (; o; o = OpSIBLING(o)) { 97 89 186
for (; o; o = OpSIBLING(o)) { 186 89 275
420 186 ▶ if (o->op_type == OP_RETURN)
Branch: 1 branch
BranchTrueFalseTotal
if (o->op_type == OP_RETURN) 11 175 186
421 11 o->op_ppaddr = eo_pp_return;
422 186 ▶ if (o->op_flags & OPf_KIDS)
Branch: 1 branch
BranchTrueFalseTotal
if (o->op_flags & OPf_KIDS) 80 106 186
423 80 eo_arm_returns(aTHX_ cUNOPo->op_first);
424 }
425 89 }
426  
427 /* An entersub to a live op becomes the call op. Its kids are kept, so it
428 * still pushes the sub, and any fallback is pp_entersub itself. */
429 static OP *
430 372 eo_convert_call(pTHX_ OP *o, CV *cv)
431 {
432 372 ▶ if (o->op_type == OP_ENTERSUB
Branch: 1 branch
BranchTrueFalseTotal
if (o->op_type == OP_ENTERSUB 372 0 372
433 372 ▶ && !(o->op_private & OPpENTERSUB_AMPER)
Branch: 1 branch
BranchTrueFalseTotal
&& !(o->op_private & OPpENTERSUB_AMPER) 372 0 372
434 372 ▶ && cv && eo_op_live(aTHX_ cv)) {
Branch: 2 branches
BranchTrueFalseTotal
&& cv && eo_op_live(aTHX_ cv)) { 372 0 372
&& cv && eo_op_live(aTHX_ cv)) { 372 0 372
435 372 o->op_type = OP_CUSTOM;
436 372 o->op_ppaddr = eo_pp_call;
437 #if PERL_VERSION_GE(5,16,0)
438 372 ▶ if (!o->op_targ)
Branch: 1 branch
BranchTrueFalseTotal
if (!o->op_targ) 372 0 372
439 372 o->op_targ = pad_alloc(OP_ENTERSUB, SVs_PADTMP);
440 #endif
441 }
442 372 return o;
443 }
444  
445 #if !EO_CHECK_WRAP
446 static OP *
447 372 eo_ck_call(pTHX_ OP *o, GV *namegv, SV *ckobj)
448 {
449 372 o = ck_entersub_args_proto_or_list(o, namegv, ckobj);
450 372 return eo_convert_call(aTHX_ o, (CV *)ckobj);
451 }
452 #else
453 /* Before 5.14 there are no call checkers: entersub's own check is wrapped,
454 * once for the process, and each call to a sub that is an op is found by
455 * the sub its gv names. The wrapped check runs first, so core has applied
456 * the prototype by then. */
457 static Perl_check_t eo_next_ck_entersub;
458  
459 static CV *
460 eo_call_target(pTHX_ OP *o)
461 {
462 OP *aop, *cvop = NULL, *k;
463 SV *sv;
464  
465 if (!(o->op_flags & OPf_KIDS))
466 return NULL;
467 aop = cUNOPo->op_first;
468 if (aop->op_type == OP_NULL && (aop->op_flags & OPf_KIDS) && !OpHAS_SIBLING(aop))
469 aop = cUNOPx(aop)->op_first;
470 for (k = aop; k; k = OpSIBLING(k))
471 cvop = k;
472 if (!cvop || !(cvop->op_type == OP_RV2CV || (cvop->op_type == OP_NULL && cvop->op_targ == OP_RV2CV))
473 || !(cvop->op_flags & OPf_KIDS))
474 return NULL;
475 k = cUNOPx(cvop)->op_first;
476 if (!k || k->op_type != OP_GV)
477 return NULL;
478 sv = (SV *)cGVOPx_gv(k);
479 if (!sv)
480 return NULL;
481 if (isGV_with_GP(sv))
482 return GvCVu((GV *)sv);
483 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV)
484 return (CV *)SvRV(sv);
485 return NULL;
486 }
487  
488 static OP *
489 eo_ck_entersub(pTHX_ OP *o)
490 {
491 o = eo_next_ck_entersub(aTHX_ o);
492 return eo_convert_call(aTHX_ o, eo_call_target(aTHX_ o));
493 }
494  
495 # ifdef EO_TEST_HOOKS
496 static Perl_check_t eo_test_next_ck;
497 static IV eo_test_seen;
498 static OP *
499 eo_test_ck(pTHX_ OP *o)
500 {
501 eo_test_seen++;
502 return eo_test_next_ck(aTHX_ o);
503 }
504 # endif
505 #endif
506  
507 /* Called when registration accepts a sub. */
508 static void
509 2249 eo_arm(pTHX_ CV *cv, eo_op_t *e)
510 {
511 2249 e->root->op_ppaddr = eo_pp_leave;
512 2249 ▶ if (e->has_return)
Branch: 1 branch
BranchTrueFalseTotal
if (e->has_return) 9 2240 2249
513 9 eo_arm_returns(aTHX_ cUNOPx(e->root)->op_first);
514 #if !EO_CHECK_WRAP
515 2249 cv_set_call_checker(cv, eo_ck_call, (SV *)cv);
516 #else
517 PERL_UNUSED_ARG(cv);
518 #endif
519 2249 }
520  
521 static void
522 39 eo_boot_ops(pTHX)
523 {
524 39 XopENTRY_set(&eo_xop_call, xop_name, "exop_call");
525 39 XopENTRY_set(&eo_xop_call, xop_desc, "Ex::Op call");
526 39 XopENTRY_set(&eo_xop_call, xop_class, OA_UNOP);
527 39 Perl_custom_op_register(aTHX_ eo_pp_call, &eo_xop_call);
528 #if EO_CHECK_WRAP
529 if (!eo_next_ck_entersub)
530 eo_wrap_check(OP_ENTERSUB, eo_ck_entersub, &eo_next_ck_entersub);
531 #endif
532 39 }
533  
534 #endif
« Op.xs ↑ Summary include/ex_op_kw.h »