filehandles.xs

filter: Statementstmt 100% 112 / 112 Branchbran 79.3% 46 / 58 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 92.9% 158 / 170 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary blib/lib/bareword/filehandles.pm »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 #include "hook_op_check.h"
5 #include "ppport.h"
6  
7 #define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
8 #define PERL_DECIMAL_VERSION \
9 PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
10 #define PERL_VERSION_GE(r,v,s) \
11 (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
12  
13 #if PERL_VERSION_GE(5,9,2)
14 #define CONST const
15 #else
16 #define CONST /**/
17 #endif
18  
19 #define bareword_croak_unless_builtin(op, gv) \
20 THX_bareword_croak_unless_builtin(aTHX_ op, gv)
21 558 STATIC void THX_bareword_croak_unless_builtin (pTHX_ CONST OP *op, const GV *gv) {
22 558 ▶ if (gv
Branch: 1 branch
BranchTrueFalseTotal
if (gv 558 0 558
23 558 ▶ && gv != PL_stdingv
Branch: 1 branch
BranchTrueFalseTotal
&& gv != PL_stdingv 459 99 558
24 459 ▶ && gv != PL_stderrgv
Branch: 1 branch
BranchTrueFalseTotal
&& gv != PL_stderrgv 362 97 459
25 362 ▶ && gv != PL_defgv
Branch: 1 branch
BranchTrueFalseTotal
&& gv != PL_defgv 362 0 362
26 362 ▶ && gv != PL_argvgv
Branch: 1 branch
BranchTrueFalseTotal
&& gv != PL_argvgv 265 97 362
27 265 ▶ && gv != PL_argvoutgv
Branch: 1 branch
BranchTrueFalseTotal
&& gv != PL_argvoutgv 265 0 265
28 265 ▶ && gv != gv_fetchpv("STDOUT", TRUE, SVt_PVIO)
Branch: 1 branch
BranchTrueFalseTotal
&& gv != gv_fetchpv("STDOUT", TRUE, SVt_PVIO) 168 97 265
29 168 ▶ && gv != gv_fetchpv("DATA", TRUE, SVt_PVIO)
Branch: 1 branch
BranchTrueFalseTotal
&& gv != gv_fetchpv("DATA", TRUE, SVt_PVIO) 71 97 168
30 )
31 71 ▶ croak("Use of bareword filehandle in %s", OP_DESC(op));
Branch: 1 branch
BranchTrueFalseTotal
croak("Use of bareword filehandle in %s", OP_DESC(op)); 0 71 71
32 487 }
33  
34 #define bareword_croak_unless_builtin_op(op, argop) \
35 THX_bareword_croak_unless_builtin_op(aTHX_ op, argop)
36 240 STATIC void THX_bareword_croak_unless_builtin_op (pTHX_ CONST OP *op, const OP *argop) {
37 240 ▶ if (argop && argop->op_type == OP_GV)
Branch: 2 branches
BranchTrueFalseTotal
if (argop && argop->op_type == OP_GV) 240 0 240
if (argop && argop->op_type == OP_GV) 225 15 240
38 225 bareword_croak_unless_builtin(op, cGVOPx_gv(argop));
39 15 ▶ else if (argop && argop->op_type == OP_CONST &&
Branch: 2 branches
BranchTrueFalseTotal
else if (argop && argop->op_type == OP_CONST && 15 0 15
else if (argop && argop->op_type == OP_CONST && 12 3 15
40 12 ▶ (argop->op_private & OPpCONST_BARE)) {
Branch: 1 branch
BranchTrueFalseTotal
(argop->op_private & OPpCONST_BARE)) { 12 0 12
41 12 const GV *gv = gv_fetchsv(cSVOPx(argop)->op_sv, 0, SVt_PVIO);
42 12 bareword_croak_unless_builtin(op, gv);
43 }
44 198 }
45  
46 98 STATIC OP *bareword_filehandles_unary_check_op (pTHX_ OP *op, void *user_data) {
47 98 SV **hint = hv_fetchs(GvHV(PL_hintgv), "bareword::filehandles/disabled", 0);
48  
49 PERL_UNUSED_ARG(user_data);
50  
51 98 ▶ if (!hint || !SvOK(*hint))
Branch: 2 branches
BranchTrueFalseTotal
if (!hint || !SvOK(*hint)) 91 7 98
if (!hint || !SvOK(*hint)) 0 91 91
52 7 return op;
53  
54 91 ▶ if (op->op_flags & OPf_KIDS)
Branch: 1 branch
BranchTrueFalseTotal
if (op->op_flags & OPf_KIDS) 78 13 91
55 78 bareword_croak_unless_builtin_op(op, cUNOPx(op)->op_first);
56  
57 78 return op;
58 }
59  
60 380 STATIC OP *bareword_filehandles_stat_check_op (pTHX_ OP *op, void *user_data) {
61 380 SV **hint = hv_fetchs(GvHV(PL_hintgv), "bareword::filehandles/disabled", 0);
62  
63 PERL_UNUSED_ARG(user_data);
64  
65 380 ▶ if (!hint || !SvOK(*hint))
Branch: 2 branches
BranchTrueFalseTotal
if (!hint || !SvOK(*hint)) 377 3 380
if (!hint || !SvOK(*hint)) 0 377 377
66 3 return op;
67  
68 377 ▶ if (op->op_flags & OPf_REF)
Branch: 1 branch
BranchTrueFalseTotal
if (op->op_flags & OPf_REF) 321 56 377
69 321 bareword_croak_unless_builtin(op, cGVOPx_gv(op));
70  
71 348 return op;
72 }
73  
74 198 STATIC OP *bareword_filehandles_list_check_op (pTHX_ OP *op, void *user_data) {
75 198 SV **hint = hv_fetchs(GvHV(PL_hintgv), "bareword::filehandles/disabled", 0);
76 OP *child;
77 198 ▶ int num_args = user_data ? *(int*)user_data : 1;
Branch: 1 branch
BranchTrueFalseTotal
int num_args = user_data ? *(int*)user_data : 1; 24 174 198
78  
79 198 ▶ if (!hint || !SvOK(*hint))
Branch: 2 branches
BranchTrueFalseTotal
if (!hint || !SvOK(*hint)) 185 13 198
if (!hint || !SvOK(*hint)) 0 185 185
80 13 return op;
81  
82 185 child = cLISTOPx(op)->op_first;
83 185 ▶ if (child && (child->op_type == OP_PUSHMARK || child->op_type == OP_NULL)) {
Branch: 3 branches
BranchTrueFalseTotal
if (child && (child->op_type == OP_PUSHMARK || child->op_type == OP_NULL)) { 185 0 185
if (child && (child->op_type == OP_PUSHMARK || child->op_type == OP_NULL)) { 143 42 185
if (child && (child->op_type == OP_PUSHMARK || child->op_type == OP_NULL)) { 143 0 143
84 318 ▶ while(num_args-- && (child = OpSIBLING(child)))
Branch: 3 branches
BranchTrueFalseTotal
while(num_args-- && (child = OpSIBLING(child))) 203 115 318
while(num_args-- && (child = OpSIBLING(child))) 162 41 203
while(num_args-- && (child = OpSIBLING(child))) 162 41 203
85 162 bareword_croak_unless_builtin_op(op, child);
86 }
87  
88 156 return op;
89 }
90  
91 STATIC const int bareword_filehandles_two = 2;
92  
93 MODULE = bareword::filehandles PACKAGE = bareword::filehandles
94  
95 PROTOTYPES: ENABLE
96  
97 #define bareword_check(type, op) \
98 hook_op_check(op, bareword_filehandles_##type##_check_op, NULL);
99  
100 #define bareword_check_list2(op) \
101 hook_op_check(op, bareword_filehandles_list_check_op, \
102 (void*)&bareword_filehandles_two);
103  
104 BOOT:
105 1 bareword_check(unary, OP_CLOSE);
106 1 bareword_check(unary, OP_CLOSEDIR);
107 1 bareword_check(unary, OP_ENTERWRITE);
108 1 bareword_check(unary, OP_EOF);
109 1 bareword_check(unary, OP_FILENO);
110 1 bareword_check(unary, OP_GETC);
111 1 bareword_check(unary, OP_GETPEERNAME);
112 1 bareword_check(unary, OP_GETSOCKNAME);
113 1 bareword_check(unary, OP_READDIR);
114 1 bareword_check(unary, OP_READLINE);
115 1 bareword_check(unary, OP_REWINDDIR);
116 1 bareword_check(unary, OP_TELL);
117 1 bareword_check(unary, OP_TELLDIR);
118 1 bareword_check(unary, OP_CHDIR);
119  
120 1 bareword_check(list, OP_BIND);
121 1 bareword_check(list, OP_BINMODE);
122 1 bareword_check(list, OP_CONNECT);
123 1 bareword_check(list, OP_FCNTL);
124 1 bareword_check(list, OP_FLOCK);
125 1 bareword_check(list, OP_GSOCKOPT);
126 1 bareword_check(list, OP_IOCTL);
127 1 bareword_check(list, OP_LISTEN);
128 1 bareword_check(list, OP_OPEN);
129 1 bareword_check(list, OP_OPEN_DIR);
130 1 bareword_check(list, OP_READ);
131 1 bareword_check(list, OP_RECV);
132 1 bareword_check(list, OP_SEEK);
133 1 bareword_check(list, OP_SEEKDIR);
134 1 bareword_check(list, OP_SELECT);
135 1 bareword_check(list, OP_SEND);
136 1 bareword_check(list, OP_SHUTDOWN);
137 1 bareword_check(list, OP_SOCKET);
138 1 bareword_check(list, OP_SSOCKOPT);
139 1 bareword_check(list, OP_SYSREAD);
140 1 bareword_check(list, OP_SYSSEEK);
141 1 bareword_check(list, OP_SYSWRITE);
142 1 bareword_check(list, OP_TRUNCATE);
143 1 bareword_check_list2(OP_ACCEPT);
144 1 bareword_check_list2(OP_PIPE_OP);
145 1 bareword_check_list2(OP_SOCKPAIR);
146  
147 1 bareword_check(stat, OP_STAT);
148 1 bareword_check(stat, OP_LSTAT);
149 #if PERL_VERSION_GE(5,31,1)
150 1 bareword_check(stat, OP_FTRREAD);
151 1 bareword_check(stat, OP_FTRWRITE);
152 1 bareword_check(stat, OP_FTREXEC);
153 1 bareword_check(stat, OP_FTEREAD);
154 1 bareword_check(stat, OP_FTEWRITE);
155 1 bareword_check(stat, OP_FTEEXEC);
156 1 bareword_check(stat, OP_FTIS);
157 1 bareword_check(stat, OP_FTSIZE);
158 1 bareword_check(stat, OP_FTMTIME);
159 1 bareword_check(stat, OP_FTATIME);
160 1 bareword_check(stat, OP_FTCTIME);
161 1 bareword_check(stat, OP_FTROWNED);
162 1 bareword_check(stat, OP_FTEOWNED);
163 1 bareword_check(stat, OP_FTZERO);
164 1 bareword_check(stat, OP_FTSOCK);
165 1 bareword_check(stat, OP_FTCHR);
166 1 bareword_check(stat, OP_FTBLK);
167 1 bareword_check(stat, OP_FTFILE);
168 1 bareword_check(stat, OP_FTDIR);
169 1 bareword_check(stat, OP_FTPIPE);
170 1 bareword_check(stat, OP_FTSUID);
171 1 bareword_check(stat, OP_FTSGID);
172 1 bareword_check(stat, OP_FTSVTX);
173 1 bareword_check(stat, OP_FTLINK);
174 1 bareword_check(stat, OP_FTTTY);
175 1 bareword_check(stat, OP_FTTEXT);
176 1 bareword_check(stat, OP_FTBINARY);
177 #endif
↑ Summary blib/lib/bareword/filehandles.pm »