lexical.xs

filter: Statementstmt 91.6% 11 / 12 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 85.7% 12 / 14 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/constant/lexical.pm ↑ Summary
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 /* In 5.18 and 5.20, intro_my is not exported. We could just call
6 Perl_intro_my, but Windows users might complain, so just copy the
7 function here (and tweak it). */
8 #ifndef intro_my
9 #define intro_my() S_intro_my(aTHX)
10  
11 /* Fortunately these macros are the same in both versions (but different in
12 5.22+; fortunately, 5.22 exposes intro_my). */
13  
14 #define COP_SEQ_RANGE_LOW_set(sv,val) \
15 STMT_START { ((XPVNV*)SvANY(sv))->xnv_u.xpad_cop_seq.xlow = (val); } STMT_END
16 #define COP_SEQ_RANGE_HIGH_set(sv,val) \
17 STMT_START { ((XPVNV*)SvANY(sv))->xnv_u.xpad_cop_seq.xhigh = (val); } STMT_END
18  
19  
20 static U32
21 S_intro_my(pTHX)
22 {
23 dVAR;
24 SV **svp;
25 I32 i;
26 U32 seq;
27  
28 if (! PL_min_intro_pending)
29 return PL_cop_seqmax;
30  
31 svp = AvARRAY(PL_comppad_name);
32 for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) {
33 SV * const sv = svp[i];
34  
35 /* 5.18 uses sv != &PL_sv_undef; 5.20 uses PadnameLEN(sv), defining it
36 differently from 5.18. The main thing is that it is neither
37 &PL_sv_undef nor &PL_sv_no. Checking that the name has length to it is
38 the canonical way of deing this, but a simple SvCUR() won’t work on
39 &PL_sv_undef, which has no such field. If it is not &PL_sv_undef, then
40 it has a PV and a valid SvCUR field. */
41 if (sv && sv != &PL_sv_undef && SvCUR(sv) && !SvFAKE(sv)
42 && COP_SEQ_RANGE_LOW(sv) == PERL_PADSEQ_INTRO)
43 {
44 COP_SEQ_RANGE_HIGH_set(sv, PERL_PADSEQ_INTRO); /* Don't know scope end yet. */
45 COP_SEQ_RANGE_LOW_set(sv, PL_cop_seqmax);
46 }
47 }
48 seq = PL_cop_seqmax;
49 PL_cop_seqmax++;
50 if (PL_cop_seqmax == PERL_PADSEQ_INTRO) /* not a legal value */
51 PL_cop_seqmax++;
52 PL_min_intro_pending = 0;
53 PL_comppad_name_fill = PL_max_intro_pending; /* Needn't search higher */
54  
55 return seq;
56 }
57  
58 #endif
59  
60 /* Copied from XS::APItest::lexical_import. */
61  
62 MODULE = constant::lexical PACKAGE = constant::lexical
63  
64 void
65 install_lexical_sub(SV *name, CV *cv)
66 CODE:
67 {
68 PADLIST *pl;
69 PADOFFSET off;
70 11 ▶ if (!PL_compcv)
Branch: 1 branch
BranchTrueFalseTotal
if (!PL_compcv) 0 11 11
71 0 Perl_croak(aTHX_
72 "install_lexical_sub can only be called at compile time");
73 11 pl = CvPADLIST(PL_compcv);
74 11 ENTER;
75 11 SAVESPTR(PL_comppad_name); PL_comppad_name = PadlistNAMES(pl);
76 11 SAVESPTR(PL_comppad); PL_comppad = PadlistARRAY(pl)[1];
77 11 SAVESPTR(PL_curpad); PL_curpad = PadARRAY(PL_comppad);
78 11 off = pad_add_name_sv(sv_2mortal(newSVpvf("&%"SVf,name)),
79 padadd_STATE, 0, 0);
80 11 SvREFCNT_dec(PL_curpad[off]);
81 11 PL_curpad[off] = SvREFCNT_inc(cv);
82 11 intro_my();
83 11 LEAVE;
84 }
« blib/lib/constant/lexical.pm ↑ Summary