C2XS/Context.pm

filter: Statementstmt 13.3% 8 / 60 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 50.0% 2 / 4 Podpod 0.0% 0 / 2 totaltotal 6.7% 10 / 148 CC 38 SCAR 70.7
CC
38
Cov
6%
apply_context_args
1332.0
exclude
12.0
BEGIN
1.0
CRAP 1170.5
↑ Summary C2XS.pm »
1 package InlineX::C2XS::Context;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 our $VERSION = '0.27';
7  
8 ###################################
9 ###################################
10  
11 0 ▶sub apply_context_args {
Subroutine apply_context_args: not called CC=36 SCAR=71.9
Pod undocumented
12  
13 # $_[0]: The XS file to which we want to apply the context args (aTHX, aTHX_, pTHX, pTHX_).
14 # $_[1]: A reference to a list/array of the C functions to which we wish to apply the
15 # context args.
16  
17 0 ▶ die "Usage: InlineX::C2XS::Context::apply_context_args(\$xs_file, \\\@functions)"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
18 unless @_ == 2;
19  
20 0 ▶ open RD, '<', $_[0] or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open RD, "<", $_[0] or die $! 0 0 0
21 0 my @xs = <RD>;
22 0 ▶ close RD or die $!;
Branch: 1 branch
BranchTrueFalseTotal
close RD or die $! 0 0 0
23 0 ▶ open WR, '>', $_[0] or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open WR, ">", $_[0] or die $! 0 0 0
24  
25 0 my($aTHX_warn, $pTHX_warn) = (0, 0);
26  
27 0 for(@xs) {
28 0 ▶ $pTHX_warn = 1 if $_ =~ /pTHX/;
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /pTHX/ 0 0 0
29 0 ▶ $aTHX_warn = 1 if $_ =~ /aTHX/;
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /aTHX/ 0 0 0
30 }
31  
32 0 ▶ warn "Potential problem: the string 'aTHX' was found in $_[0]"
Branch: 1 branch
BranchTrueFalseTotal
if $aTHX_warn 0 0 0
33 if $aTHX_warn;
34  
35 0 ▶ warn "Potential problem: the string 'pTHX' was found in $_[0]"
Branch: 1 branch
BranchTrueFalseTotal
if $pTHX_warn 0 0 0
36 if $pTHX_warn;
37  
38 0 for my $f(@{$_[1]}) {
39 0 my $seen_pthx = 0;
40 0 ▶ for(my $i = 1; $i < @xs; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @xs) 0 0 0
41  
42 0 ▶ if($xs[$i] =~ /.+\b$f\b(\s+)?\(/ && !$seen_pthx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xs[$i] =~ /.+\b$f\b(\s+)?\(/ and not $seen_pthx) 0 0 0
Condition0%0/3
$xs[$i] =~ /.+\b$f\b(\s+)?\(/ and not $seen_pthx
!ll&&!rl&&r
000
MC/DC0%0/2
$xs[$i] =~ /.+\b$f\b(\s+)?\(/ and not $seen_pthx
$xs[$i] =~ /.+\b$f\b(\s+)?\(/ not $seen_pthx
Truth table0%0/3
A and not(B)
A= $xs[$i] =~ /.+\b$f\b(\s+)?\(/B= not $seen_pthx
ABresult
0X0
100
111
43 0 ▶ $xs[$i] !~ /\((\s+)?(void)?(\s+)?\)/
Branch: 2 branches
BranchTrueFalseTotal
!($xs[$i] =~ /\((\s+)?(void)?(\s+)?\)/) ? : 0 0 0
$xs[$i] =~ /(a|p)THX/ ? : 0 0 0
44 ? $xs[$i] =~ /(a|p)THX/ ? $xs[$i] = $xs[$i]
45 : $xs[$i] =~ s/\(/\(pTHX_ /
46 : $xs[$i] =~ s/\((\s+)?(void)?(\s+)?\)/\(pTHX\)/;
47 0 ▶ $seen_pthx = 1 if $xs[$i] =~ /pTHX/;
Branch: 1 branch
BranchTrueFalseTotal
if $xs[$i] =~ /pTHX/ 0 0 0
48 }
49  
50  
51 0 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($xs[$i] =~ /^(S|H|A)V \*\n/ || $xs[$i] =~ /^(signed |unsigned )?(long)?\s?int(\s\*)?\n/ || $xs[$i] =~ /^(long)?\s?double(\s\*)?\n/ || $xs[$i] =~ /^(signed |unsigned )?long(\s\*)?\n/ and $xs[$i + 1] =~ /^$f\b/) 0 0 0
Condition0%0/12
$xs[$i] =~ /^(S|H|A)V \*\n/ || $xs[$i] =~ /^(signed |unsigned )?(long)?\s?int(\s\*)?\n/ || $xs[$i] =~ /^(long)?\s?double(\s\*)?\n/ || $xs[$i] =~ /^(signed |unsigned )?long(\s\*)?\n/ and $xs[$i + 1] =~ /^$f\b/
!ll&&!rl&&r
000
$xs[$i] =~ /^(S|H|A)V \*\n/ or $xs[$i] =~ /^(signed |unsigned )?(long)?\s?int(\s\*)?\n/ or $xs[$i] =~ /^(long)?\s?double(\s\*)?\n/ or $xs[$i] =~ /^(signed |unsigned )?long(\s\*)?\n/
l!l&&r!l&&!r
000
$xs[$i] =~ /^(S|H|A)V \*\n/ or $xs[$i] =~ /^(signed |unsigned )?(long)?\s?int(\s\*)?\n/ or $xs[$i] =~ /^(long)?\s?double(\s\*)?\n/
l!l&&r!l&&!r
000
$xs[$i] =~ /^(S|H|A)V \*\n/ or $xs[$i] =~ /^(signed |unsigned )?(long)?\s?int(\s\*)?\n/
l!l&&r!l&&!r
000
MC/DC0%0/5
$xs[$i] =~ /^(S|H|A)V \*\n/ || $xs[$i] =~ /^(signed |unsigned )?(long)?\s?int(\s\*)?\n/ || $xs[$i] =~ /^(long)?\s?double(\s\*)?\n/ || $xs[$i] =~ /^(signed |unsigned )?long(\s\*)?\n/ and $xs[$i + 1] =~ /^$f\b/
$xs[$i] =~ /^(S|H|A)V \*\n/ $xs[$i] =~ /^(signed |unsigned )?(long)?\s?int(\s\*)?\n/ $xs[$i] =~ /^(long)?\s?double(\s\*)?\n/ $xs[$i] =~ /^(signed |unsigned )?long(\s\*)?\n/ $xs[$i + 1] =~ /^$f\b/
Truth table0%0/9
A or B or C or D and E
A= $xs[$i] =~ /^(S|H|A)V \*\n/B= $xs[$i] =~ /^(signed |unsigned )?(long)?\s?int(\s\*)?\n/C= $xs[$i] =~ /^(long)?\s?double(\s\*)?\n/D= $xs[$i] =~ /^(signed |unsigned )?long(\s\*)?\n/E= $xs[$i + 1] =~ /^$f\b/
ABCDEresult
0000X0
1XXX00
01XX00
001X00
000100
1XXX11
01XX11
001X11
000111
52 (
53 $xs[$i] =~ /^(S|H|A)V \*\n/ ||
54 $xs[$i] =~ /^(signed |unsigned )?(long)?\s?int(\s\*)?\n/ ||
55 $xs[$i] =~ /^(long)?\s?double(\s\*)?\n/ ||
56 $xs[$i] =~ /^(signed |unsigned )?long(\s\*)?\n/
57 )
58 && $xs[$i + 1] =~ /^$f\b/
59 ) {
60 0 my $function = $xs[$i + 1];
61 0 chomp $function;
62 0 my $jump = scalar(split /,/, $xs[$i + 1]);
63 0 ▶ if($xs[$i + 1] !~ /\(\)/) {$function =~ s/\(/\(aTHX_ /}
Branch: 1 branch
BranchTrueFalseTotal
if (not $xs[$i + 1] =~ /\(\)/) { } 0 0 0
64 else {
65 0 $function =~ s/\(\)/\(aTHX\)/;
66 0 $jump--;
67 }
68 0 $function .= ';';
69 0 ▶ unless($xs[$i + 2 + $jump] =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xs[$i + 2 + $jump] =~ /\S/) { } 0 0 0
70 0 $xs[$i + 2 + $jump] = "CODE:\n RETVAL = $function\nOUTPUT: RETVAL\n\n";
71 }
72 0 else { warn "$i: $xs[$i + 2 + $jump]\n"}
73 }
74 }
75 }
76  
77 # The following can break if $f appears in comments.
78 0 for my $f (@{$_[1]}) {
79 0 my $seen_pthx = 0;
80 0 ▶ for(my $i = 1; $i < @xs; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @xs) 0 0 0
81 0 ▶ if($seen_pthx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_pthx) { } 0 0 0
82 0 ▶ $xs[$i] =~ s/\b$f(\s+)?\((\s+)?\)/$f(aTHX)/
Branch: 1 branch
BranchTrueFalseTotal
unless $xs[$i] =~ /^$f\b/ 0 0 0
83 unless $xs[$i] =~ /^$f\b/; # XS section - we don't want aTHX/aTHX_ here.
84 0 ▶ $xs[$i] =~ s/\b$f(\s+)?\(/$f(aTHX_ /
Branch: 1 branch
BranchTrueFalseTotal
unless $xs[$i] =~ /aTHX|pTHX/ or $xs[$i] =~ /^$f\b/ 0 0 0
Condition0%0/3
$xs[$i] =~ /aTHX|pTHX/ or $xs[$i] =~ /^$f\b/
l!l&&r!l&&!r
000
MC/DC0%0/2
$xs[$i] =~ /aTHX|pTHX/ or $xs[$i] =~ /^$f\b/
$xs[$i] =~ /aTHX|pTHX/ $xs[$i] =~ /^$f\b/
Truth table0%0/3
A or B
A= $xs[$i] =~ /aTHX|pTHX/B= $xs[$i] =~ /^$f\b/
ABresult
1X1
011
000
85 unless ($xs[$i] =~ /aTHX|pTHX/
86 ||
87 $xs[$i] =~ /^$f\b/); # XS section - we don't want aTHX/aTHX_ here.
88 }
89 else {
90 0 ▶ if($xs[$i] =~ /\b$f\b/ && $xs[$i] =~ /\bpTHX\b|\bpTHX_\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xs[$i] =~ /\b$f\b/ and $xs[$i] =~ /\bpTHX\b|\bpTHX_\b/) 0 0 0
Condition0%0/3
$xs[$i] =~ /\b$f\b/ and $xs[$i] =~ /\bpTHX\b|\bpTHX_\b/
!ll&&!rl&&r
000
MC/DC0%0/2
$xs[$i] =~ /\b$f\b/ and $xs[$i] =~ /\bpTHX\b|\bpTHX_\b/
$xs[$i] =~ /\b$f\b/ $xs[$i] =~ /\bpTHX\b|\bpTHX_\b/
Truth table0%0/3
A and B
A= $xs[$i] =~ /\b$f\b/B= $xs[$i] =~ /\bpTHX\b|\bpTHX_\b/
ABresult
0X0
100
111
91 0 $seen_pthx = 1;
92 0 next;
93 }
94 0 ▶ $seen_pthx = 1 if $xs[$i] =~ /\b$f(\s+)?\(/;
Branch: 1 branch
BranchTrueFalseTotal
if $xs[$i] =~ /\b$f(\s+)?\(/ 0 0 0
95 0 $xs[$i] =~ s/\b$f(\s+)?\((\s+)?(void)(\s+)?\)/$f(pTHX)/;
96 0 ▶ $xs[$i] =~ s/\b$f(\s+)?\(/$f(pTHX_ /
Branch: 1 branch
BranchTrueFalseTotal
unless $xs[$i] =~ /(p|a)THX/ 0 0 0
97 unless $xs[$i] =~ /(p|a)THX/;
98 }
99 }
100 }
101  
102 0 for(@xs) {print WR $_}
103  
104 0 ▶ close WR or die $!;
Branch: 1 branch
BranchTrueFalseTotal
close WR or die $! 0 0 0
105  
106 0 print "$_[0] has been rewritten for PERL_NO_GET_CONTEXT\n";
107  
108 }
109  
110 ###################################
111 ###################################
112  
113 0 ▶sub exclude {
Subroutine exclude: not called CC=3 SCAR=24.8
Pod undocumented
114 0 my @exclusions = @{$_[1]};
115  
116 0 for(@exclusions) {
117 0 ▶ return 1 if $_[0] =~ /$_/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /$_/ 0 0 0
118 }
119 0 return 0;
120 }
121  
122 15 1;
↑ Summary C2XS.pm »