ListUtil.xs

filter: Statementstmt 0.0% 0 / 706 Branchbran 0.0% 0 / 802 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 1508 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Sub/Util.pm ↑ Summary blib/lib/List/Util/XS.pm »
1 /* Copyright (c) 1997-2000 Graham Barr <gbarr@pobox.com>. All rights reserved.
2 * Copyright (C) 2014, cPanel Inc. All rights reserved.
3 * Copyright (C) 2017, Reini Urban. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the same terms as Perl itself.
6 */
7 #define PERL_NO_GET_CONTEXT /* we want efficiency */
8 #include <EXTERN.h>
9 #include <perl.h>
10 #include <XSUB.h>
11  
12 #ifdef USE_PPPORT_H
13 # define NEED_sv_2pv_flags 1
14 # define NEED_newSVpvn_flags 1
15 # define NEED_sv_catpvn_flags
16 # include "ppport.h"
17 #endif
18  
19 #ifndef PERL_VERSION_DECIMAL
20 # define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
21 #endif
22 #ifndef PERL_DECIMAL_VERSION
23 # define PERL_DECIMAL_VERSION \
24 PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
25 #endif
26 #ifndef PERL_VERSION_GE
27 # define PERL_VERSION_GE(r,v,s) \
28 (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
29 #endif
30 #ifndef PERL_VERSION_LE
31 # define PERL_VERSION_LE(r,v,s) \
32 (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
33 #endif
34  
35 /* if to disallow \0 in names */
36 #if PERL_VERSION_LE(5,16,0) || (defined(USE_CPERL) && PERL_VERSION_GE(5,25,2))
37 # define PERL_STRIP_NUL
38 #endif
39  
40 #if PERL_VERSION_GE(5,6,0)
41 # include "multicall.h"
42 #endif
43  
44 #if PERL_VERSION_LE(5,8,8) && PERL_VERSION_GE(5,7,0)
45 #define COP_SEQ_RANGE_LOW(sv) U_32(SvNVX(sv))
46 #define COP_SEQ_RANGE_HIGH(sv) U_32(SvUVX(sv))
47 #endif
48  
49 /* since 5.16.0 */
50 #ifndef GvNAMEUTF8
51 # define GvNAMEUTF8(gv) 0
52 #endif
53 #ifndef HvNAMEUTF8
54 # define HvNAMEUTF8(hv) 0
55 #endif
56 /* since 5.8.9 */
57 #ifndef HV_FETCH_JUST_SV
58 # define HV_FETCH_JUST_SV 0
59 #endif
60  
61  
62 #if PERL_VERSION_GE(5,25,7) && !defined(USE_CPERL) && !defined(find_rundefsvoffset)
63 STATIC PADOFFSET
64 0 Perl_find_rundefsvoffset(pTHX)
65 {
66 0 return NOT_IN_PAD;
67 }
68 #endif
69  
70 #if PERL_VERSION_LE(5,8,9)
71 /* non-destructive variant, without cloning */
72 STATIC PADOFFSET
73 Perl_find_rundefsvoffset(pTHX)
74 {
75 # if PERL_VERSION_LE(5,7,0)
76 return NOT_IN_PAD;
77 # else
78 const char *name = "$_";
79 PADOFFSET newoff = 0;
80 const CV* innercv = Perl_find_runcv(aTHX_ NULL);
81 CV *cv;
82 I32 off = 0;
83 SV *sv;
84 CV* startcv;
85 U32 seq;
86 I32 depth;
87 AV *oldpad;
88 SV *oldsv;
89 AV *curlist;
90  
91 seq = CvOUTSIDE_SEQ(innercv);
92 startcv = CvOUTSIDE(innercv);
93  
94 for (cv = startcv; cv; seq = CvOUTSIDE_SEQ(cv), cv = CvOUTSIDE(cv)) {
95 SV **svp;
96 AV *curname;
97 I32 fake_off = 0;
98  
99 curlist = CvPADLIST(cv);
100 if (!curlist)
101 continue; /* an undef CV */
102 svp = av_fetch(curlist, 0, FALSE);
103 if (!svp || *svp == &PL_sv_undef)
104 continue;
105 curname = (AV*)*svp;
106 svp = AvARRAY(curname);
107  
108 depth = CvDEPTH(cv);
109 for (off = AvFILLp(curname); off > 0; off--) {
110 sv = svp[off];
111 if (!sv || sv == &PL_sv_undef || !strEQ(SvPVX_const(sv), name))
112 continue;
113 if (SvFAKE(sv)) {
114 /* we'll use this later if we don't find a real entry */
115 fake_off = off;
116 continue;
117 }
118 else {
119 if ( seq > COP_SEQ_RANGE_LOW(sv) /* min */
120 && seq <= COP_SEQ_RANGE_HIGH(sv) /* max */
121 && !(newoff && !depth) /* ignore inactive when cloning */
122 )
123 return off;
124 }
125 }
126  
127 /* no real entry - but did we find a fake one? */
128 if (fake_off) {
129 if (newoff && !depth)
130 return NOT_IN_PAD; /* don't clone from inactive stack frame */
131 off = fake_off;
132 return off;
133 }
134 }
135 return NOT_IN_PAD;
136 # endif
137 }
138 #endif
139  
140 #if !PERL_VERSION_GE(5,23,8)
141 # define UNUSED_VAR_newsp PERL_UNUSED_VAR(newsp)
142 #else
143 # define UNUSED_VAR_newsp NOOP
144 #endif
145  
146 #ifndef CvISXSUB
147 # define CvISXSUB(cv) CvXSUB(cv)
148 #endif
149  
150 #ifndef HvNAMELEN_get
151 #define HvNAMELEN_get(stash) strlen(HvNAME(stash))
152 #endif
153  
154 #ifndef HvNAMEUTF8
155 #define HvNAMEUTF8(stash) 0
156 #endif
157  
158 #ifndef GvNAMEUTF8
159 #ifdef GvNAME_HEK
160 #define GvNAMEUTF8(gv) HEK_UTF8(GvNAME_HEK(gv))
161 #else
162 #define GvNAMEUTF8(gv) 0
163 #endif
164 #endif
165  
166 #ifndef SV_CATUTF8
167 #define SV_CATUTF8 0
168 #endif
169  
170 #ifndef SV_CATBYTES
171 #define SV_CATBYTES 0
172 #endif
173  
174 #ifndef sv_catpvn_flags
175 #define sv_catpvn_flags(b,n,l,f) sv_catpvn(b,n,l)
176 #endif
177  
178 /* Some platforms have strict exports. And before 5.7.3 cxinc (or Perl_cxinc)
179 was not exported. Therefore platforms like win32, VMS etc have problems
180 so we redefine it here -- GMB
181 */
182 #if !PERL_VERSION_GE(5,7,0)
183 /* Not in 5.6.1. */
184 # ifdef cxinc
185 # undef cxinc
186 # endif
187 # define cxinc() my_cxinc(aTHX)
188 static I32
189 my_cxinc(pTHX)
190 {
191 cxstack_max = cxstack_max * 3 / 2;
192 Renew(cxstack, cxstack_max + 1, struct context); /* fencepost bug in older CXINC macros requires +1 here */
193 return cxstack_ix + 1;
194 }
195 #endif
196  
197 #ifndef sv_copypv
198 #define sv_copypv(a, b) my_sv_copypv(aTHX_ a, b)
199 static void
200 my_sv_copypv(pTHX_ SV *const dsv, SV *const ssv)
201 {
202 STRLEN len;
203 const char * const s = SvPV_const(ssv,len);
204 sv_setpvn(dsv,s,len);
205 if(SvUTF8(ssv))
206 SvUTF8_on(dsv);
207 else
208 SvUTF8_off(dsv);
209 }
210 #endif
211  
212 #ifdef SVf_IVisUV
213 # define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv))
214 #else
215 # define slu_sv_value(sv) (SvIOK(sv)) ? (NV)(SvIVX(sv)) : (SvNV(sv))
216 #endif
217  
218 #if PERL_VERSION < 13 || (PERL_VERSION == 13 && PERL_SUBVERSION < 9)
219 # define PERL_HAS_BAD_MULTICALL_REFCOUNT
220 #endif
221  
222 #if PERL_VERSION < 14
223 # define croak_no_modify() croak("%s", PL_no_modify)
224 #endif
225  
226 #ifndef SvNV_nomg
227 # define SvNV_nomg SvNV
228 #endif
229  
230 enum slu_accum {
231 ACC_IV,
232 ACC_NV,
233 ACC_SV,
234 };
235  
236 0 static enum slu_accum accum_type(SV *sv) {
237 0 ▶ if(SvAMAGIC(sv))
Branch: 3 branches
BranchTrueFalseTotal
if(SvAMAGIC(sv)) 0 0 0
if(SvAMAGIC(sv)) 0 0 0
if(SvAMAGIC(sv)) 0 0 0
238 0 return ACC_SV;
239  
240 0 ▶ if(SvIOK(sv) && !SvNOK(sv) && !SvUOK(sv))
Branch: 3 branches
BranchTrueFalseTotal
if(SvIOK(sv) && !SvNOK(sv) && !SvUOK(sv)) 0 0 0
if(SvIOK(sv) && !SvNOK(sv) && !SvUOK(sv)) 0 0 0
if(SvIOK(sv) && !SvNOK(sv) && !SvUOK(sv)) 0 0 0
241 0 return ACC_IV;
242  
243 0 return ACC_NV;
244 }
245  
246 /* Magic for set_subname */
247 static MGVTBL subname_vtbl;
248  
249 MODULE=List::Util PACKAGE=List::Util
250  
251 void
252 min(...)
253 PROTOTYPE: @
254 ALIAS:
255 min = 0
256 max = 1
257 CODE:
258 {
259 int index;
260 0 NV retval = 0.0; /* avoid 'uninit var' warning */
261 SV *retsv;
262 int magic;
263  
264 0 ▶ if(!items)
Branch: 1 branch
BranchTrueFalseTotal
if(!items) 0 0 0
265 0 XSRETURN_UNDEF;
266  
267 0 retsv = ST(0);
268 0 SvGETMAGIC(retsv);
269 0 ▶ magic = SvAMAGIC(retsv);
Branch: 3 branches
BranchTrueFalseTotal
magic = SvAMAGIC(retsv); 0 0 0
magic = SvAMAGIC(retsv); 0 0 0
magic = SvAMAGIC(retsv); 0 0 0
270 0 ▶ if(!magic)
Branch: 1 branch
BranchTrueFalseTotal
if(!magic) 0 0 0
271 0 ▶ retval = slu_sv_value(retsv);
Branch: 2 branches
BranchTrueFalseTotal
retval = slu_sv_value(retsv); 0 0 0
retval = slu_sv_value(retsv); 0 0 0
272  
273 0 ▶ for(index = 1 ; index < items ; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 1 ; index < items ; index++) { 0 0 0
274 0 SV *stacksv = ST(index);
275 SV *tmpsv;
276 0 SvGETMAGIC(stacksv);
277 0 ▶ if((magic || SvAMAGIC(stacksv)) && (tmpsv = amagic_call(retsv, stacksv, gt_amg, 0))) {
Branch: 5 branches
BranchTrueFalseTotal
if((magic || SvAMAGIC(stacksv)) && (tmpsv = amagic_call(retsv, stacksv, gt_amg, 0))) { 0 0 0
if((magic || SvAMAGIC(stacksv)) && (tmpsv = amagic_call(retsv, stacksv, gt_amg, 0))) { 0 0 0
if((magic || SvAMAGIC(stacksv)) && (tmpsv = amagic_call(retsv, stacksv, gt_amg, 0))) { 0 0 0
if((magic || SvAMAGIC(stacksv)) && (tmpsv = amagic_call(retsv, stacksv, gt_amg, 0))) { 0 0 0
if((magic || SvAMAGIC(stacksv)) && (tmpsv = amagic_call(retsv, stacksv, gt_amg, 0))) { 0 0 0
278 0 ▶ if(SvTRUE(tmpsv) ? !ix : ix) {
Branch: 2 branches
BranchTrueFalseTotal
if(SvTRUE(tmpsv) ? !ix : ix) { 0 0 0
if(SvTRUE(tmpsv) ? !ix : ix) { 0 0 0
279 0 retsv = stacksv;
280 0 ▶ magic = SvAMAGIC(retsv);
Branch: 3 branches
BranchTrueFalseTotal
magic = SvAMAGIC(retsv); 0 0 0
magic = SvAMAGIC(retsv); 0 0 0
magic = SvAMAGIC(retsv); 0 0 0
281 0 ▶ if(!magic) {
Branch: 1 branch
BranchTrueFalseTotal
if(!magic) { 0 0 0
282 0 ▶ retval = slu_sv_value(retsv);
Branch: 2 branches
BranchTrueFalseTotal
retval = slu_sv_value(retsv); 0 0 0
retval = slu_sv_value(retsv); 0 0 0
283 }
284 }
285 }
286 else {
287 0 ▶ NV val = slu_sv_value(stacksv);
Branch: 2 branches
BranchTrueFalseTotal
NV val = slu_sv_value(stacksv); 0 0 0
NV val = slu_sv_value(stacksv); 0 0 0
288 0 ▶ if(magic) {
Branch: 1 branch
BranchTrueFalseTotal
if(magic) { 0 0 0
289 0 ▶ retval = slu_sv_value(retsv);
Branch: 2 branches
BranchTrueFalseTotal
retval = slu_sv_value(retsv); 0 0 0
retval = slu_sv_value(retsv); 0 0 0
290 0 magic = 0;
291 }
292 0 ▶ if(val < retval ? !ix : ix) {
Branch: 2 branches
BranchTrueFalseTotal
if(val < retval ? !ix : ix) { 0 0 0
if(val < retval ? !ix : ix) { 0 0 0
293 0 retsv = stacksv;
294 0 retval = val;
295 }
296 }
297 }
298 0 ST(0) = retsv;
299 0 XSRETURN(1);
300 }
301  
302  
303 void
304 sum(...)
305 PROTOTYPE: @
306 ALIAS:
307 sum = 0
308 sum0 = 1
309 product = 2
310 CODE:
311 {
312 0 ▶ dXSTARG;
Branch: 1 branch
BranchTrueFalseTotal
dXSTARG; 0 0 0
313 SV *sv;
314 0 IV retiv = 0;
315 0 NV retnv = 0.0;
316 0 SV *retsv = NULL;
317 int index;
318 enum slu_accum accum;
319 0 int is_product = (ix == 2);
320 SV *tmpsv;
321  
322 0 ▶ if(!items)
Branch: 1 branch
BranchTrueFalseTotal
if(!items) 0 0 0
323 0 switch(ix) {
324 0 case 0: XSRETURN_UNDEF;
325 0 case 1: ST(0) = sv_2mortal(newSViv(0)); XSRETURN(1);
326 0 case 2: ST(0) = sv_2mortal(newSViv(1)); XSRETURN(1);
327 }
328  
329 0 sv = ST(0);
330 0 SvGETMAGIC(sv);
331 0 switch((accum = accum_type(sv))) {
332 0 case ACC_SV:
333 0 retsv = TARG;
334 0 sv_setsv(retsv, sv);
335 0 break;
336 0 case ACC_IV:
337 0 retiv = SvIV(sv);
338 0 break;
339 0 case ACC_NV:
340 0 ▶ retnv = slu_sv_value(sv);
Branch: 2 branches
BranchTrueFalseTotal
retnv = slu_sv_value(sv); 0 0 0
retnv = slu_sv_value(sv); 0 0 0
341 0 break;
342 }
343  
344 0 ▶ for(index = 1 ; index < items ; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 1 ; index < items ; index++) { 0 0 0
345 0 sv = ST(index);
346 0 SvGETMAGIC(sv);
347 0 ▶ if(accum < ACC_SV && SvAMAGIC(sv)){
Branch: 4 branches
BranchTrueFalseTotal
if(accum < ACC_SV && SvAMAGIC(sv)){ 0 0 0
if(accum < ACC_SV && SvAMAGIC(sv)){ 0 0 0
if(accum < ACC_SV && SvAMAGIC(sv)){ 0 0 0
if(accum < ACC_SV && SvAMAGIC(sv)){ 0 0 0
348 0 ▶ if(!retsv)
Branch: 1 branch
BranchTrueFalseTotal
if(!retsv) 0 0 0
349 0 retsv = TARG;
350 0 ▶ sv_setnv(retsv, accum == ACC_NV ? retnv : retiv);
Branch: 1 branch
BranchTrueFalseTotal
sv_setnv(retsv, accum == ACC_NV ? retnv : retiv); 0 0 0
351 0 accum = ACC_SV;
352 }
353 0 switch(accum) {
354 0 case ACC_SV:
355 0 ▶ tmpsv = amagic_call(retsv, sv,
Branch: 4 branches
BranchTrueFalseTotal
tmpsv = amagic_call(retsv, sv, 0 0 0
tmpsv = amagic_call(retsv, sv, 0 0 0
tmpsv = amagic_call(retsv, sv, 0 0 0
tmpsv = amagic_call(retsv, sv, 0 0 0
356 is_product ? mult_amg : add_amg,
357 SvAMAGIC(retsv) ? AMGf_assign : 0);
358 0 ▶ if(tmpsv) {
Branch: 1 branch
BranchTrueFalseTotal
if(tmpsv) { 0 0 0
359 0 switch((accum = accum_type(tmpsv))) {
360 0 case ACC_SV:
361 0 retsv = tmpsv;
362 0 break;
363 0 case ACC_IV:
364 0 retiv = SvIV(tmpsv);
365 0 break;
366 0 case ACC_NV:
367 0 ▶ retnv = slu_sv_value(tmpsv);
Branch: 2 branches
BranchTrueFalseTotal
retnv = slu_sv_value(tmpsv); 0 0 0
retnv = slu_sv_value(tmpsv); 0 0 0
368 0 break;
369 }
370 }
371 else {
372 /* fall back to default */
373 0 accum = ACC_NV;
374 0 is_product ? (retnv = SvNV(retsv) * SvNV(sv))
375 0 ▶ : (retnv = SvNV(retsv) + SvNV(sv));
Branch: 1 branch
BranchTrueFalseTotal
: (retnv = SvNV(retsv) + SvNV(sv)); 0 0 0
376 }
377 0 break;
378 0 case ACC_IV:
379 0 ▶ if(is_product) {
Branch: 1 branch
BranchTrueFalseTotal
if(is_product) { 0 0 0
380 /* TODO: Consider if product() should shortcircuit the moment its
381 * accumulator becomes zero
382 */
383 /* XXX testing flags before running get_magic may
384 * cause some valid tied values to fallback to the NV path
385 * - DAPM */
386 0 ▶ if(!SvNOK(sv) && SvIOK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if(!SvNOK(sv) && SvIOK(sv)) { 0 0 0
if(!SvNOK(sv) && SvIOK(sv)) { 0 0 0
387 0 IV i = SvIV(sv);
388 0 ▶ if (retiv == 0) /* avoid later division by zero */
Branch: 1 branch
BranchTrueFalseTotal
if (retiv == 0) /* avoid later division by zero */ 0 0 0
389 0 break;
390 0 ▶ if (retiv < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (retiv < 0) { 0 0 0
391 0 ▶ if (i < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (i < 0) { 0 0 0
392 0 ▶ if (i >= IV_MAX / retiv) {
Branch: 1 branch
BranchTrueFalseTotal
if (i >= IV_MAX / retiv) { 0 0 0
393 0 retiv *= i;
394 0 break;
395 }
396 }
397 else {
398 0 ▶ if (i <= IV_MIN / retiv) {
Branch: 1 branch
BranchTrueFalseTotal
if (i <= IV_MIN / retiv) { 0 0 0
399 0 retiv *= i;
400 0 break;
401 }
402 }
403 }
404 else {
405 0 ▶ if (i < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (i < 0) { 0 0 0
406 0 ▶ if (i >= IV_MIN / retiv) {
Branch: 1 branch
BranchTrueFalseTotal
if (i >= IV_MIN / retiv) { 0 0 0
407 0 retiv *= i;
408 0 break;
409 }
410 }
411 else {
412 0 ▶ if (i <= IV_MAX / retiv) {
Branch: 1 branch
BranchTrueFalseTotal
if (i <= IV_MAX / retiv) { 0 0 0
413 0 retiv *= i;
414 0 break;
415 }
416 }
417 }
418 }
419 /* else fallthrough */
420 }
421 else {
422 /* XXX testing flags before running get_magic may
423 * cause some valid tied values to fallback to the NV path
424 * - DAPM */
425 0 ▶ if(!SvNOK(sv) && SvIOK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if(!SvNOK(sv) && SvIOK(sv)) { 0 0 0
if(!SvNOK(sv) && SvIOK(sv)) { 0 0 0
426 0 IV i = SvIV(sv);
427 0 ▶ if (retiv >= 0 && i >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (retiv >= 0 && i >= 0) { 0 0 0
if (retiv >= 0 && i >= 0) { 0 0 0
428 0 ▶ if (retiv <= IV_MAX - i) {
Branch: 1 branch
BranchTrueFalseTotal
if (retiv <= IV_MAX - i) { 0 0 0
429 0 retiv += i;
430 0 break;
431 }
432 /* else fallthrough */
433 }
434 0 ▶ else if (retiv < 0 && i < 0) {
Branch: 2 branches
BranchTrueFalseTotal
else if (retiv < 0 && i < 0) { 0 0 0
else if (retiv < 0 && i < 0) { 0 0 0
435 0 ▶ if (retiv >= IV_MIN - i) {
Branch: 1 branch
BranchTrueFalseTotal
if (retiv >= IV_MIN - i) { 0 0 0
436 0 retiv += i;
437 0 break;
438 }
439 /* else fallthrough */
440 }
441 else {
442 /* mixed signs can't overflow */
443 0 retiv += i;
444 0 break;
445 }
446 }
447 /* else fallthrough */
448 }
449  
450 /* fallthrough to NV now */
451 0 retnv = retiv;
452 0 accum = ACC_NV;
453 0 case ACC_NV:
454 0 ▶ is_product ? (retnv *= slu_sv_value(sv))
Branch: 2 branches
BranchTrueFalseTotal
is_product ? (retnv *= slu_sv_value(sv)) 0 0 0
is_product ? (retnv *= slu_sv_value(sv)) 0 0 0
455 0 ▶ : (retnv += slu_sv_value(sv));
Branch: 3 branches
BranchTrueFalseTotal
: (retnv += slu_sv_value(sv)); 0 0 0
: (retnv += slu_sv_value(sv)); 0 0 0
: (retnv += slu_sv_value(sv)); 0 0 0
456 0 break;
457 }
458 }
459  
460 0 ▶ if(!retsv)
Branch: 1 branch
BranchTrueFalseTotal
if(!retsv) 0 0 0
461 0 retsv = TARG;
462  
463 0 switch(accum) {
464 0 case ACC_SV: /* nothing to do */
465 0 break;
466 0 case ACC_IV:
467 0 sv_setiv(retsv, retiv);
468 0 break;
469 0 case ACC_NV:
470 0 sv_setnv(retsv, retnv);
471 0 break;
472 }
473  
474 0 ST(0) = retsv;
475 0 XSRETURN(1);
476 }
477  
478 #define SLU_CMP_LARGER 1
479 #define SLU_CMP_SMALLER -1
480  
481 void
482 minstr(...)
483 PROTOTYPE: @
484 ALIAS:
485 minstr = SLU_CMP_LARGER
486 maxstr = SLU_CMP_SMALLER
487 CODE:
488 {
489 SV *left;
490 int index;
491  
492 0 ▶ if(!items)
Branch: 1 branch
BranchTrueFalseTotal
if(!items) 0 0 0
493 0 XSRETURN_UNDEF;
494  
495 0 left = ST(0);
496 #ifdef OPpLOCALE
497 if(MAXARG & OPpLOCALE) {
498 for(index = 1 ; index < items ; index++) {
499 SV *right = ST(index);
500 if(sv_cmp_locale(left, right) == ix)
501 left = right;
502 }
503 }
504 else {
505 #endif
506 0 ▶ for(index = 1 ; index < items ; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 1 ; index < items ; index++) { 0 0 0
507 0 SV *right = ST(index);
508 0 ▶ if(sv_cmp(left, right) == ix)
Branch: 1 branch
BranchTrueFalseTotal
if(sv_cmp(left, right) == ix) 0 0 0
509 0 left = right;
510 }
511 #ifdef OPpLOCALE
512 }
513 #endif
514 0 ST(0) = left;
515 0 XSRETURN(1);
516 }
517  
518  
519  
520  
521 void
522 reduce(block,...)
523 SV *block
524 PROTOTYPE: &@
525 CODE:
526 {
527 0 SV *ret = sv_newmortal();
528 int index;
529 GV *agv,*bgv,*gv;
530 HV *stash;
531 0 SV **args = &PL_stack_base[ax];
532 0 CV *cv = sv_2cv(block, &stash, &gv, 0);
533  
534 0 ▶ if(cv == Nullcv)
Branch: 1 branch
BranchTrueFalseTotal
if(cv == Nullcv) 0 0 0
535 0 croak("Not a subroutine reference");
536  
537 0 ▶ if(items <= 1)
Branch: 1 branch
BranchTrueFalseTotal
if(items <= 1) 0 0 0
538 0 XSRETURN_UNDEF;
539  
540 0 agv = gv_fetchpv("a", GV_ADD, SVt_PV);
541 0 bgv = gv_fetchpv("b", GV_ADD, SVt_PV);
542 0 SAVESPTR(GvSV(agv));
543 0 SAVESPTR(GvSV(bgv));
544 0 GvSV(agv) = ret;
545 0 ▶ SvSetMagicSV(ret, args[1]);
Branch: 2 branches
BranchTrueFalseTotal
SvSetMagicSV(ret, args[1]); 0 0 0
SvSetMagicSV(ret, args[1]); 0 0 0
546 #ifdef dMULTICALL
547 0 ▶ if(!CvISXSUB(cv)) {
Branch: 1 branch
BranchTrueFalseTotal
if(!CvISXSUB(cv)) { 0 0 0
548 dMULTICALL;
549 0 I32 gimme = G_SCALAR;
550  
551 UNUSED_VAR_newsp;
552 0 ▶ PUSH_MULTICALL(cv);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_MULTICALL(cv); 0 0 0
553 0 ▶ for(index = 2 ; index < items ; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 2 ; index < items ; index++) { 0 0 0
554 0 GvSV(bgv) = args[index];
555 0 MULTICALL;
556 0 ▶ SvSetMagicSV(ret, *PL_stack_sp);
Branch: 2 branches
BranchTrueFalseTotal
SvSetMagicSV(ret, *PL_stack_sp); 0 0 0
SvSetMagicSV(ret, *PL_stack_sp); 0 0 0
557 }
558 # ifdef PERL_HAS_BAD_MULTICALL_REFCOUNT
559 if(CvDEPTH(multicall_cv) > 1)
560 SvREFCNT_inc_simple_void_NN(multicall_cv);
561 # endif
562 0 ▶ POP_MULTICALL;
Branch: 1 branch
BranchTrueFalseTotal
POP_MULTICALL; 0 0 0
563 }
564 else
565 #endif
566 {
567 0 ▶ for(index = 2 ; index < items ; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 2 ; index < items ; index++) { 0 0 0
568 0 dSP;
569 0 GvSV(bgv) = args[index];
570  
571 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
572 0 call_sv((SV*)cv, G_SCALAR);
573  
574 0 ▶ SvSetMagicSV(ret, *PL_stack_sp);
Branch: 2 branches
BranchTrueFalseTotal
SvSetMagicSV(ret, *PL_stack_sp); 0 0 0
SvSetMagicSV(ret, *PL_stack_sp); 0 0 0
575 }
576 }
577  
578 0 ST(0) = ret;
579 0 XSRETURN(1);
580 }
581  
582 void
583 first(block,...)
584 SV *block
585 PROTOTYPE: &@
586 CODE:
587 {
588 int index;
589 GV *gv;
590 HV *stash;
591 0 SV **args = &PL_stack_base[ax];
592 0 CV *cv = sv_2cv(block, &stash, &gv, 0);
593 PADOFFSET targlex;
594 0 ▶ if(cv == Nullcv)
Branch: 1 branch
BranchTrueFalseTotal
if(cv == Nullcv) 0 0 0
595 0 croak("Not a subroutine reference");
596 0 ▶ if(items <= 1)
Branch: 1 branch
BranchTrueFalseTotal
if(items <= 1) 0 0 0
597 0 XSRETURN_UNDEF;
598 #ifdef dMULTICALL
599 0 ▶ if(!CvISXSUB(cv)) {
Branch: 1 branch
BranchTrueFalseTotal
if(!CvISXSUB(cv)) { 0 0 0
600 dMULTICALL;
601 0 I32 gimme = G_SCALAR;
602  
603 UNUSED_VAR_newsp;
604 0 ▶ PUSH_MULTICALL(cv);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_MULTICALL(cv); 0 0 0
605 0 targlex = Perl_find_rundefsvoffset(aTHX);
606 0 ▶ if (targlex == NOT_IN_PAD)
Branch: 1 branch
BranchTrueFalseTotal
if (targlex == NOT_IN_PAD) 0 0 0
607 0 SAVESPTR(GvSV(PL_defgv));
608 0 ▶ for(index = 1 ; index < items ; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 1 ; index < items ; index++) { 0 0 0
609 # if PERL_VERSION_GE(5,7,0)
610 0 ▶ if (targlex != NOT_IN_PAD) {
Branch: 1 branch
BranchTrueFalseTotal
if (targlex != NOT_IN_PAD) { 0 0 0
611 0 PAD_SVl(targlex) = args[index];
612 0 SvREFCNT_inc_NN(PAD_SVl(targlex));
613 }
614 else
615 # endif
616 0 GvSV(PL_defgv) = args[index];
617 0 MULTICALL;
618 0 ▶ if(SvTRUEx(*PL_stack_sp)) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvTRUEx(*PL_stack_sp)) { 0 0 0
619 # ifdef PERL_HAS_BAD_MULTICALL_REFCOUNT
620 if(CvDEPTH(multicall_cv) > 1)
621 SvREFCNT_inc_simple_void_NN(multicall_cv);
622 # endif
623 0 ▶ POP_MULTICALL;
Branch: 1 branch
BranchTrueFalseTotal
POP_MULTICALL; 0 0 0
624 0 ST(0) = ST(index);
625 0 XSRETURN(1);
626 }
627 }
628 # ifdef PERL_HAS_BAD_MULTICALL_REFCOUNT
629 if(CvDEPTH(multicall_cv) > 1)
630 SvREFCNT_inc_simple_void_NN(multicall_cv);
631 # endif
632 0 ▶ POP_MULTICALL;
Branch: 1 branch
BranchTrueFalseTotal
POP_MULTICALL; 0 0 0
633 }
634 else
635 #endif
636 {
637 0 SAVESPTR(GvSV(PL_defgv));
638 0 ▶ for(index = 1 ; index < items ; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 1 ; index < items ; index++) { 0 0 0
639 0 dSP;
640 0 GvSV(PL_defgv) = args[index];
641  
642 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
643 0 call_sv((SV*)cv, G_SCALAR);
644 0 ▶ if(SvTRUEx(*PL_stack_sp)) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvTRUEx(*PL_stack_sp)) { 0 0 0
645 0 ST(0) = ST(index);
646 0 XSRETURN(1);
647 }
648 }
649 }
650 0 XSRETURN_UNDEF;
651 }
652  
653  
654 void
655 any(block,...)
656 SV *block
657 ALIAS:
658 none = 0
659 all = 1
660 any = 2
661 notall = 3
662 PROTOTYPE: &@
663 PPCODE:
664 {
665 0 int ret_true = !(ix & 2); /* return true at end of loop for none/all; false for any/notall */
666 0 int invert = (ix & 1); /* invert block test for all/notall */
667 GV *gv;
668 HV *stash;
669 0 SV **args = &PL_stack_base[ax];
670 0 CV *cv = sv_2cv(block, &stash, &gv, 0);
671  
672 0 ▶ if(cv == Nullcv)
Branch: 1 branch
BranchTrueFalseTotal
if(cv == Nullcv) 0 0 0
673 0 croak("Not a subroutine reference");
674 #ifdef dMULTICALL
675 0 ▶ if(!CvISXSUB(cv)) {
Branch: 1 branch
BranchTrueFalseTotal
if(!CvISXSUB(cv)) { 0 0 0
676 dMULTICALL;
677 0 I32 gimme = G_SCALAR;
678 int index;
679 PADOFFSET targlex;
680  
681 UNUSED_VAR_newsp;
682 0 ▶ PUSH_MULTICALL(cv);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_MULTICALL(cv); 0 0 0
683 0 targlex = Perl_find_rundefsvoffset(aTHX);
684 0 ▶ if (targlex == NOT_IN_PAD)
Branch: 1 branch
BranchTrueFalseTotal
if (targlex == NOT_IN_PAD) 0 0 0
685 0 SAVESPTR(GvSV(PL_defgv));
686 0 ▶ for(index = 1; index < items; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 1; index < items; index++) { 0 0 0
687 # if PERL_VERSION_GE(5,7,0)
688 0 ▶ if (targlex != NOT_IN_PAD) {
Branch: 1 branch
BranchTrueFalseTotal
if (targlex != NOT_IN_PAD) { 0 0 0
689 0 PAD_SVl(targlex) = args[index];
690 0 SvREFCNT_inc_NN(PAD_SVl(targlex));
691 } else
692 # endif
693 {
694 # ifdef SvTEMP_off
695 0 SV *def_sv =
696 # endif
697 0 GvSV(PL_defgv) = args[index];
698 # ifdef SvTEMP_off
699 0 SvTEMP_off(def_sv);
700 # endif
701 }
702  
703 0 MULTICALL;
704 0 ▶ if(SvTRUEx(*PL_stack_sp) ^ invert) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvTRUEx(*PL_stack_sp) ^ invert) { 0 0 0
705 0 ▶ POP_MULTICALL;
Branch: 1 branch
BranchTrueFalseTotal
POP_MULTICALL; 0 0 0
706 0 ▶ ST(0) = ret_true ? &PL_sv_no : &PL_sv_yes;
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = ret_true ? &PL_sv_no : &PL_sv_yes; 0 0 0
707 0 XSRETURN(1);
708 }
709 }
710 0 ▶ POP_MULTICALL;
Branch: 1 branch
BranchTrueFalseTotal
POP_MULTICALL; 0 0 0
711 }
712 else
713 #endif
714 {
715 int index;
716 0 SAVESPTR(GvSV(PL_defgv));
717 0 ▶ for(index = 1; index < items; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 1; index < items; index++) { 0 0 0
718 0 dSP;
719 0 GvSV(PL_defgv) = args[index];
720  
721 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
722 0 call_sv((SV*)cv, G_SCALAR);
723 0 ▶ if(SvTRUEx(*PL_stack_sp) ^ invert) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvTRUEx(*PL_stack_sp) ^ invert) { 0 0 0
724 0 ▶ ST(0) = ret_true ? &PL_sv_no : &PL_sv_yes;
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = ret_true ? &PL_sv_no : &PL_sv_yes; 0 0 0
725 0 XSRETURN(1);
726 }
727 }
728 }
729  
730 0 ▶ ST(0) = ret_true ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = ret_true ? &PL_sv_yes : &PL_sv_no; 0 0 0
731 0 XSRETURN(1);
732 }
733  
734 void
735 head(size,...)
736 PROTOTYPE: $@
737 ALIAS:
738 head = 0
739 tail = 1
740 PPCODE:
741 {
742 0 int size = 0;
743 0 int start = 0;
744 0 int end = 0;
745 0 int i = 0;
746  
747 0 size = SvIV( ST(0) );
748  
749 0 ▶ if ( ix == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ix == 0 ) { 0 0 0
750 0 start = 1;
751 0 end = start + size;
752 0 ▶ if ( size < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( size < 0 ) { 0 0 0
753 0 end += items - 1;
754 }
755 0 ▶ if ( end > items ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( end > items ) { 0 0 0
756 0 end = items;
757 }
758 }
759 else {
760 0 end = items;
761 0 ▶ if ( size < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( size < 0 ) { 0 0 0
762 0 start = -size + 1;
763 }
764 else {
765 0 start = end - size;
766 }
767 0 ▶ if ( start < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( start < 1 ) { 0 0 0
768 0 start = 1;
769 }
770 }
771  
772 0 ▶ if ( end < start ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( end < start ) { 0 0 0
773 0 XSRETURN(0);
774 }
775 else {
776 0 ▶ EXTEND( SP, end - start );
Branch: 2 branches
BranchTrueFalseTotal
EXTEND( SP, end - start ); 0 0 0
EXTEND( SP, end - start ); 0 0 0
777 0 ▶ for ( i = start; i <= end; i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
for ( i = start; i <= end; i++ ) { 0 0 0
778 0 PUSHs( sv_2mortal( newSVsv( ST(i) ) ) );
779 }
780 0 XSRETURN( end - start );
781 }
782 }
783  
784 void
785 pairs(...)
786 PROTOTYPE: @
787 PPCODE:
788 {
789 0 int argi = 0;
790 0 int reti = 0;
791 0 HV *pairstash = get_hv("List::Util::_Pair::", GV_ADD);
792  
793 0 ▶ if(items % 2 && ckWARN(WARN_MISC))
Branch: 2 branches
BranchTrueFalseTotal
if(items % 2 && ckWARN(WARN_MISC)) 0 0 0
if(items % 2 && ckWARN(WARN_MISC)) 0 0 0
794 0 warn("Odd number of elements in pairs");
795  
796 {
797 0 ▶ for(; argi < items; argi += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for(; argi < items; argi += 2) { 0 0 0
798 0 SV *a = ST(argi);
799 0 ▶ SV *b = argi < items-1 ? ST(argi+1) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *b = argi < items-1 ? ST(argi+1) : &PL_sv_undef; 0 0 0
800  
801 0 AV *av = newAV();
802 0 av_push(av, newSVsv(a));
803 0 av_push(av, newSVsv(b));
804  
805 0 ST(reti) = sv_2mortal(newRV_noinc((SV *)av));
806 0 sv_bless(ST(reti), pairstash);
807 0 reti++;
808 }
809 }
810  
811 0 XSRETURN(reti);
812 }
813  
814 void
815 unpairs(...)
816 PROTOTYPE: @
817 PPCODE:
818 {
819 /* Unlike pairs(), we're going to trash the input values on the stack
820 * almost as soon as we start generating output. So clone them first
821 */
822 int i;
823 SV **args_copy;
824 0 Newx(args_copy, items, SV *);
825 0 SAVEFREEPV(args_copy);
826  
827 0 Copy(&ST(0), args_copy, items, SV *);
828  
829 0 ▶ for(i = 0; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < items; i++) { 0 0 0
830 0 SV *pair = args_copy[i];
831 AV *pairav;
832  
833 0 SvGETMAGIC(pair);
834  
835 0 ▶ if(SvTYPE(pair) != SVt_RV)
Branch: 1 branch
BranchTrueFalseTotal
if(SvTYPE(pair) != SVt_RV) 0 0 0
836 0 croak("Not a reference at List::Util::unpairs() argument %d", i);
837 0 ▶ if(SvTYPE(SvRV(pair)) != SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
if(SvTYPE(SvRV(pair)) != SVt_PVAV) 0 0 0
838 0 croak("Not an ARRAY reference at List::Util::unpairs() argument %d", i);
839  
840 /* TODO: assert pair is an ARRAY ref */
841 0 pairav = (AV *)SvRV(pair);
842  
843 0 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 0 0
844  
845 0 ▶ if(AvFILL(pairav) >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if(AvFILL(pairav) >= 0) 0 0 0
846 0 mPUSHs(newSVsv(AvARRAY(pairav)[0]));
847 else
848 0 PUSHs(&PL_sv_undef);
849  
850 0 ▶ if(AvFILL(pairav) >= 1)
Branch: 1 branch
BranchTrueFalseTotal
if(AvFILL(pairav) >= 1) 0 0 0
851 0 mPUSHs(newSVsv(AvARRAY(pairav)[1]));
852 else
853 0 PUSHs(&PL_sv_undef);
854 }
855  
856 0 XSRETURN(items * 2);
857 }
858  
859 void
860 pairkeys(...)
861 PROTOTYPE: @
862 PPCODE:
863 {
864 0 int argi = 0;
865 0 int reti = 0;
866  
867 0 ▶ if(items % 2 && ckWARN(WARN_MISC))
Branch: 2 branches
BranchTrueFalseTotal
if(items % 2 && ckWARN(WARN_MISC)) 0 0 0
if(items % 2 && ckWARN(WARN_MISC)) 0 0 0
868 0 warn("Odd number of elements in pairkeys");
869  
870 {
871 0 ▶ for(; argi < items; argi += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for(; argi < items; argi += 2) { 0 0 0
872 0 SV *a = ST(argi);
873  
874 0 ST(reti++) = sv_2mortal(newSVsv(a));
875 }
876 }
877  
878 0 XSRETURN(reti);
879 }
880  
881 void
882 pairvalues(...)
883 PROTOTYPE: @
884 PPCODE:
885 {
886 0 int argi = 0;
887 0 int reti = 0;
888  
889 0 ▶ if(items % 2 && ckWARN(WARN_MISC))
Branch: 2 branches
BranchTrueFalseTotal
if(items % 2 && ckWARN(WARN_MISC)) 0 0 0
if(items % 2 && ckWARN(WARN_MISC)) 0 0 0
890 0 warn("Odd number of elements in pairvalues");
891  
892 {
893 0 ▶ for(; argi < items; argi += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for(; argi < items; argi += 2) { 0 0 0
894 0 ▶ SV *b = argi < items-1 ? ST(argi+1) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *b = argi < items-1 ? ST(argi+1) : &PL_sv_undef; 0 0 0
895  
896 0 ST(reti++) = sv_2mortal(newSVsv(b));
897 }
898 }
899  
900 0 XSRETURN(reti);
901 }
902  
903 void
904 pairfirst(block,...)
905 SV *block
906 PROTOTYPE: &@
907 PPCODE:
908 {
909 GV *agv,*bgv,*gv;
910 HV *stash;
911 0 CV *cv = sv_2cv(block, &stash, &gv, 0);
912 0 I32 ret_gimme = GIMME_V;
913 0 int argi = 1; /* "shift" the block */
914  
915 0 ▶ if(!(items % 2) && ckWARN(WARN_MISC))
Branch: 2 branches
BranchTrueFalseTotal
if(!(items % 2) && ckWARN(WARN_MISC)) 0 0 0
if(!(items % 2) && ckWARN(WARN_MISC)) 0 0 0
916 0 warn("Odd number of elements in pairfirst");
917 0 ▶ if(cv == Nullcv)
Branch: 1 branch
BranchTrueFalseTotal
if(cv == Nullcv) 0 0 0
918 0 croak("Not a subroutine reference");
919  
920 0 agv = gv_fetchpv("a", GV_ADD, SVt_PV);
921 0 bgv = gv_fetchpv("b", GV_ADD, SVt_PV);
922 0 SAVESPTR(GvSV(agv));
923 0 SAVESPTR(GvSV(bgv));
924 #ifdef dMULTICALL
925 0 ▶ if(!CvISXSUB(cv)) {
Branch: 1 branch
BranchTrueFalseTotal
if(!CvISXSUB(cv)) { 0 0 0
926 /* Since MULTICALL is about to move it */
927 0 SV **stack = PL_stack_base + ax;
928  
929 dMULTICALL;
930 0 I32 gimme = G_SCALAR;
931  
932 UNUSED_VAR_newsp;
933 0 ▶ PUSH_MULTICALL(cv);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_MULTICALL(cv); 0 0 0
934 0 ▶ for(; argi < items; argi += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for(; argi < items; argi += 2) { 0 0 0
935 0 SV *a = GvSV(agv) = stack[argi];
936 0 ▶ SV *b = GvSV(bgv) = argi < items-1 ? stack[argi+1] : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *b = GvSV(bgv) = argi < items-1 ? stack[argi+1] : &PL_sv_undef; 0 0 0
937  
938 0 MULTICALL;
939  
940 0 ▶ if(!SvTRUEx(*PL_stack_sp))
Branch: 1 branch
BranchTrueFalseTotal
if(!SvTRUEx(*PL_stack_sp)) 0 0 0
941 0 continue;
942  
943 0 ▶ POP_MULTICALL;
Branch: 1 branch
BranchTrueFalseTotal
POP_MULTICALL; 0 0 0
944 0 ▶ if(ret_gimme == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if(ret_gimme == G_ARRAY) { 0 0 0
945 0 ST(0) = sv_mortalcopy(a);
946 0 ST(1) = sv_mortalcopy(b);
947 0 XSRETURN(2);
948 }
949 else
950 0 XSRETURN_YES;
951 }
952 0 ▶ POP_MULTICALL;
Branch: 1 branch
BranchTrueFalseTotal
POP_MULTICALL; 0 0 0
953 0 XSRETURN(0);
954 }
955 else
956 #endif
957 {
958 0 ▶ for(; argi < items; argi += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for(; argi < items; argi += 2) { 0 0 0
959 0 dSP;
960 0 SV *a = GvSV(agv) = ST(argi);
961 0 ▶ SV *b = GvSV(bgv) = argi < items-1 ? ST(argi+1) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *b = GvSV(bgv) = argi < items-1 ? ST(argi+1) : &PL_sv_undef; 0 0 0
962  
963 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
964 0 call_sv((SV*)cv, G_SCALAR);
965  
966 0 SPAGAIN;
967  
968 0 ▶ if(!SvTRUEx(*PL_stack_sp))
Branch: 1 branch
BranchTrueFalseTotal
if(!SvTRUEx(*PL_stack_sp)) 0 0 0
969 0 continue;
970  
971 0 ▶ if(ret_gimme == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if(ret_gimme == G_ARRAY) { 0 0 0
972 0 ST(0) = sv_mortalcopy(a);
973 0 ST(1) = sv_mortalcopy(b);
974 0 XSRETURN(2);
975 }
976 else
977 0 XSRETURN_YES;
978 }
979 }
980  
981 0 XSRETURN(0);
982 }
983  
984 void
985 pairgrep(block,...)
986 SV *block
987 PROTOTYPE: &@
988 PPCODE:
989 {
990 GV *agv,*bgv,*gv;
991 HV *stash;
992 0 CV *cv = sv_2cv(block, &stash, &gv, 0);
993 0 I32 ret_gimme = GIMME_V;
994  
995 /* This function never returns more than it consumed in arguments. So we
996 * can build the results "live", behind the arguments
997 */
998 0 int argi = 1; /* "shift" the block */
999 0 int reti = 0;
1000  
1001 0 ▶ if(!(items % 2) && ckWARN(WARN_MISC))
Branch: 2 branches
BranchTrueFalseTotal
if(!(items % 2) && ckWARN(WARN_MISC)) 0 0 0
if(!(items % 2) && ckWARN(WARN_MISC)) 0 0 0
1002 0 warn("Odd number of elements in pairgrep");
1003 0 ▶ if(cv == Nullcv)
Branch: 1 branch
BranchTrueFalseTotal
if(cv == Nullcv) 0 0 0
1004 0 croak("Not a subroutine reference");
1005  
1006 0 agv = gv_fetchpv("a", GV_ADD, SVt_PV);
1007 0 bgv = gv_fetchpv("b", GV_ADD, SVt_PV);
1008 0 SAVESPTR(GvSV(agv));
1009 0 SAVESPTR(GvSV(bgv));
1010 #ifdef dMULTICALL
1011 0 ▶ if(!CvISXSUB(cv)) {
Branch: 1 branch
BranchTrueFalseTotal
if(!CvISXSUB(cv)) { 0 0 0
1012 /* Since MULTICALL is about to move it */
1013 0 SV **stack = PL_stack_base + ax;
1014 int i;
1015  
1016 dMULTICALL;
1017 0 I32 gimme = G_SCALAR;
1018  
1019 UNUSED_VAR_newsp;
1020 0 ▶ PUSH_MULTICALL(cv);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_MULTICALL(cv); 0 0 0
1021 0 ▶ for(; argi < items; argi += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for(; argi < items; argi += 2) { 0 0 0
1022 0 SV *a = GvSV(agv) = stack[argi];
1023 0 ▶ SV *b = GvSV(bgv) = argi < items-1 ? stack[argi+1] : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *b = GvSV(bgv) = argi < items-1 ? stack[argi+1] : &PL_sv_undef; 0 0 0
1024  
1025 0 MULTICALL;
1026  
1027 0 ▶ if(SvTRUEx(*PL_stack_sp)) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvTRUEx(*PL_stack_sp)) { 0 0 0
1028 0 ▶ if(ret_gimme == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if(ret_gimme == G_ARRAY) { 0 0 0
1029 /* We can't mortalise yet or they'd be mortal too early */
1030 0 stack[reti++] = newSVsv(a);
1031 0 stack[reti++] = newSVsv(b);
1032 }
1033 0 ▶ else if(ret_gimme == G_SCALAR)
Branch: 1 branch
BranchTrueFalseTotal
else if(ret_gimme == G_SCALAR) 0 0 0
1034 0 reti++;
1035 }
1036 }
1037 0 ▶ POP_MULTICALL;
Branch: 1 branch
BranchTrueFalseTotal
POP_MULTICALL; 0 0 0
1038  
1039 0 ▶ if(ret_gimme == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if(ret_gimme == G_ARRAY) 0 0 0
1040 0 ▶ for(i = 0; i < reti; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < reti; i++) 0 0 0
1041 0 sv_2mortal(stack[i]);
1042 }
1043 else
1044 #endif
1045 {
1046 0 ▶ for(; argi < items; argi += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for(; argi < items; argi += 2) { 0 0 0
1047 0 dSP;
1048 0 SV *a = GvSV(agv) = ST(argi);
1049 0 ▶ SV *b = GvSV(bgv) = argi < items-1 ? ST(argi+1) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *b = GvSV(bgv) = argi < items-1 ? ST(argi+1) : &PL_sv_undef; 0 0 0
1050  
1051 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
1052 0 call_sv((SV*)cv, G_SCALAR);
1053  
1054 0 SPAGAIN;
1055  
1056 0 ▶ if(SvTRUEx(*PL_stack_sp)) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvTRUEx(*PL_stack_sp)) { 0 0 0
1057 0 ▶ if(ret_gimme == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if(ret_gimme == G_ARRAY) { 0 0 0
1058 0 ST(reti++) = sv_mortalcopy(a);
1059 0 ST(reti++) = sv_mortalcopy(b);
1060 }
1061 0 ▶ else if(ret_gimme == G_SCALAR)
Branch: 1 branch
BranchTrueFalseTotal
else if(ret_gimme == G_SCALAR) 0 0 0
1062 0 reti++;
1063 }
1064 }
1065 }
1066  
1067 0 ▶ if(ret_gimme == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if(ret_gimme == G_ARRAY) 0 0 0
1068 0 XSRETURN(reti);
1069 0 ▶ else if(ret_gimme == G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
else if(ret_gimme == G_SCALAR) { 0 0 0
1070 0 ST(0) = newSViv(reti);
1071 0 XSRETURN(1);
1072 }
1073 }
1074  
1075 void
1076 pairmap(block,...)
1077 SV *block
1078 PROTOTYPE: &@
1079 PPCODE:
1080 {
1081 GV *agv,*bgv,*gv;
1082 HV *stash;
1083 0 CV *cv = sv_2cv(block, &stash, &gv, 0);
1084 0 SV **args_copy = NULL;
1085 0 I32 ret_gimme = GIMME_V;
1086  
1087 0 int argi = 1; /* "shift" the block */
1088 0 int reti = 0;
1089  
1090 0 ▶ if(!(items % 2) && ckWARN(WARN_MISC))
Branch: 2 branches
BranchTrueFalseTotal
if(!(items % 2) && ckWARN(WARN_MISC)) 0 0 0
if(!(items % 2) && ckWARN(WARN_MISC)) 0 0 0
1091 0 warn("Odd number of elements in pairmap");
1092 0 ▶ if(cv == Nullcv)
Branch: 1 branch
BranchTrueFalseTotal
if(cv == Nullcv) 0 0 0
1093 0 croak("Not a subroutine reference");
1094  
1095 0 agv = gv_fetchpv("a", GV_ADD, SVt_PV);
1096 0 bgv = gv_fetchpv("b", GV_ADD, SVt_PV);
1097 0 SAVESPTR(GvSV(agv));
1098 0 SAVESPTR(GvSV(bgv));
1099 /* This MULTICALL-based code appears to fail on perl 5.10.0 and 5.8.9
1100 * Skip it on those versions (RT#87857)
1101 */
1102 #if defined(dMULTICALL) && (PERL_VERSION_GE(5,10,1) || PERL_VERSION_LE(5,8,8))
1103 assert(cv);
1104 0 ▶ if(!CvISXSUB(cv)) {
Branch: 1 branch
BranchTrueFalseTotal
if(!CvISXSUB(cv)) { 0 0 0
1105 /* Since MULTICALL is about to move it */
1106 0 SV **stack = PL_stack_base + ax;
1107 0 I32 ret_gimme = GIMME_V;
1108 int i;
1109 0 AV *spill = NULL; /* accumulates results if too big for stack */
1110  
1111 dMULTICALL;
1112 0 I32 gimme = G_ARRAY;
1113  
1114 UNUSED_VAR_newsp;
1115 0 ▶ PUSH_MULTICALL(cv);
Branch: 1 branch
BranchTrueFalseTotal
PUSH_MULTICALL(cv); 0 0 0
1116 0 ▶ for(; argi < items; argi += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for(; argi < items; argi += 2) { 0 0 0
1117 int count;
1118  
1119 0 GvSV(agv) = stack[argi];
1120 0 ▶ GvSV(bgv) = argi < items-1 ? stack[argi+1]: &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
GvSV(bgv) = argi < items-1 ? stack[argi+1]: &PL_sv_undef; 0 0 0
1121  
1122 0 MULTICALL;
1123 0 count = PL_stack_sp - PL_stack_base;
1124  
1125 0 ▶ if (count > 2 || spill) {
Branch: 2 branches
BranchTrueFalseTotal
if (count > 2 || spill) { 0 0 0
if (count > 2 || spill) { 0 0 0
1126 /* We can't return more than 2 results for a given input pair
1127 * without trashing the remaining arguments on the stack still
1128 * to be processed, or possibly overrunning the stack end.
1129 * So, we'll accumulate the results in a temporary buffer
1130 * instead.
1131 * We didn't do this initially because in the common case, most
1132 * code blocks will return only 1 or 2 items so it won't be
1133 * necessary
1134 */
1135 int fill;
1136  
1137 0 ▶ if (!spill) {
Branch: 1 branch
BranchTrueFalseTotal
if (!spill) { 0 0 0
1138 0 spill = newAV();
1139 0 AvREAL_off(spill); /* don't ref count its contents */
1140 /* can't mortalize here as every nextstate in the code
1141 * block frees temps */
1142 0 SAVEFREESV(spill);
1143 }
1144  
1145 0 fill = (int)AvFILL(spill);
1146 0 av_extend(spill, fill + count);
1147 0 ▶ for(i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < count; i++) 0 0 0
1148 0 (void)av_store(spill, ++fill,
1149 newSVsv(PL_stack_base[i + 1]));
1150 }
1151 else
1152 0 ▶ for(i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < count; i++) 0 0 0
1153 0 stack[reti++] = newSVsv(PL_stack_base[i + 1]);
1154 }
1155  
1156 /* the POP_MULTICALL will trigger the SAVEFREESV above;
1157 * keep it alive it on the temps stack instead */
1158 0 ▶ SvREFCNT_inc_simple_void(spill);
Branch: 1 branch
BranchTrueFalseTotal
SvREFCNT_inc_simple_void(spill); 0 0 0
1159  
1160 0 ▶ POP_MULTICALL;
Branch: 1 branch
BranchTrueFalseTotal
POP_MULTICALL; 0 0 0
1161  
1162 0 ▶ if (spill) {
Branch: 1 branch
BranchTrueFalseTotal
if (spill) { 0 0 0
1163 0 int n = (int)AvFILL(spill) + 1;
1164 0 SP = &ST(reti - 1);
1165 0 ▶ EXTEND(SP, n);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, n); 0 0 0
EXTEND(SP, n); 0 0 0
1166 0 ▶ for (i = 0; i < n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) 0 0 0
1167 0 *++SP = *av_fetch(spill, i, FALSE);
1168 0 reti += n;
1169 0 av_clear(spill);
1170 }
1171  
1172 0 ▶ if(ret_gimme == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if(ret_gimme == G_ARRAY) 0 0 0
1173 0 ▶ for(i = 0; i < reti; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < reti; i++) 0 0 0
1174 0 sv_2mortal(ST(i));
1175 }
1176 else
1177 #endif
1178 {
1179 0 ▶ for(; argi < items; argi += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for(; argi < items; argi += 2) { 0 0 0
1180 0 dSP;
1181 int count;
1182 int i;
1183  
1184 0 ▶ GvSV(agv) = args_copy ? args_copy[argi] : ST(argi);
Branch: 1 branch
BranchTrueFalseTotal
GvSV(agv) = args_copy ? args_copy[argi] : ST(argi); 0 0 0
1185 0 GvSV(bgv) = argi < items-1 ?
1186 0 ▶ (args_copy ? args_copy[argi+1] : ST(argi+1)) :
Branch: 2 branches
BranchTrueFalseTotal
(args_copy ? args_copy[argi+1] : ST(argi+1)) : 0 0 0
(args_copy ? args_copy[argi+1] : ST(argi+1)) : 0 0 0
1187 &PL_sv_undef;
1188  
1189 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
1190 0 count = call_sv((SV*)cv, G_ARRAY);
1191  
1192 0 SPAGAIN;
1193  
1194 0 ▶ if(count > 2 && !args_copy && ret_gimme == G_ARRAY) {
Branch: 3 branches
BranchTrueFalseTotal
if(count > 2 && !args_copy && ret_gimme == G_ARRAY) { 0 0 0
if(count > 2 && !args_copy && ret_gimme == G_ARRAY) { 0 0 0
if(count > 2 && !args_copy && ret_gimme == G_ARRAY) { 0 0 0
1195 0 int n_args = items - argi;
1196 0 Newx(args_copy, n_args, SV *);
1197 0 SAVEFREEPV(args_copy);
1198  
1199 0 Copy(&ST(argi), args_copy, n_args, SV *);
1200  
1201 0 argi = 0;
1202 0 items = n_args;
1203 }
1204  
1205 0 ▶ if(ret_gimme == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if(ret_gimme == G_ARRAY) 0 0 0
1206 0 ▶ for(i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < count; i++) 0 0 0
1207 0 ST(reti++) = sv_mortalcopy(SP[i - count + 1]);
1208 else
1209 0 reti += count;
1210  
1211 0 PUTBACK;
1212 }
1213 }
1214  
1215 0 ▶ if(ret_gimme == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if(ret_gimme == G_ARRAY) 0 0 0
1216 0 XSRETURN(reti);
1217  
1218 0 ST(0) = sv_2mortal(newSViv(reti));
1219 0 XSRETURN(1);
1220 }
1221  
1222 void
1223 shuffle(...)
1224 PROTOTYPE: @
1225 CODE:
1226 {
1227 int index;
1228 #if (PERL_VERSION < 9)
1229 struct op dmy_op;
1230 struct op *old_op = PL_op;
1231  
1232 /* We call pp_rand here so that Drand01 get initialized if rand()
1233 or srand() has not already been called
1234 */
1235 memzero((char*)(&dmy_op), sizeof(struct op));
1236 /* we let pp_rand() borrow the TARG allocated for this XS sub */
1237 dmy_op.op_targ = PL_op->op_targ;
1238 PL_op = &dmy_op;
1239 (void)*(PL_ppaddr[OP_RAND])(aTHX);
1240 PL_op = old_op;
1241 #else
1242 /* Initialize Drand01 if rand() or srand() has
1243 not already been called
1244 */
1245 0 ▶ if(!PL_srand_called) {
Branch: 1 branch
BranchTrueFalseTotal
if(!PL_srand_called) { 0 0 0
1246 0 (void)seedDrand01((Rand_seed_t)Perl_seed(aTHX));
1247 0 PL_srand_called = TRUE;
1248 }
1249 #endif
1250  
1251 0 ▶ for (index = items ; index > 1 ; ) {
Branch: 1 branch
BranchTrueFalseTotal
for (index = items ; index > 1 ; ) { 0 0 0
1252 0 int swap = (int)(Drand01() * (double)(index--));
1253 0 SV *tmp = ST(swap);
1254 0 ST(swap) = ST(index);
1255 0 ST(index) = tmp;
1256 }
1257  
1258 0 XSRETURN(items);
1259 }
1260  
1261  
1262 void
1263 uniq(...)
1264 PROTOTYPE: @
1265 ALIAS:
1266 uniqnum = 0
1267 uniqstr = 1
1268 uniq = 2
1269 CODE:
1270 {
1271 0 int retcount = 0;
1272 int index;
1273 0 SV **args = &PL_stack_base[ax];
1274 HV *seen;
1275  
1276 0 ▶ if(items == 0 || (items == 1 && !SvGAMAGIC(args[0]) && SvOK(args[0]))) {
Branch: 7 branches
BranchTrueFalseTotal
if(items == 0 || (items == 1 && !SvGAMAGIC(args[0]) && SvOK(args[0]))) { 0 0 0
if(items == 0 || (items == 1 && !SvGAMAGIC(args[0]) && SvOK(args[0]))) { 0 0 0
if(items == 0 || (items == 1 && !SvGAMAGIC(args[0]) && SvOK(args[0]))) { 0 0 0
if(items == 0 || (items == 1 && !SvGAMAGIC(args[0]) && SvOK(args[0]))) { 0 0 0
if(items == 0 || (items == 1 && !SvGAMAGIC(args[0]) && SvOK(args[0]))) { 0 0 0
if(items == 0 || (items == 1 && !SvGAMAGIC(args[0]) && SvOK(args[0]))) { 0 0 0
if(items == 0 || (items == 1 && !SvGAMAGIC(args[0]) && SvOK(args[0]))) { 0 0 0
1277 /* Optimise for the case of the empty list or a defined nonmagic
1278 * singleton. Leave a singleton magical||undef for the regular case */
1279 0 retcount = items;
1280 0 goto finish;
1281 }
1282  
1283 0 sv_2mortal((SV *)(seen = newHV()));
1284  
1285 0 ▶ if(ix == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(ix == 0) { 0 0 0
1286 /* uniqnum */
1287 /* A temporary buffer for number stringification */
1288 0 SV *keysv = sv_newmortal();
1289  
1290 0 ▶ for(index = 0 ; index < items ; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 0 ; index < items ; index++) { 0 0 0
1291 0 SV *arg = args[index];
1292  
1293 0 ▶ if(SvGAMAGIC(arg))
Branch: 4 branches
BranchTrueFalseTotal
if(SvGAMAGIC(arg)) 0 0 0
if(SvGAMAGIC(arg)) 0 0 0
if(SvGAMAGIC(arg)) 0 0 0
if(SvGAMAGIC(arg)) 0 0 0
1294 /* clone the value so we don't invoke magic again */
1295 0 arg = sv_mortalcopy(arg);
1296  
1297 0 ▶ if(SvUOK(arg))
Branch: 1 branch
BranchTrueFalseTotal
if(SvUOK(arg)) 0 0 0
1298 0 sv_setpvf(keysv, "%" UVuf, SvUV(arg));
1299 0 ▶ else if(SvIOK(arg))
Branch: 1 branch
BranchTrueFalseTotal
else if(SvIOK(arg)) 0 0 0
1300 0 sv_setpvf(keysv, "%" IVdf, SvIV(arg));
1301 else
1302 0 sv_setpvf(keysv, "%" NVgf, SvNV(arg));
1303 #ifdef HV_FETCH_EMPTY_HE
1304 {
1305 0 HE* he = (HE*)hv_common(seen, NULL, SvPVX(keysv), SvCUR(keysv), 0,
1306 HV_FETCH_LVALUE | HV_FETCH_EMPTY_HE, NULL, 0);
1307 0 ▶ if (HeVAL(he))
Branch: 1 branch
BranchTrueFalseTotal
if (HeVAL(he)) 0 0 0
1308 0 continue;
1309  
1310 0 HeVAL(he) = &PL_sv_undef;
1311 }
1312 #else
1313 if(hv_exists(seen, SvPVX(keysv), SvCUR(keysv)))
1314 continue;
1315  
1316 hv_store(seen, SvPVX(keysv), SvCUR(keysv), &PL_sv_yes, 0);
1317 #endif
1318  
1319 0 ▶ if(GIMME_V == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if(GIMME_V == G_ARRAY) 0 0 0
1320 0 ▶ ST(retcount) = SvOK(arg) ? arg : sv_2mortal(newSViv(0));
Branch: 1 branch
BranchTrueFalseTotal
ST(retcount) = SvOK(arg) ? arg : sv_2mortal(newSViv(0)); 0 0 0
1321 0 retcount++;
1322 }
1323 }
1324 else {
1325 /* uniqstr or uniq */
1326 0 int seen_undef = 0;
1327  
1328 0 ▶ for(index = 0 ; index < items ; index++) {
Branch: 1 branch
BranchTrueFalseTotal
for(index = 0 ; index < items ; index++) { 0 0 0
1329 0 SV *arg = args[index];
1330  
1331 0 ▶ if(SvGAMAGIC(arg))
Branch: 4 branches
BranchTrueFalseTotal
if(SvGAMAGIC(arg)) 0 0 0
if(SvGAMAGIC(arg)) 0 0 0
if(SvGAMAGIC(arg)) 0 0 0
if(SvGAMAGIC(arg)) 0 0 0
1332 /* clone the value so we don't invoke magic again */
1333 0 arg = sv_mortalcopy(arg);
1334  
1335 0 ▶ if(ix == 2 && !SvOK(arg)) {
Branch: 2 branches
BranchTrueFalseTotal
if(ix == 2 && !SvOK(arg)) { 0 0 0
if(ix == 2 && !SvOK(arg)) { 0 0 0
1336 /* special handling of undef for uniq() */
1337 0 ▶ if(seen_undef)
Branch: 1 branch
BranchTrueFalseTotal
if(seen_undef) 0 0 0
1338 0 continue;
1339  
1340 0 seen_undef++;
1341  
1342 0 ▶ if(GIMME_V == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if(GIMME_V == G_ARRAY) 0 0 0
1343 0 ST(retcount) = arg;
1344 0 retcount++;
1345 0 continue;
1346 }
1347 #ifdef HV_FETCH_EMPTY_HE
1348 {
1349 0 HE* he = (HE*)hv_common(seen, arg, NULL, 0, 0, HV_FETCH_LVALUE | HV_FETCH_EMPTY_HE, NULL, 0);
1350 0 ▶ if (HeVAL(he))
Branch: 1 branch
BranchTrueFalseTotal
if (HeVAL(he)) 0 0 0
1351 0 continue;
1352  
1353 0 HeVAL(he) = &PL_sv_undef;
1354 }
1355 #else
1356 if (hv_exists_ent(seen, arg, 0))
1357 continue;
1358  
1359 hv_store_ent(seen, arg, &PL_sv_yes, 0);
1360 #endif
1361  
1362 0 ▶ if(GIMME_V == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if(GIMME_V == G_ARRAY) 0 0 0
1363 0 ▶ ST(retcount) = SvOK(arg) ? arg : sv_2mortal(newSVpvn("", 0));
Branch: 1 branch
BranchTrueFalseTotal
ST(retcount) = SvOK(arg) ? arg : sv_2mortal(newSVpvn("", 0)); 0 0 0
1364 0 retcount++;
1365 }
1366 }
1367  
1368 0 finish:
1369 0 ▶ if(GIMME_V == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if(GIMME_V == G_ARRAY) 0 0 0
1370 0 XSRETURN(retcount);
1371 else
1372 0 ST(0) = sv_2mortal(newSViv(retcount));
1373 }
1374  
1375 MODULE=List::Util PACKAGE=Scalar::Util
1376  
1377 void
1378 dualvar(num,str)
1379 SV *num
1380 SV *str
1381 PROTOTYPE: $$
1382 CODE:
1383 {
1384 0 ▶ dXSTARG;
Branch: 1 branch
BranchTrueFalseTotal
dXSTARG; 0 0 0
1385  
1386 0 ▶ (void)SvUPGRADE(TARG, SVt_PVNV);
Branch: 1 branch
BranchTrueFalseTotal
(void)SvUPGRADE(TARG, SVt_PVNV); 0 0 0
1387  
1388 0 sv_copypv(TARG,str);
1389  
1390 0 ▶ if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
Branch: 3 branches
BranchTrueFalseTotal
if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) { 0 0 0
if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) { 0 0 0
if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) { 0 0 0
1391 0 SvNV_set(TARG, SvNV(num));
1392 0 SvNOK_on(TARG);
1393 }
1394 #ifdef SVf_IVisUV
1395 0 ▶ else if(SvUOK(num)) {
Branch: 1 branch
BranchTrueFalseTotal
else if(SvUOK(num)) { 0 0 0
1396 0 SvUV_set(TARG, SvUV(num));
1397 0 SvIOK_on(TARG);
1398 0 SvIsUV_on(TARG);
1399 }
1400 #endif
1401 else {
1402 0 SvIV_set(TARG, SvIV(num));
1403 0 SvIOK_on(TARG);
1404 }
1405  
1406 0 ▶ if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
Branch: 5 branches
BranchTrueFalseTotal
if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 0 0
if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 0 0
if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 0 0
if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 0 0
if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 0 0
1407 0 ▶ SvTAINTED_on(TARG);
Branch: 1 branch
BranchTrueFalseTotal
SvTAINTED_on(TARG); 0 0 0
1408  
1409 0 ST(0) = TARG;
1410 0 XSRETURN(1);
1411 }
1412  
1413 void
1414 isdual(sv)
1415 SV *sv
1416 PROTOTYPE: $
1417 CODE:
1418 0 ▶ if(SvMAGICAL(sv))
Branch: 1 branch
BranchTrueFalseTotal
if(SvMAGICAL(sv)) 0 0 0
1419 0 mg_get(sv);
1420  
1421 0 ▶ ST(0) = boolSV((SvPOK(sv) || SvPOKp(sv)) && (SvNIOK(sv) || SvNIOKp(sv)));
Branch: 4 branches
BranchTrueFalseTotal
ST(0) = boolSV((SvPOK(sv) || SvPOKp(sv)) && (SvNIOK(sv) || SvNIOKp(sv))); 0 0 0
ST(0) = boolSV((SvPOK(sv) || SvPOKp(sv)) && (SvNIOK(sv) || SvNIOKp(sv))); 0 0 0
ST(0) = boolSV((SvPOK(sv) || SvPOKp(sv)) && (SvNIOK(sv) || SvNIOKp(sv))); 0 0 0
ST(0) = boolSV((SvPOK(sv) || SvPOKp(sv)) && (SvNIOK(sv) || SvNIOKp(sv))); 0 0 0
1422 0 XSRETURN(1);
1423  
1424 char *
1425 blessed(sv)
1426 SV *sv
1427 PROTOTYPE: $
1428 CODE:
1429 {
1430 0 SvGETMAGIC(sv);
1431  
1432 0 ▶ if(!(SvROK(sv) && SvOBJECT(SvRV(sv))))
Branch: 2 branches
BranchTrueFalseTotal
if(!(SvROK(sv) && SvOBJECT(SvRV(sv)))) 0 0 0
if(!(SvROK(sv) && SvOBJECT(SvRV(sv)))) 0 0 0
1433 0 XSRETURN_UNDEF;
1434  
1435 0 RETVAL = (char*)sv_reftype(SvRV(sv),TRUE);
1436 }
1437 OUTPUT:
1438 RETVAL
1439  
1440 char *
1441 reftype(sv)
1442 SV *sv
1443 PROTOTYPE: $
1444 CODE:
1445 {
1446 0 SvGETMAGIC(sv);
1447 0 ▶ if(!SvROK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if(!SvROK(sv)) 0 0 0
1448 0 XSRETURN_UNDEF;
1449  
1450 0 RETVAL = (char*)sv_reftype(SvRV(sv),FALSE);
1451 }
1452 OUTPUT:
1453 RETVAL
1454  
1455 UV
1456 refaddr(sv)
1457 SV *sv
1458 PROTOTYPE: $
1459 CODE:
1460 {
1461 0 SvGETMAGIC(sv);
1462 0 ▶ if(!SvROK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if(!SvROK(sv)) 0 0 0
1463 0 XSRETURN_UNDEF;
1464  
1465 0 ▶ RETVAL = PTR2UV(SvRV(sv));
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PTR2UV(SvRV(sv)); 0 0 0
1466 }
1467 OUTPUT:
1468 RETVAL
1469  
1470 void
1471 weaken(sv)
1472 SV *sv
1473 PROTOTYPE: $
1474 CODE:
1475 #ifdef SvWEAKREF
1476 0 sv_rvweaken(sv);
1477 #else
1478 croak("weak references are not implemented in this release of perl");
1479 #endif
1480  
1481 void
1482 unweaken(sv)
1483 SV *sv
1484 PROTOTYPE: $
1485 INIT:
1486 SV *tsv;
1487 CODE:
1488 #if defined(sv_rvunweaken)
1489 PERL_UNUSED_VAR(tsv);
1490 0 sv_rvunweaken(sv);
1491 #elif defined(SvWEAKREF)
1492 /* This code stolen from core's sv_rvweaken() and modified */
1493 if (!SvOK(sv))
1494 return;
1495 if (!SvROK(sv))
1496 croak("Can't unweaken a nonreference");
1497 else if (!SvWEAKREF(sv)) {
1498 if(ckWARN(WARN_MISC))
1499 warn("Reference is not weak");
1500 return;
1501 }
1502 else if (SvREADONLY(sv)) croak_no_modify();
1503  
1504 tsv = SvRV(sv);
1505 #if PERL_VERSION >= 14
1506 SvWEAKREF_off(sv); SvROK_on(sv);
1507 SvREFCNT_inc_NN(tsv);
1508 Perl_sv_del_backref(aTHX_ tsv, sv);
1509 #else
1510 /* Lacking sv_del_backref() the best we can do is clear the old (weak) ref
1511 * then set a new strong one
1512 */
1513 sv_setsv(sv, &PL_sv_undef);
1514 SvRV_set(sv, SvREFCNT_inc_NN(tsv));
1515 SvROK_on(sv);
1516 #endif
1517 #else
1518 croak("weak references are not implemented in this release of perl");
1519 #endif
1520  
1521 void
1522 isweak(sv)
1523 SV *sv
1524 PROTOTYPE: $
1525 CODE:
1526 #ifdef SvWEAKREF
1527 0 ▶ ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
Branch: 2 branches
BranchTrueFalseTotal
ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv)); 0 0 0
ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv)); 0 0 0
1528 0 XSRETURN(1);
1529 #else
1530 croak("weak references are not implemented in this release of perl");
1531 #endif
1532  
1533 int
1534 readonly(sv)
1535 SV *sv
1536 PROTOTYPE: $
1537 CODE:
1538 0 SvGETMAGIC(sv);
1539 0 ▶ RETVAL = SvREADONLY(sv);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvREADONLY(sv); 0 0 0
1540 OUTPUT:
1541 RETVAL
1542  
1543 int
1544 tainted(sv)
1545 SV *sv
1546 PROTOTYPE: $
1547 CODE:
1548 0 SvGETMAGIC(sv);
1549 0 ▶ RETVAL = SvTAINTED(sv);
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = SvTAINTED(sv); 0 0 0
RETVAL = SvTAINTED(sv); 0 0 0
RETVAL = SvTAINTED(sv); 0 0 0
1550 OUTPUT:
1551 RETVAL
1552  
1553 void
1554 isvstring(sv)
1555 SV *sv
1556 PROTOTYPE: $
1557 CODE:
1558 #ifdef SvVOK
1559 0 SvGETMAGIC(sv);
1560 0 ▶ ST(0) = boolSV(SvVOK(sv));
Branch: 2 branches
BranchTrueFalseTotal
ST(0) = boolSV(SvVOK(sv)); 0 0 0
ST(0) = boolSV(SvVOK(sv)); 0 0 0
1561 0 XSRETURN(1);
1562 #else
1563 croak("vstrings are not implemented in this release of perl");
1564 #endif
1565  
1566 SV *
1567 looks_like_number(sv)
1568 SV *sv
1569 PROTOTYPE: $
1570 CODE:
1571 SV *tempsv;
1572 0 SvGETMAGIC(sv);
1573 0 ▶ if(SvAMAGIC(sv) && (tempsv = AMG_CALLun(sv, numer))) {
Branch: 4 branches
BranchTrueFalseTotal
if(SvAMAGIC(sv) && (tempsv = AMG_CALLun(sv, numer))) { 0 0 0
if(SvAMAGIC(sv) && (tempsv = AMG_CALLun(sv, numer))) { 0 0 0
if(SvAMAGIC(sv) && (tempsv = AMG_CALLun(sv, numer))) { 0 0 0
if(SvAMAGIC(sv) && (tempsv = AMG_CALLun(sv, numer))) { 0 0 0
1574 0 sv = tempsv;
1575 }
1576 #if !PERL_VERSION_GE(5,8,5)
1577 if(SvPOK(sv) || SvPOKp(sv)) {
1578 RETVAL = looks_like_number(sv) ? &PL_sv_yes : &PL_sv_no;
1579 }
1580 else {
1581 RETVAL = (SvFLAGS(sv) & (SVf_NOK|SVp_NOK|SVf_IOK|SVp_IOK)) ? &PL_sv_yes : &PL_sv_no;
1582 }
1583 #else
1584 0 ▶ RETVAL = looks_like_number(sv) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = looks_like_number(sv) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1585 #endif
1586 OUTPUT:
1587 RETVAL
1588  
1589 void
1590 openhandle(SV *sv)
1591 PROTOTYPE: $
1592 CODE:
1593 {
1594 0 IO *io = NULL;
1595 0 SvGETMAGIC(sv);
1596 0 ▶ if(SvROK(sv)){
Branch: 1 branch
BranchTrueFalseTotal
if(SvROK(sv)){ 0 0 0
1597 /* deref first */
1598 0 sv = SvRV(sv);
1599 }
1600  
1601 /* must be GLOB or IO */
1602 0 ▶ if(isGV(sv)){
Branch: 1 branch
BranchTrueFalseTotal
if(isGV(sv)){ 0 0 0
1603 0 ▶ io = GvIO((GV*)sv);
Branch: 4 branches
BranchTrueFalseTotal
io = GvIO((GV*)sv); 0 0 0
io = GvIO((GV*)sv); 0 0 0
io = GvIO((GV*)sv); 0 0 0
io = GvIO((GV*)sv); 0 0 0
1604 }
1605 0 ▶ else if(SvTYPE(sv) == SVt_PVIO){
Branch: 1 branch
BranchTrueFalseTotal
else if(SvTYPE(sv) == SVt_PVIO){ 0 0 0
1606 0 io = (IO*)sv;
1607 }
1608  
1609 0 ▶ if(io){
Branch: 1 branch
BranchTrueFalseTotal
if(io){ 0 0 0
1610 /* real or tied filehandle? */
1611 0 ▶ if(IoIFP(io) || SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)){
Branch: 3 branches
BranchTrueFalseTotal
if(IoIFP(io) || SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)){ 0 0 0
if(IoIFP(io) || SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)){ 0 0 0
if(IoIFP(io) || SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)){ 0 0 0
1612 0 XSRETURN(1);
1613 }
1614 }
1615 0 XSRETURN_UNDEF;
1616 }
1617  
1618 MODULE=List::Util PACKAGE=Sub::Util
1619  
1620 void
1621 set_prototype(proto, code)
1622 SV *proto
1623 SV *code
1624 PREINIT:
1625 SV *cv; /* not CV * */
1626 PPCODE:
1627 0 SvGETMAGIC(code);
1628 0 ▶ if(!SvROK(code))
Branch: 1 branch
BranchTrueFalseTotal
if(!SvROK(code)) 0 0 0
1629 0 croak("set_prototype: not a reference");
1630  
1631 0 cv = SvRV(code);
1632 0 ▶ if(SvTYPE(cv) != SVt_PVCV)
Branch: 1 branch
BranchTrueFalseTotal
if(SvTYPE(cv) != SVt_PVCV) 0 0 0
1633 0 croak("set_prototype: not a subroutine reference");
1634  
1635 0 ▶ if(SvPOK(proto)) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvPOK(proto)) { 0 0 0
1636 /* set the prototype */
1637 0 sv_copypv(cv, proto);
1638 }
1639 else {
1640 /* delete the prototype */
1641 0 SvPOK_off(cv);
1642 }
1643  
1644 0 PUSHs(code);
1645 0 XSRETURN(1);
1646  
1647 # Binary and unicode support from https://github.com/rurban/sub-name/commits/binary
1648 # refined in https://github.com/Leont/Sub-Name/commits/safe
1649 # cperl-5.25.2c started disallowing NUL again, as <5.16
1650  
1651 void
1652 set_subname(name, sub)
1653 SV *name
1654 SV *sub
1655 PREINIT:
1656 0 CV *cv = NULL;
1657 GV *gv;
1658 0 HV *stash = CopSTASH(PL_curcop);
1659 0 const char *s, *end = NULL, *begin = NULL;
1660 MAGIC *mg;
1661 STRLEN namelen;
1662 0 const char* nameptr = SvPV(name, namelen);
1663 0 int utf8flag = SvUTF8(name);
1664 0 int seen_quote = 0;
1665 PPCODE:
1666 0 ▶ if (!SvROK(sub) && SvGMAGICAL(sub))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(sub) && SvGMAGICAL(sub)) 0 0 0
if (!SvROK(sub) && SvGMAGICAL(sub)) 0 0 0
1667 0 mg_get(sub);
1668 0 ▶ if (SvROK(sub))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sub)) 0 0 0
1669 0 cv = (CV *) SvRV(sub);
1670 0 ▶ else if (SvTYPE(sub) == SVt_PVGV)
Branch: 1 branch
BranchTrueFalseTotal
else if (SvTYPE(sub) == SVt_PVGV) 0 0 0
1671 0 ▶ cv = GvCVu(sub);
Branch: 1 branch
BranchTrueFalseTotal
cv = GvCVu(sub); 0 0 0
1672 0 ▶ else if (!SvOK(sub))
Branch: 1 branch
BranchTrueFalseTotal
else if (!SvOK(sub)) 0 0 0
1673 0 croak(PL_no_usym, "a subroutine");
1674 0 ▶ else if (PL_op->op_private & HINT_STRICT_REFS)
Branch: 1 branch
BranchTrueFalseTotal
else if (PL_op->op_private & HINT_STRICT_REFS) 0 0 0
1675 0 croak("Can't use string (\"%" SVf "\") as %s ref while \"strict refs\" in use",
1676 SVfARG(sub), "a subroutine");
1677 0 ▶ else if ((gv = gv_fetchsv(sub, FALSE, SVt_PVCV)))
Branch: 1 branch
BranchTrueFalseTotal
else if ((gv = gv_fetchsv(sub, FALSE, SVt_PVCV))) 0 0 0
1678 0 ▶ cv = GvCVu(gv);
Branch: 1 branch
BranchTrueFalseTotal
cv = GvCVu(gv); 0 0 0
1679 0 ▶ if (!cv)
Branch: 1 branch
BranchTrueFalseTotal
if (!cv) 0 0 0
1680 0 croak("Undefined subroutine %" SVf, SVfARG(sub));
1681 0 ▶ if (SvTYPE(cv) != SVt_PVCV && SvTYPE(cv) != SVt_PVFM)
Branch: 2 branches
BranchTrueFalseTotal
if (SvTYPE(cv) != SVt_PVCV && SvTYPE(cv) != SVt_PVFM) 0 0 0
if (SvTYPE(cv) != SVt_PVCV && SvTYPE(cv) != SVt_PVFM) 0 0 0
1682 0 croak("Not a subroutine reference");
1683  
1684 /* TODO: If there exists a UTF8 codepoint with ending ':' we are screwed.
1685 But perl5 does not care neither. */
1686 0 ▶ for (s = nameptr; s < nameptr + namelen; s++) {
Branch: 1 branch
BranchTrueFalseTotal
for (s = nameptr; s < nameptr + namelen; s++) { 0 0 0
1687 #ifdef PERL_STRIP_NUL
1688 if (!*s) {
1689 # if defined(USE_CPERL) && PERL_VERSION >= 25
1690 SV* tmp = newSVpvs_flags("", SVs_TEMP);
1691 if (Perl_ckwarn(aTHX_ packWARN(WARN_SECURITY)))
1692 Perl_warn_security(aTHX_
1693 "Invalid \\0 character in name for set_subname: %s",
1694 pv_display(tmp, nameptr, namelen, namelen, 127));
1695 else
1696 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
1697 "Invalid \\0 character in name for set_subname: %s",
1698 pv_display(tmp, nameptr, namelen, namelen, 127));
1699 # endif
1700 namelen = s - nameptr;
1701 break;
1702 }
1703 #endif
1704 0 ▶ if (s > nameptr && *s == ':' && s[-1] == ':') {
Branch: 3 branches
BranchTrueFalseTotal
if (s > nameptr && *s == ':' && s[-1] == ':') { 0 0 0
if (s > nameptr && *s == ':' && s[-1] == ':') { 0 0 0
if (s > nameptr && *s == ':' && s[-1] == ':') { 0 0 0
1705 0 end = s - 1;
1706 0 begin = ++s;
1707 0 ▶ if (seen_quote)
Branch: 1 branch
BranchTrueFalseTotal
if (seen_quote) 0 0 0
1708 0 seen_quote++;
1709 }
1710 #ifndef PERL_NO_QUOTE_PKGSEPERATOR
1711 /* cperl doesn't expand the perl4 ' pkg seperator anymore.
1712 gv.c:S_parse_gv_stash_name */
1713 0 ▶ else if (s > nameptr && *s != '\0' && s[-1] == '\'') {
Branch: 3 branches
BranchTrueFalseTotal
else if (s > nameptr && *s != '\0' && s[-1] == '\'') { 0 0 0
else if (s > nameptr && *s != '\0' && s[-1] == '\'') { 0 0 0
else if (s > nameptr && *s != '\0' && s[-1] == '\'') { 0 0 0
1714 0 end = s - 1;
1715 0 begin = s;
1716 0 seen_quote++;
1717 }
1718 #endif
1719 }
1720 0 ▶ if (end) {
Branch: 1 branch
BranchTrueFalseTotal
if (end) { 0 0 0
1721 0 ▶ if (seen_quote > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (seen_quote > 1) { 0 0 0
1722 #ifndef PERL_NO_QUOTE_PKGSEPERATOR
1723 int i, j;
1724 0 const STRLEN stash_len = end - nameptr + seen_quote;
1725 char* left;
1726 0 SV* tmp = newSV(stash_len);
1727 0 left = SvPVX(tmp);
1728 0 ▶ for (i = 0, j = 0; j <= end - nameptr; ++i, ++j) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0, j = 0; j <= end - nameptr; ++i, ++j) { 0 0 0
1729 0 ▶ if (nameptr[j] == '\'') {
Branch: 1 branch
BranchTrueFalseTotal
if (nameptr[j] == '\'') { 0 0 0
1730 0 left[i] = ':';
1731 0 left[++i] = ':';
1732 }
1733 else {
1734 0 left[i] = nameptr[j];
1735 }
1736 }
1737 0 stash = gv_stashpvn(left, i - 2, GV_ADD | utf8flag);
1738 0 SvREFCNT_dec(tmp);
1739 #else
1740 stash = gv_stashpvn(nameptr, end - nameptr, GV_ADD | utf8flag);
1741 #endif
1742 }
1743 else
1744 0 stash = gv_stashpvn(nameptr, end - nameptr, GV_ADD | utf8flag);
1745 0 nameptr = begin;
1746 0 namelen -= begin - nameptr;
1747 }
1748  
1749 /* under debugger, provide information about sub location */
1750 0 ▶ if (PL_DBsub && CvGV(cv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (PL_DBsub && CvGV(cv)) { 0 0 0
if (PL_DBsub && CvGV(cv)) { 0 0 0
1751 0 HV* DBsub = GvHV(PL_DBsub);
1752 HE* old_data;
1753  
1754 0 GV* oldgv = CvGV(cv);
1755 0 HV* oldhv = GvSTASH(oldgv);
1756 SV* old_full_name;
1757 #ifdef USE_CPERL
1758 if (oldhv == PL_defstash) {
1759 old_full_name = sv_2mortal(newSVpvs(""));
1760 }
1761 else
1762 #endif
1763 {
1764 0 ▶ old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv),
Branch: 20 branches
BranchTrueFalseTotal
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
old_full_name = sv_2mortal(newSVpvn_flags(HvNAME(oldhv), HvNAMELEN_get(oldhv), 0 0 0
1765 HvNAMEUTF8(oldhv) ? SVf_UTF8 : 0));
1766 0 sv_catpvn(old_full_name, "::", 2);
1767 }
1768 0 ▶ sv_catpvn_flags(old_full_name, GvNAME(oldgv), GvNAMELEN(oldgv),
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn_flags(old_full_name, GvNAME(oldgv), GvNAMELEN(oldgv), 0 0 0
1769 GvNAMEUTF8(oldgv) ? SV_CATUTF8 : SV_CATBYTES);
1770  
1771 0 old_data = hv_fetch_ent(DBsub, old_full_name, 0, 0);
1772 0 ▶ if (old_data && HeVAL(old_data)) {
Branch: 2 branches
BranchTrueFalseTotal
if (old_data && HeVAL(old_data)) { 0 0 0
if (old_data && HeVAL(old_data)) { 0 0 0
1773 SV* new_full_name;
1774 #ifdef USE_CPERL
1775 if (stash == PL_defstash) {
1776 new_full_name = sv_2mortal(newSVpvs(""));
1777 }
1778 else
1779 #endif
1780 {
1781 0 ▶ new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash),
Branch: 20 branches
BranchTrueFalseTotal
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
new_full_name = sv_2mortal(newSVpvn_flags(HvNAME(stash), 0 0 0
1782 HvNAMELEN_get(stash), HvNAMEUTF8(stash) ? SVf_UTF8 : 0));
1783 0 sv_catpvn(new_full_name, "::", 2);
1784 }
1785 0 ▶ sv_catpvn_flags(new_full_name, nameptr, s - nameptr,
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn_flags(new_full_name, nameptr, s - nameptr, 0 0 0
1786 utf8flag ? SV_CATUTF8 : SV_CATBYTES);
1787 0 SvREFCNT_inc(HeVAL(old_data));
1788 0 ▶ if (hv_store_ent(DBsub, new_full_name, HeVAL(old_data), 0))
Branch: 1 branch
BranchTrueFalseTotal
if (hv_store_ent(DBsub, new_full_name, HeVAL(old_data), 0)) 0 0 0
1789 0 SvREFCNT_inc(HeVAL(old_data));
1790 }
1791 }
1792  
1793 0 gv = (GV *) newSV(0);
1794 0 gv_init_pvn(gv, stash, nameptr, s - nameptr, GV_ADDMULTI | utf8flag);
1795  
1796 /*
1797 * set_subname needs to create a GV to store the name prior to 5.20.
1798 * The CvGV field of a
1799 * CV is not refcounted, so perl wouldn't know to SvREFCNT_dec() this GV if
1800 * it destroys the containing CV. We use a MAGIC with an empty vtable
1801 * simply for the side-effect of using MGf_REFCOUNTED to store the
1802 * actually-counted reference to the GV.
1803 */
1804 0 mg = SvMAGIC(cv);
1805 0 ▶ while (mg && mg->mg_virtual != &subname_vtbl)
Branch: 2 branches
BranchTrueFalseTotal
while (mg && mg->mg_virtual != &subname_vtbl) 0 0 0
while (mg && mg->mg_virtual != &subname_vtbl) 0 0 0
1806 0 mg = mg->mg_moremagic;
1807 0 ▶ if (!mg) {
Branch: 1 branch
BranchTrueFalseTotal
if (!mg) { 0 0 0
1808 0 Newxz(mg, 1, MAGIC);
1809 0 mg->mg_moremagic = SvMAGIC(cv);
1810 0 mg->mg_type = PERL_MAGIC_ext;
1811 0 mg->mg_virtual = &subname_vtbl;
1812 0 SvMAGIC_set(cv, mg);
1813 }
1814 0 ▶ if (mg->mg_flags & MGf_REFCOUNTED)
Branch: 1 branch
BranchTrueFalseTotal
if (mg->mg_flags & MGf_REFCOUNTED) 0 0 0
1815 0 SvREFCNT_dec(mg->mg_obj);
1816 0 mg->mg_flags |= MGf_REFCOUNTED;
1817 0 mg->mg_obj = (SV *) gv;
1818 0 SvRMAGICAL_on(cv);
1819 0 CvANON_off(cv);
1820 #ifndef CvGV_set
1821 CvGV(cv) = gv;
1822 #else
1823 0 CvGV_set(cv, gv);
1824 #endif
1825 0 PUSHs(sub);
1826  
1827 void
1828 subname(code)
1829 SV *code
1830 PREINIT:
1831 CV *cv;
1832 GV *gv;
1833 HV *pkg;
1834 SV *name;
1835 PPCODE:
1836 0 ▶ if (!SvROK(code) && SvGMAGICAL(code))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(code) && SvGMAGICAL(code)) 0 0 0
if (!SvROK(code) && SvGMAGICAL(code)) 0 0 0
1837 0 mg_get(code);
1838  
1839 0 ▶ if(!SvROK(code) || SvTYPE(cv = (CV *)SvRV(code)) != SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
if(!SvROK(code) || SvTYPE(cv = (CV *)SvRV(code)) != SVt_PVCV) 0 0 0
if(!SvROK(code) || SvTYPE(cv = (CV *)SvRV(code)) != SVt_PVCV) 0 0 0
1840 0 croak("Not a subroutine reference");
1841  
1842 0 ▶ if(!(gv = CvGV(cv)))
Branch: 1 branch
BranchTrueFalseTotal
if(!(gv = CvGV(cv))) 0 0 0
1843 0 XSRETURN(0);
1844  
1845 0 pkg = GvSTASH(gv);
1846 0 ▶ name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg),
Branch: 20 branches
BranchTrueFalseTotal
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
name = newSVpvn_flags(HvNAME(pkg), HvNAMELEN_get(pkg), 0 0 0
1847 HvNAMEUTF8(pkg) ? SVf_UTF8 : 0);
1848 0 sv_catpvs(name, "::");
1849 0 sv_catpvn(name, GvNAME(gv), GvNAMELEN(gv));
1850 0 mPUSHs(name);
1851 0 XSRETURN(1);
1852  
1853 BOOT:
1854 {
1855 0 HV *lu_stash = gv_stashpvn("List::Util", 10, TRUE);
1856 0 GV *rmcgv = *(GV**)hv_fetch(lu_stash, "REAL_MULTICALL", 14, TRUE);
1857 SV *rmcsv;
1858 #if !defined(SvWEAKREF) || !defined(SvVOK)
1859 HV *su_stash = gv_stashpvn("Scalar::Util", 12, TRUE);
1860 GV *vargv = *(GV**)hv_fetch(su_stash, "EXPORT_FAIL", 11, TRUE);
1861 AV *varav;
1862 if(SvTYPE(vargv) != SVt_PVGV)
1863 gv_init(vargv, su_stash, "Scalar::Util", 12, TRUE);
1864 varav = GvAVn(vargv);
1865 #endif
1866 0 ▶ if(SvTYPE(rmcgv) != SVt_PVGV)
Branch: 1 branch
BranchTrueFalseTotal
if(SvTYPE(rmcgv) != SVt_PVGV) 0 0 0
1867 0 gv_init(rmcgv, lu_stash, "List::Util", 10, TRUE);
1868 0 ▶ rmcsv = GvSVn(rmcgv);
Branch: 1 branch
BranchTrueFalseTotal
rmcsv = GvSVn(rmcgv); 0 0 0
1869 #ifndef SvWEAKREF
1870 av_push(varav, newSVpv("weaken",6));
1871 av_push(varav, newSVpv("isweak",6));
1872 #endif
1873 #ifndef SvVOK
1874 av_push(varav, newSVpv("isvstring",9));
1875 #endif
1876 #ifdef REAL_MULTICALL
1877 0 sv_setsv(rmcsv, &PL_sv_yes);
1878 #else
1879 sv_setsv(rmcsv, &PL_sv_no);
1880 #endif
1881 }
« blib/lib/Sub/Util.pm ↑ Summary blib/lib/List/Util/XS.pm »