include/ex_op_call.h

filter: Statementstmt 97.7% 254 / 262 (2 uncoverable) Branchbran 87.1% 186 / 226 (11 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 92.8% 440 / 488 (13 uncoverable) 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 1682190 eo_cv_on_stack(pTHX_ SV *sv)
10 {
11 /*
12 # uncoverable branch false
13 # uncoverable condition right count:1 */
14 1682190 ▶ if (SvTYPE(sv) == SVt_PVGV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(sv) == SVt_PVGV) 1682190 0 1682190
15 1682190 ▶ return GvCVu((GV *)sv);
Branch: 1 branch
BranchTrueFalseTotal
return GvCVu((GV *)sv); 1682190 0 1682190
16 /*
17 # uncoverable statement
18 # uncoverable branch true
19 # uncoverable branch false
20 # uncoverable condition left count:1..2
21 # uncoverable condition right count:1..2 */
22 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
23 0 return (CV *)SvRV(sv); /* # uncoverable statement */
24 /*
25 # uncoverable statement
26 # uncoverable branch true
27 # uncoverable branch false
28 # uncoverable condition left count:1
29 # uncoverable condition right count:1 */
30 0 ▶ if (SvTYPE(sv) == SVt_PVCV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(sv) == SVt_PVCV) 0 0 0
31 0 return (CV *)sv; /* # uncoverable statement */
32 0 return NULL; /* # uncoverable statement */
33 }
34  
35 static I32
36 1261009 eo_ret_push(pTHX_ my_cxt_t *cxt)
37 {
38 1261009 ▶ if (cxt->ret_top >= cxt->ret_max) {
Branch: 1 branch
BranchTrueFalseTotal
if (cxt->ret_top >= cxt->ret_max) { 26 1260983 1261009
39 26 ▶ 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 22 26
40 26 Renew(cxt->ret, cxt->ret_max, eo_ret_t);
41 }
42 1261009 return cxt->ret_top++;
43 }
44  
45 /* The nearest context block_gimme would read: a sub, an eval or a format,
46 * on the current context stack. */
47 static I32
48 420006 eo_gimme_cx(pTHX)
49 {
50 I32 i;
51 840015 ▶ for (i = cxstack_ix; i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = cxstack_ix; i >= 0; i--) { 840010 5 840015
52 840010 ▶ switch (CxTYPE(&cxstack[i])) {
Branch: 1 branch
BranchTrueFalseTotal
switch (CxTYPE(&cxstack[i])) { 420001 420009 840010
53 420001 case CXt_SUB:
54 case CXt_EVAL:
55 case CXt_FORMAT:
56 420001 return i;
57 420009 default:
58 420009 break;
59 }
60 }
61 5 return -1;
62 }
63  
64 /* The context find_runcv would return the sub of: the first sub or format
65 * that is not a regex code block, or a string eval. -1 when it is an eval or
66 * there is none, and the call is then an ordinary one. */
67 static I32
68 1261074 eo_runcv_cx(pTHX)
69 {
70 I32 i;
71 2524173 ▶ for (i = cxstack_ix; i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = cxstack_ix; i >= 0; i--) { 2523122 1051 2524173
72 2523122 const PERL_CONTEXT *cx = &cxstack[i];
73 2523122 switch (CxTYPE(cx)) {
74 1260023 case CXt_SUB:
75 case CXt_FORMAT:
76 #ifdef CXp_SUB_RE
77 1260023 ▶ if (cx->cx_type & CXp_SUB_RE)
Branch: 1 branch
BranchTrueFalseTotal
if (cx->cx_type & CXp_SUB_RE) 1 1260022 1260023
78 1 continue;
79 #endif
80 1260022 return i;
81 2 case CXt_EVAL:
82 2 ▶ if (!CxTRYBLOCK(cx))
Branch: 1 branch
BranchTrueFalseTotal
if (!CxTRYBLOCK(cx)) 1 1 2
83 1 return -1;
84 1 break;
85 1263097 default:
86 1263097 break;
87 }
88 }
89 1051 return -1;
90 }
91  
92 /* A parameter goes back to the state `my` leaves it in at the end of a
93 * scope: emptied, or replaced when something else holds it. */
94 static void
95 1681111 eo_clear_param(pTHX_ SV **slot)
96 {
97 1681111 SV *sv = *slot;
98 1681111 ▶ 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) { 1681108 3 1681111
if (SvREFCNT(sv) > 1 || SvMAGICAL(sv) || SvREADONLY(sv) || SvTYPE(sv) > SVt_PVMG) { 1681106 2 1681108
if (SvREFCNT(sv) > 1 || SvMAGICAL(sv) || SvREADONLY(sv) || SvTYPE(sv) > SVt_PVMG) { 1681104 2 1681106
if (SvREFCNT(sv) > 1 || SvMAGICAL(sv) || SvREADONLY(sv) || SvTYPE(sv) > SVt_PVMG) { 2 1681102 1681104
99 9 SvREFCNT_dec(sv);
100 9 *slot = newSV(0);
101 9 SvPADMY_on(*slot);
102 }
103 1681102 ▶ else if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvROK(sv)) { 11 1681091 1681102
104 11 sv_unref_flags(sv, 0);
105 }
106 /* A plain value only the op can see is overwritten by the next call,
107 * and clearing it would keep its string buffer anyway. */
108 1681111 }
109  
110 /* Everything a sub frame would restore, in one save-stack entry. It runs
111 * at the leave op's leave_scope, or when a die unwinds past the call. */
112 static void
113 1261009 eo_unwind(pTHX_ void *p)
114 {
115 dMY_CXT;
116 1261009 const I32 ri = (I32)PTR2IV(p);
117 1261009 const eo_op_t *e = MY_CXT.ret[ri].e;
118 eo_ret_t *rp;
119 U16 i;
120  
121 2942120 ▶ for (i = 0; i < e->nparams; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < e->nparams; i++) 1681111 1261009 2942120
122 1681111 eo_clear_param(aTHX_ &PL_curpad[e->params[i]]);
123  
124 /* A DESTROY run by clearing a parameter can call another op and grow
125 * the records, which moves them: the record is taken again, by index. */
126 1261009 rp = &MY_CXT.ret[ri];
127  
128 /* A context the call changed is put back only while it is still the
129 * same one. Before 5.24 a die pops contexts before the save stack is
130 * run, and its slot may be gone by now. */
131 1261009 ▶ if (rp->cxix >= 0 && rp->cxix <= cxstack_ix) /* # uncoverable condition right count:2 */
Branch: 2 branches
BranchTrueFalseTotal
if (rp->cxix >= 0 && rp->cxix <= cxstack_ix) /* # uncoverable condition right count:2 */ 420423 840586 1261009
if (rp->cxix >= 0 && rp->cxix <= cxstack_ix) /* # uncoverable condition right count:2 */ 420423 0 420423
132 420423 cxstack[rp->cxix].blk_gimme = rp->oldgimme;
133 /*
134 # uncoverable branch false
135 # uncoverable condition right count:1 */
136 1261009 ▶ if (rp->spcx <= cxstack_ix)
Branch: 1 branch
BranchTrueFalseTotal
if (rp->spcx <= cxstack_ix) 1261009 0 1261009
137 1261009 cxstack[rp->spcx].blk_oldsp = rp->oldsp;
138 1261009 ▶ if (rp->runcx >= 0 && rp->runcx <= cxstack_ix
Branch: 2 branches
BranchTrueFalseTotal
if (rp->runcx >= 0 && rp->runcx <= cxstack_ix 1261006 3 1261009
if (rp->runcx >= 0 && rp->runcx <= cxstack_ix 1261006 0 1261006
139 #if PERL_VERSION_GE(5,20,0) && !PERL_VERSION_GE(5,24,0)
140 /* 5.20 and 5.22 run the save stack inside POPSUB, after it has read
141 * the cv: the context is as good as popped. */
142 && !(cxstack[rp->runcx].blk_u16 & CxPOPSUB_DONE)
143 #endif
144 ) {
145 1261006 cxstack[rp->runcx].blk_sub.cv = rp->oldruncv;
146 }
147 #if !PERL_VERSION_GE(5,24,0)
148 else if (rp->runcx >= 0) {
149 /* Before 5.24 a die pops a sub context with POPSUB, and it popped
150 * this one holding the op: it set the op's depth and released the
151 * op instead of the caller, which was not in the sub already. */
152 CvDEPTH(rp->oldruncv) = 0;
153 SvREFCNT_inc_simple_void_NN(rp->cv);
154 SvREFCNT_dec(rp->oldruncv);
155 }
156 #endif
157 1261009 PL_comppad = rp->oldpad;
158 1261009 ▶ PL_curpad = rp->oldpad ? AvARRAY(rp->oldpad) : NULL; /* # uncoverable condition right count:1 */
Branch: 1 branch
BranchTrueFalseTotal
PL_curpad = rp->oldpad ? AvARRAY(rp->oldpad) : NULL; /* # uncoverable condition right count:1 */ 1261009 0 1261009
159 1261009 PL_curcop = rp->oldcop;
160 1261009 PL_curpm = rp->oldpm;
161 1261009 PL_tmps_floor = rp->oldfloor;
162 1261009 CvDEPTH(rp->cv) = 0;
163 1261009 MY_CXT.ret_top = ri;
164 1261009 SvREFCNT_dec(rp->cv);
165 1261009 }
166  
167 /* The call. The ops below it have pushed a mark, the arguments and the
168 * sub, exactly as for entersub, so anything the fast path does not take
169 * goes to pp_entersub with the stack as it found it. */
170 static OP *
171 1682190 eo_pp_call(pTHX)
172 {
173 1682190 dSP;
174 dMY_CXT;
175 1682190 CV *cv = eo_cv_on_stack(aTHX_ TOPs);
176 eo_op_t *e;
177 eo_ret_t *r;
178 1682190 I32 ri, markix, nargs, cxix = -1, runcx;
179 bool top_is_sub;
180 U8 gimme;
181 U16 i;
182  
183 1682190 ▶ if (!cv || CvDEPTH(cv) || !(e = eo_op_live(aTHX_ cv)) /* # uncoverable condition right count:5 */
Branch: 3 branches
BranchTrueFalseTotal
if (!cv || CvDEPTH(cv) || !(e = eo_op_live(aTHX_ cv)) /* # uncoverable condition right count:5 */ 1682189 1 1682190
if (!cv || CvDEPTH(cv) || !(e = eo_op_live(aTHX_ cv)) /* # uncoverable condition right count:5 */ 1682185 4 1682189
if (!cv || CvDEPTH(cv) || !(e = eo_op_live(aTHX_ cv)) /* # uncoverable condition right count:5 */ 1682183 2 1682185
184 1682183 ▶ || (PERLDB_SUB && PL_DBsub))
Branch: 2 branches
BranchTrueFalseTotal
|| (PERLDB_SUB && PL_DBsub)) 1 1682182 1682183
|| (PERLDB_SUB && PL_DBsub)) 1 0 1
185 8 return PL_ppaddr[OP_ENTERSUB](aTHX);
186  
187 1682182 gimme = GIMME_V;
188  
189 /*
190 # uncoverable branch true
191 # uncoverable condition left count:1 */
192 1682182 ▶ if (cxstack_ix < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (cxstack_ix < 0) 0 1682182 1682182
193 0 return PL_ppaddr[OP_ENTERSUB](aTHX); /* # uncoverable statement */
194  
195 /* The usual caller is a plain sub: then it is the context both searches
196 * below would find, and it is not an eval. */
197 3364364 top_is_sub = CxTYPE(&cxstack[cxstack_ix]) == CXt_SUB
198 #ifdef CXp_SUB_RE
199 1682182 ▶ && !(cxstack[cxstack_ix].cx_type & CXp_SUB_RE)
Branch: 2 branches
BranchTrueFalseTotal
&& !(cxstack[cxstack_ix].cx_type & CXp_SUB_RE) 988 1681194 1682182
&& !(cxstack[cxstack_ix].cx_type & CXp_SUB_RE) 987 1 988
200 #endif
201 ;
202  
203 /* An eval reads its stack base and context in die_unwind before it
204 * runs the save stack, so a call must not change an eval's. */
205 1682182 ▶ if (!top_is_sub && CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL)
Branch: 2 branches
BranchTrueFalseTotal
if (!top_is_sub && CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL) 1681195 987 1682182
if (!top_is_sub && CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL) 420115 1261080 1681195
206 420115 return PL_ppaddr[OP_ENTERSUB](aTHX);
207  
208 1262067 ▶ if (e->ctx_dep) {
Branch: 1 branch
BranchTrueFalseTotal
if (e->ctx_dep) { 420429 841638 1262067
209 420429 ▶ cxix = top_is_sub ? cxstack_ix : eo_gimme_cx(aTHX);
Branch: 1 branch
BranchTrueFalseTotal
cxix = top_is_sub ? cxstack_ix : eo_gimme_cx(aTHX); 423 420006 420429
210 420429 ▶ if (cxix < 0 || CxTYPE(&cxstack[cxix]) == CXt_EVAL)
Branch: 2 branches
BranchTrueFalseTotal
if (cxix < 0 || CxTYPE(&cxstack[cxix]) == CXt_EVAL) 420424 5 420429
if (cxix < 0 || CxTYPE(&cxstack[cxix]) == CXt_EVAL) 1 420423 420424
211 6 return PL_ppaddr[OP_ENTERSUB](aTHX);
212 }
213  
214 /* find_runcv names the variables in an uninitialised warning, and would
215 * find the caller: for a body that could warn, the call lends it the op. */
216 1262061 runcx = -1;
217 1262061 ▶ if (e->need_runcv) {
Branch: 1 branch
BranchTrueFalseTotal
if (e->need_runcv) { 1262058 3 1262061
218 1262058 ▶ runcx = top_is_sub ? cxstack_ix : eo_runcv_cx(aTHX);
Branch: 1 branch
BranchTrueFalseTotal
runcx = top_is_sub ? cxstack_ix : eo_runcv_cx(aTHX); 984 1261074 1262058
219 1262058 ▶ if (runcx < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (runcx < 0) 1052 1261006 1262058
220 1052 return PL_ppaddr[OP_ENTERSUB](aTHX);
221 #if !PERL_VERSION_GE(5,24,0)
222 /* Before 5.24 a die pops a format, or a sub called again inside
223 * itself, by the op it holds, and its depth cannot be put back. */
224 if (CxTYPE(&cxstack[runcx]) != CXt_SUB || cxstack[runcx].blk_sub.olddepth)
225 return PL_ppaddr[OP_ENTERSUB](aTHX);
226 #endif
227 }
228  
229 1261009 markix = POPMARK;
230 1261009 nargs = (I32)(SP - (PL_stack_base + markix + 1));
231  
232 1261009 ri = eo_ret_push(aTHX_ &MY_CXT);
233 1261009 r = &MY_CXT.ret[ri];
234 1261009 r->next = PL_op->op_next;
235 1261009 r->cv = cv;
236 1261009 r->e = e;
237 1261009 r->oldcop = PL_curcop;
238 1261009 r->oldpm = PL_curpm;
239 1261009 r->oldpad = PL_comppad;
240 1261009 r->oldfloor = PL_tmps_floor;
241 1261009 r->markix = markix;
242 1261009 r->gimme = gimme;
243 1261009 r->cxix = cxix;
244 1261009 r->targ = PL_op->op_targ;
245 1261009 ▶ if (cxix >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (cxix >= 0) { 420423 840586 1261009
246 420423 r->oldgimme = cxstack[cxix].blk_gimme;
247 420423 cxstack[cxix].blk_gimme = (cxstack[cxix].blk_gimme & ~G_WANT) | gimme;
248 }
249 1261009 r->runcx = runcx;
250 1261009 ▶ if (runcx >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (runcx >= 0) { 1261006 3 1261009
251 1261006 r->oldruncv = cxstack[runcx].blk_sub.cv;
252 1261006 cxstack[runcx].blk_sub.cv = cv;
253 }
254 1261009 r->spcx = cxstack_ix;
255 1261009 r->oldsp = (I32)cxstack[cxstack_ix].blk_oldsp;
256 1261009 cxstack[cxstack_ix].blk_oldsp = markix;
257  
258 1261009 SvREFCNT_inc_simple_void_NN(cv);
259 1261009 CvDEPTH(cv) = 1;
260 1261009 r->oldsaveix = PL_savestack_ix;
261 1261009 SAVEDESTRUCTOR_X(eo_unwind, INT2PTR(void *, (IV)ri));
262 1261009 r->afterix = PL_savestack_ix;
263 1261009 PL_tmps_floor = PL_tmps_ix;
264  
265 1261009 PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1);
266 /* A tied argument's FETCH may move the Perl stack: by index. */
267 2942120 ▶ for (i = 0; i < e->nparams; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < e->nparams; i++) 1681111 1261009 2942120
268 1681111 ▶ sv_setsv(PL_curpad[e->params[i]],
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(PL_curpad[e->params[i]], 1681082 29 1681111
269 (I32)i < nargs ? PL_stack_base[markix + 1 + i] : &PL_sv_undef);
270  
271 1261009 SP = PL_stack_base + markix;
272 1261009 PUTBACK;
273 1261009 return e->entry;
274 }
275  
276 /* The record of the frameless call this leave ends, or NULL for a real
277 * call. A leave in an op runs at the body's top level, where the innermost
278 * context is the one the call found. A real call has pushed its own. */
279 static eo_ret_t *
280 1681760 eo_frameless(pTHX_ my_cxt_t *cxt)
281 {
282 eo_ret_t *r;
283 1681760 ▶ if (!cxt->ret_top)
Branch: 1 branch
BranchTrueFalseTotal
if (!cxt->ret_top) 416936 1264824 1681760
284 416936 return NULL;
285 1264824 r = &cxt->ret[cxt->ret_top - 1];
286 1264824 ▶ return cxstack_ix == r->spcx ? r : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return cxstack_ix == r->spcx ? r : NULL; 1260819 4005 1264824
287 }
288  
289 /* Whether a context is one a return may unwind through: a block or a loop.
290 * The macro reads a variable named cx. */
291 static bool
292 137 eo_cx_unwinds(const PERL_CONTEXT *cx)
293 {
294 #ifdef CxTYPE_is_LOOP
295 137 ▶ return CxTYPE(cx) == CXt_BLOCK || CxTYPE_is_LOOP(cx);
Branch: 3 branches
BranchTrueFalseTotal
return CxTYPE(cx) == CXt_BLOCK || CxTYPE_is_LOOP(cx); 110 27 137
return CxTYPE(cx) == CXt_BLOCK || CxTYPE_is_LOOP(cx); 110 0 110
return CxTYPE(cx) == CXt_BLOCK || CxTYPE_is_LOOP(cx); 108 2 110
296 #else
297 return CxTYPE(cx) == CXt_BLOCK || CxTYPE(cx) == CXt_LOOP;
298 #endif
299 }
300  
301 /* The record of the frameless call this return ends, or NULL. A return in
302 * an op's body may sit inside blocks and loops, which it unwinds as
303 * pp_return does. A sub, a format or an eval between it and the call
304 * makes it theirs. */
305 static eo_ret_t *
306 160 eo_frameless_return(pTHX_ my_cxt_t *cxt)
307 {
308 eo_ret_t *r;
309 I32 i;
310 160 ▶ if (!cxt->ret_top)
Branch: 1 branch
BranchTrueFalseTotal
if (!cxt->ret_top) 3 157 160
311 3 return NULL;
312 157 r = &cxt->ret[cxt->ret_top - 1];
313 /*
314 # uncoverable branch true
315 # uncoverable condition left count:1 */
316 157 ▶ if (cxstack_ix < r->spcx)
Branch: 1 branch
BranchTrueFalseTotal
if (cxstack_ix < r->spcx) 0 157 157
317 0 return NULL; /* # uncoverable statement */
318 292 ▶ for (i = cxstack_ix; i > r->spcx; i--)
Branch: 1 branch
BranchTrueFalseTotal
for (i = cxstack_ix; i > r->spcx; i--) 137 155 292
319 137 ▶ if (!eo_cx_unwinds(&cxstack[i]))
Branch: 1 branch
BranchTrueFalseTotal
if (!eo_cx_unwinds(&cxstack[i])) 2 135 137
320 2 return NULL;
321 155 return r;
322 }
323  
324 static bool
325 2100968 eo_passes(SV *sv)
326 {
327 2100968 ▶ return SvTEMP(sv) && SvREFCNT(sv) == 1 && !SvMAGICAL(sv); /* # uncoverable condition right count:2..3 */
Branch: 3 branches
BranchTrueFalseTotal
return SvTEMP(sv) && SvREFCNT(sv) == 1 && !SvMAGICAL(sv); /* # uncoverable condition right count:2..3 */ 85 2100883 2100968
return SvTEMP(sv) && SvREFCNT(sv) == 1 && !SvMAGICAL(sv); /* # uncoverable condition right count:2..3 */ 85 0 85
return SvTEMP(sv) && SvREFCNT(sv) == 1 && !SvMAGICAL(sv); /* # uncoverable condition right count:2..3 */ 85 0 85
328 }
329  
330 /* Leave the call's scope. When the body left nothing on the save stack
331 * above the call's own entry, that entry is taken off and run here, which
332 * is what leave_scope would do, without the dispatch. */
333 static void
334 1260974 eo_leave_call(pTHX_ I32 ri, I32 saveix, I32 afterix)
335 {
336 1260974 ▶ if (PL_savestack_ix == afterix) {
Branch: 1 branch
BranchTrueFalseTotal
if (PL_savestack_ix == afterix) { 1260877 97 1260974
337 1260877 PL_savestack_ix = saveix;
338 1260877 eo_unwind(aTHX_ INT2PTR(void *, (IV)ri));
339 }
340 else {
341 97 leave_scope(saveix);
342 }
343 1260974 }
344  
345 /* The end of a frameless call, with its values from the call's mark up to
346 * sp, copied as leavesub copies them. Anything that runs during
347 * leave_scope (a DESTROY) may move the Perl stack and the records, so
348 * after it only indexes are used. */
349 static OP *
350 1260974 eo_finish(pTHX_ eo_ret_t *r, I32 ri, SV **sp)
351 {
352 1260974 const I32 markix = r->markix;
353 1260974 const I32 saveix = r->oldsaveix;
354 1260974 const I32 afterix = r->afterix;
355 1260974 const U8 gimme = r->gimme;
356 1260974 OP *next = r->next;
357 1260974 SV **mark = PL_stack_base + markix;
358  
359 1260974 ▶ if (gimme == G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (gimme == G_SCALAR) { 840442 420532 1260974
360 840442 ▶ SV *sv = sp > mark ? *sp : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *sv = sp > mark ? *sp : &PL_sv_undef; 840439 3 840442
361 SV *result;
362 840442 bool in_targ = FALSE;
363  
364 840442 ▶ if (SvIMMORTAL(sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (SvIMMORTAL(sv)) { 41 840401 840442
if (SvIMMORTAL(sv)) { 35 6 41
if (SvIMMORTAL(sv)) { 0 35 35
365 6 result = sv;
366 6 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 6 6
367 }
368 840436 ▶ else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) { /* # uncoverable condition right count:1 */
Branch: 4 branches
BranchTrueFalseTotal
else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) { /* # uncoverable condition right count:1 */ 840436 0 840436
else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) { /* # uncoverable condition right count:1 */ 420433 420003 840436
else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) { /* # uncoverable condition right count:1 */ 420432 1 420433
else if (r->targ && !SvROK(sv) && SvTYPE(sv) <= SVt_PVMG && !eo_passes(sv)) { /* # uncoverable condition right count:1 */ 420350 82 420432
369 420350 result = AvARRAY(r->oldpad)[r->targ];
370 420350 sv_setsv(result, sv);
371 420350 SvPADTMP_on(result);
372 420350 in_targ = TRUE;
373 420350 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 16 420334 420350
374 }
375 else {
376 420086 SvREFCNT_inc_simple_void_NN(sv);
377 420086 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 420085 1 420086
378 /*
379 # uncoverable branch true
380 # uncoverable condition left count:1 */
381 420086 ▶ if (eo_passes(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eo_passes(sv)) { 0 420086 420086
382 0 result = sv; /* # uncoverable statement */
383 }
384 else {
385 420086 result = newSVsv(sv);
386 420086 SvREFCNT_dec(sv);
387 }
388 }
389  
390 840442 PL_stack_sp = mark;
391 840442 eo_leave_call(aTHX_ ri, saveix, afterix);
392  
393 840442 ▶ if (!in_targ && !SvIMMORTAL(result))
Branch: 4 branches
BranchTrueFalseTotal
if (!in_targ && !SvIMMORTAL(result)) 420092 420350 840442
if (!in_targ && !SvIMMORTAL(result)) 6 420086 420092
if (!in_targ && !SvIMMORTAL(result)) 0 6 6
if (!in_targ && !SvIMMORTAL(result)) 0 0 0
394 420086 sv_2mortal(result);
395 840442 sp = PL_stack_sp;
396 840442 ▶ EXTEND(sp, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp, 1); 0 840442 840442
397 840442 *++sp = result;
398 840442 PL_stack_sp = sp;
399 }
400 420532 ▶ else if (gimme == G_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
else if (gimme == G_LIST) { 420261 271 420532
401 420261 const SSize_t n = sp - mark;
402 SSize_t i;
403  
404 /* FREETMPS, a copy of a tied value and leave_scope can all run Perl
405 * code that moves the stack, so the values are found by index. */
406 420261 PL_stack_sp = mark + n;
407 1680597 ▶ for (i = 1; i <= n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= n; i++) 1260336 420261 1680597
408 1260336 ▶ if (!SvIMMORTAL(PL_stack_base[markix + i]))
Branch: 3 branches
BranchTrueFalseTotal
if (!SvIMMORTAL(PL_stack_base[markix + i])) 66 1260270 1260336
if (!SvIMMORTAL(PL_stack_base[markix + i])) 63 3 66
if (!SvIMMORTAL(PL_stack_base[markix + i])) 63 0 63
409 1260333 SvREFCNT_inc_simple_void_NN(PL_stack_base[markix + i]);
410 420261 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 420108 153 420261
411 1680597 ▶ for (i = 1; i <= n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= n; i++) { 1260336 420261 1680597
412 1260336 SV *sv = PL_stack_base[markix + i];
413 SV *copy;
414 1260336 ▶ if (SvIMMORTAL(sv) || eo_passes(sv))
Branch: 4 branches
BranchTrueFalseTotal
if (SvIMMORTAL(sv) || eo_passes(sv)) 66 1260270 1260336
if (SvIMMORTAL(sv) || eo_passes(sv)) 63 3 66
if (SvIMMORTAL(sv) || eo_passes(sv)) 63 0 63
if (SvIMMORTAL(sv) || eo_passes(sv)) 0 1260333 1260333
415 3 continue;
416 1260333 copy = newSVsv(sv);
417 1260333 PL_stack_base[markix + i] = copy;
418 1260333 SvREFCNT_dec(sv);
419 }
420  
421 420261 PL_stack_sp = PL_stack_base + markix + n;
422 420261 eo_leave_call(aTHX_ ri, saveix, afterix);
423  
424 1680597 ▶ for (i = 1; i <= n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= n; i++) 1260336 420261 1680597
425 1260336 ▶ if (!SvIMMORTAL(PL_stack_base[markix + i]))
Branch: 3 branches
BranchTrueFalseTotal
if (!SvIMMORTAL(PL_stack_base[markix + i])) 3 1260333 1260336
if (!SvIMMORTAL(PL_stack_base[markix + i])) 0 3 3
if (!SvIMMORTAL(PL_stack_base[markix + i])) 0 0 0
426 1260333 sv_2mortal(PL_stack_base[markix + i]);
427 420261 PL_stack_sp = PL_stack_base + markix + n;
428 }
429 else {
430 271 PL_stack_sp = mark;
431 271 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 142 129 271
432 271 eo_leave_call(aTHX_ ri, saveix, afterix);
433 271 PL_stack_sp = PL_stack_base + markix;
434 }
435  
436 1260974 return next;
437 }
438  
439 /* The op's leavesub. */
440 static OP *
441 1681760 eo_pp_leave(pTHX)
442 {
443 dMY_CXT;
444 1681760 eo_ret_t *r = eo_frameless(aTHX_ &MY_CXT);
445  
446 1681760 ▶ if (!r || CvROOT(r->cv) != PL_op) /* # uncoverable condition left count:2 */
Branch: 2 branches
BranchTrueFalseTotal
if (!r || CvROOT(r->cv) != PL_op) /* # uncoverable condition left count:2 */ 1260819 420941 1681760
if (!r || CvROOT(r->cv) != PL_op) /* # uncoverable condition left count:2 */ 0 1260819 1260819
447 420941 return PL_ppaddr[OP_LEAVESUB](aTHX);
448 1260819 return eo_finish(aTHX_ r, MY_CXT.ret_top - 1, PL_stack_sp);
449 }
450  
451 /* A return in an op's body. Its values are above its own mark, and move
452 * down to the call's. From inside blocks or loops, the values are first
453 * made safe from what unwinding frees (a loop's variable, a block's
454 * lexical), then the contexts above the call's are unwound. */
455 static OP *
456 160 eo_pp_return(pTHX)
457 {
458 dMY_CXT;
459 160 eo_ret_t *r = eo_frameless_return(aTHX_ &MY_CXT);
460 SV **from, **to, **sp, **p;
461  
462 160 ▶ if (!r)
Branch: 1 branch
BranchTrueFalseTotal
if (!r) 5 155 160
463 5 return PL_ppaddr[OP_RETURN](aTHX);
464  
465 155 from = PL_stack_base + POPMARK;
466 155 to = PL_stack_base + r->markix;
467 155 sp = PL_stack_sp;
468 155 ▶ if (cxstack_ix > r->spcx) {
Branch: 1 branch
BranchTrueFalseTotal
if (cxstack_ix > r->spcx) { 108 47 155
469 225 ▶ for (p = from + 1; p <= sp; p++)
Branch: 1 branch
BranchTrueFalseTotal
for (p = from + 1; p <= sp; p++) 117 108 225
470 117 ▶ if (!SvIMMORTAL(*p) && !eo_passes(*p))
Branch: 4 branches
BranchTrueFalseTotal
if (!SvIMMORTAL(*p) && !eo_passes(*p)) 45 72 117
if (!SvIMMORTAL(*p) && !eo_passes(*p)) 45 0 45
if (!SvIMMORTAL(*p) && !eo_passes(*p)) 45 0 45
if (!SvIMMORTAL(*p) && !eo_passes(*p)) 114 3 117
471 114 *p = sv_mortalcopy(*p);
472 108 dounwind(r->spcx);
473 }
474 155 ▶ if (from != to) {
Branch: 1 branch
BranchTrueFalseTotal
if (from != to) { 18 137 155
475 45 ▶ while (from < sp)
Branch: 1 branch
BranchTrueFalseTotal
while (from < sp) 27 18 45
476 27 *++to = *++from;
477 18 sp = to;
478 }
479 155 return eo_finish(aTHX_ r, MY_CXT.ret_top - 1, sp);
480 }
481  
482 static void
483 570 eo_arm_returns(pTHX_ OP *o)
484 {
485 1819 ▶ for (; o; o = OpSIBLING(o)) {
Branch: 2 branches
BranchTrueFalseTotal
for (; o; o = OpSIBLING(o)) { 679 570 1249
for (; o; o = OpSIBLING(o)) { 1249 570 1819
486 1249 ▶ if (o->op_type == OP_RETURN)
Branch: 1 branch
BranchTrueFalseTotal
if (o->op_type == OP_RETURN) 52 1197 1249
487 52 o->op_ppaddr = eo_pp_return;
488 1249 ▶ if (o->op_flags & OPf_KIDS)
Branch: 1 branch
BranchTrueFalseTotal
if (o->op_flags & OPf_KIDS) 522 727 1249
489 522 eo_arm_returns(aTHX_ cUNOPo->op_first);
490 }
491 570 }
492  
493 /* An entersub to a live op becomes the call op. Its kids are kept, so it
494 * still pushes the sub, and any fallback is pp_entersub itself. */
495 static OP *
496 488 eo_convert_call(pTHX_ OP *o, CV *cv)
497 {
498 /*
499 # uncoverable branch false
500 # uncoverable condition right count:1..4 */
501 488 ▶ if (o->op_type == OP_ENTERSUB
Branch: 1 branch
BranchTrueFalseTotal
if (o->op_type == OP_ENTERSUB 488 0 488
502 488 ▶ && !(o->op_private & OPpENTERSUB_AMPER)
Branch: 1 branch
BranchTrueFalseTotal
&& !(o->op_private & OPpENTERSUB_AMPER) 488 0 488
503 488 ▶ && cv && eo_op_live(aTHX_ cv)) {
Branch: 2 branches
BranchTrueFalseTotal
&& cv && eo_op_live(aTHX_ cv)) { 488 0 488
&& cv && eo_op_live(aTHX_ cv)) { 488 0 488
504 488 o->op_type = OP_CUSTOM;
505 488 o->op_ppaddr = eo_pp_call;
506 #if PERL_VERSION_GE(5,16,0)
507 /*
508 # uncoverable branch false
509 # uncoverable condition right count:1 */
510 488 ▶ if (!o->op_targ)
Branch: 1 branch
BranchTrueFalseTotal
if (!o->op_targ) 488 0 488
511 488 o->op_targ = pad_alloc(OP_ENTERSUB, SVs_PADTMP);
512 #endif
513 }
514 488 return o;
515 }
516  
517 #if !EO_CHECK_WRAP
518 static OP *
519 488 eo_ck_call(pTHX_ OP *o, GV *namegv, SV *ckobj)
520 {
521 488 o = ck_entersub_args_proto_or_list(o, namegv, ckobj);
522 488 return eo_convert_call(aTHX_ o, (CV *)ckobj);
523 }
524 #else
525 /* Before 5.14 there are no call checkers: entersub's own check is wrapped,
526 * once for the process, and each call to a sub that is an op is found by
527 * the sub its gv names. The wrapped check runs first, so core has applied
528 * the prototype by then. */
529 static Perl_check_t eo_next_ck_entersub;
530  
531 static CV *
532 eo_call_target(pTHX_ OP *o)
533 {
534 OP *aop, *cvop = NULL, *k;
535 SV *sv;
536  
537 if (!(o->op_flags & OPf_KIDS))
538 return NULL;
539 aop = cUNOPo->op_first;
540 if (aop->op_type == OP_NULL && (aop->op_flags & OPf_KIDS) && !OpHAS_SIBLING(aop))
541 aop = cUNOPx(aop)->op_first;
542 for (k = aop; k; k = OpSIBLING(k))
543 cvop = k;
544 if (!cvop || !(cvop->op_type == OP_RV2CV || (cvop->op_type == OP_NULL && cvop->op_targ == OP_RV2CV))
545 || !(cvop->op_flags & OPf_KIDS))
546 return NULL;
547 k = cUNOPx(cvop)->op_first;
548 if (!k || k->op_type != OP_GV)
549 return NULL;
550 sv = (SV *)cGVOPx_gv(k);
551 if (!sv)
552 return NULL;
553 if (isGV_with_GP(sv))
554 return GvCVu((GV *)sv);
555 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV)
556 return (CV *)SvRV(sv);
557 return NULL;
558 }
559  
560 static OP *
561 eo_ck_entersub(pTHX_ OP *o)
562 {
563 o = eo_next_ck_entersub(aTHX_ o);
564 return eo_convert_call(aTHX_ o, eo_call_target(aTHX_ o));
565 }
566  
567 # ifdef EO_TEST_HOOKS
568 static Perl_check_t eo_test_next_ck;
569 static IV eo_test_seen;
570 static OP *
571 eo_test_ck(pTHX_ OP *o)
572 {
573 eo_test_seen++;
574 return eo_test_next_ck(aTHX_ o);
575 }
576 # endif
577 #endif
578  
579 /* Called when registration accepts a sub. */
580 static void
581 308 eo_arm(pTHX_ CV *cv, eo_op_t *e)
582 {
583 308 e->root->op_ppaddr = eo_pp_leave;
584 308 ▶ if (e->has_return)
Branch: 1 branch
BranchTrueFalseTotal
if (e->has_return) 48 260 308
585 48 eo_arm_returns(aTHX_ cUNOPx(e->root)->op_first);
586 #if !EO_CHECK_WRAP
587 308 cv_set_call_checker(cv, eo_ck_call, (SV *)cv);
588 #else
589 PERL_UNUSED_ARG(cv);
590 #endif
591 308 }
592  
593 static void
594 50 eo_boot_ops(pTHX)
595 {
596 50 XopENTRY_set(&eo_xop_call, xop_name, "exop_call");
597 50 XopENTRY_set(&eo_xop_call, xop_desc, "Ex::Op call");
598 50 XopENTRY_set(&eo_xop_call, xop_class, OA_UNOP);
599 50 Perl_custom_op_register(aTHX_ eo_pp_call, &eo_xop_call);
600 #if EO_CHECK_WRAP
601 if (!eo_next_ck_entersub)
602 eo_wrap_check(OP_ENTERSUB, eo_ck_entersub, &eo_next_ck_entersub);
603 #endif
604 50 }
605  
606 #endif
« Op.xs ↑ Summary include/ex_op_kw.h »