blib/lib/ExtUtils/Constant/ProxySubs.pm

filter: Statementstmt 92.8% 196 / 211 Branchbran 62.0% 62 / 100 Conditioncond 54.5% 18 / 33 MC/DCmcdc 15.0% 3 / 20 Subroutinesub 94.1% 32 / 34 Podpod 0.0% 0 / 5 totaltotal 77.1% 311 / 403 CC 65 SCAR 38.9
CC
65
Cov
80%
WriteConstants
93.0
partition_names
9.0
boottime_iterator
4.3
CRAP 48.9
↑ Summary blib/lib/ExtUtils/Constant.pm »
1 package ExtUtils::Constant::ProxySubs;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 use vars qw($VERSION @ISA %type_to_struct %type_from_struct %type_to_sv
5 %type_to_C_value %type_is_a_problem %type_num_args
6 1 ▶ %type_temporary);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 require ExtUtils::Constant::XS;
9 1 ▶use ExtUtils::Constant::Utils qw(C_stringify);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use ExtUtils::Constant::XS qw(%XS_TypeSet);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 $VERSION = '0.09';
13 1 @ISA = 'ExtUtils::Constant::XS';
14  
15 1 %type_to_struct =
16 (
17 IV => '{const char *name; I32 namelen; IV value;}',
18 NV => '{const char *name; I32 namelen; NV value;}',
19 UV => '{const char *name; I32 namelen; UV value;}',
20 PV => '{const char *name; I32 namelen; const char *value;}',
21 PVN => '{const char *name; I32 namelen; const char *value; STRLEN len;}',
22 YES => '{const char *name; I32 namelen;}',
23 NO => '{const char *name; I32 namelen;}',
24 UNDEF => '{const char *name; I32 namelen;}',
25 '' => '{const char *name; I32 namelen;} ',
26 );
27  
28 %type_from_struct =
29 (
30 1 ▶ IV => sub { $_[0] . '->value' },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 1 ▶ NV => sub { $_[0] . '->value' },
Subroutine __ANON__: called CC=1 SCAR=0.0
32 1 ▶ UV => sub { $_[0] . '->value' },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 1 ▶ PV => sub { $_[0] . '->value' },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 1 ▶ PVN => sub { $_[0] . '->value', $_[0] . '->len' },
Subroutine __ANON__: called CC=1 SCAR=0.0
35 ▶ YES => sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
36 ▶ NO => sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
37 ▶ UNDEF => sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
38 ▶ '' => sub {},
Subroutine __ANON__: not called CC=1 SCAR=0.0
39 1 );
40  
41 %type_to_sv =
42 (
43 1 ▶ IV => sub { "newSViv($_[0])" },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 1 ▶ NV => sub { "newSVnv($_[0])" },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 1 ▶ UV => sub { "newSVuv($_[0])" },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 1 ▶ PV => sub { "newSVpv($_[0], 0)" },
Subroutine __ANON__: called CC=1 SCAR=0.0
47 1 ▶ PVN => sub { "newSVpvn($_[0], $_[1])" },
Subroutine __ANON__: called CC=1 SCAR=0.0
48 1 ▶ YES => sub { '&PL_sv_yes' },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 1 ▶ NO => sub { '&PL_sv_no' },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 1 ▶ UNDEF => sub { '&PL_sv_undef' },
Subroutine __ANON__: called CC=1 SCAR=0.0
51 0 ▶ '' => sub { '&PL_sv_yes' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 1 ▶ SV => sub {"SvREFCNT_inc($_[0])"},
Subroutine __ANON__: called CC=1 SCAR=0.0
53 1 );
54  
55 %type_to_C_value =
56 (
57 ▶ YES => sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
58 ▶ NO => sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
59 ▶ UNDEF => sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
60 ▶ '' => sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
61 1 );
62  
63 sub type_to_C_value {
64 10 ▶ my ($self, $type) = @_;
Subroutine type_to_C_value: called CC=2 SCAR=7.0
Pod undocumented
65 10 ▶ return $type_to_C_value{$type} || sub {return map {ref $_ ? @$_ : $_} @_};
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 2 21 23
Condition66%2/3
$ExtUtils::Constant::ProxySubs::type_to_C_value{$type} || sub { return map({ref $_ ? @$_ : $_;} @_); }
l!l&&r!l&&!r
460
MC/DC0%0/2
$ExtUtils::Constant::ProxySubs::type_to_C_value{$type} || sub { return map({ref $_ ? @$_ : $_;} @_); }
$ExtUtils::Constant::ProxySubs::type_to_C_value{$type} sub { return map({ref $_ ? @$_ : $_;} @_); }
Truth table66%2/3
A || B
A= $ExtUtils::Constant::ProxySubs::type_to_C_value{$type}B= sub { return map({ref $_ ? @$_ : $_;} @_); }
ABresult
1X1
011
000
66 }
67  
68 # TODO - figure out if there is a clean way for the type_to_sv code to
69 # attempt s/sv_2mortal// and if it succeeds tell type_to_sv not to add
70 # SvREFCNT_inc
71 1 %type_is_a_problem =
72 (
73 # The documentation says *mortal SV*, but we now need a non-mortal copy.
74 SV => 1,
75 );
76  
77 1 %type_temporary =
78 (
79 SV => ['SV *'],
80 PV => ['const char *'],
81 PVN => ['const char *', 'STRLEN'],
82 );
83 1 $type_temporary{$_} = [$_] foreach qw(IV UV NV);
84
85 1 ▶while (my ($type, $value) = each %XS_TypeSet) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %ExtUtils::Constant::ProxySubs::XS_TypeSet) 9 1 10
86 9 ▶ $type_num_args{$type}
Branch: 2 branches
BranchTrueFalseTotal
defined $value ? : 6 3 9
ref $value ? : 1 5 6
87 = defined $value ? ref $value ? scalar @$value : 1 : 0;
88 }
89 1 $type_num_args{''} = 0;
90  
91 sub partition_names {
92 1 ▶ my ($self, $default_type, @items) = @_;
Subroutine partition_names: called CC=9 SCAR=22.0
Pod undocumented
93 1 my (%found, @notfound, @trouble);
94  
95 1 ▶ while (my $item = shift @items) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $item = shift @items) 26 1 27
96 26 my $default = delete $item->{default};
97 26 ▶ if ($default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default) { } 1 25 26
98 # If we find a default value, convert it into a regular item and
99 # append it to the queue of items to process
100 1 my $default_item = {%$item};
101 1 $default_item->{invert_macro} = 1;
102 1 $default_item->{pre} = delete $item->{def_pre};
103 1 $default_item->{post} = delete $item->{def_post};
104 1 $default_item->{type} = shift @$default;
105 1 $default_item->{value} = $default;
106 1 push @items, $default_item;
107 } else {
108 # It can be "not found" unless it's the default (invert the macro)
109 # or the "macro" is an empty string (ie no macro)
110 push @notfound, $item unless $item->{invert_macro}
111 25 ▶ or !$self->macro_to_ifdef($self->macro_from_item($item));
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"invert_macro"} or not $self->macro_to_ifdef($self->macro_from_item($item)) 20 5 25
Condition100%3/3
$item->{"invert_macro"} or not $self->macro_to_ifdef($self->macro_from_item($item))
l!l&&r!l&&!r
1420
MC/DC100%2/2
$item->{"invert_macro"} or not $self->macro_to_ifdef($self->macro_from_item($item))
$item->{"invert_macro"} not $self->macro_to_ifdef($self->macro_from_item($item))
Truth table100%3/3
A or not(B)
A= $item->{"invert_macro"}B= not $self->macro_to_ifdef($self->macro_from_item($item))
ABresult
1X1
011
000
112 }
113  
114 26 ▶ if ($item->{pre} or $item->{post} or $item->{not_constant}
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{'pre'} or $item->{'post'} or $item->{'not_constant'} or $ExtUtils::Constant::ProxySubs::type_is_a_problem{$item->{'type'}}) { } 1 25 26
Condition66%6/9
$item->{"pre"} or $item->{"post"} or $item->{"not_constant"} or $ExtUtils::Constant::ProxySubs::type_is_a_problem{$item->{"type"}}
l!l&&r!l&&!r
1025
$item->{"pre"} or $item->{"post"} or $item->{"not_constant"}
l!l&&r!l&&!r
1025
$item->{"pre"} or $item->{"post"}
l!l&&r!l&&!r
1025
MC/DC25%1/4
$item->{"pre"} or $item->{"post"} or $item->{"not_constant"} or $ExtUtils::Constant::ProxySubs::type_is_a_problem{$item->{"type"}}
$item->{"pre"} $item->{"post"} $item->{"not_constant"} $ExtUtils::Constant::ProxySubs::type_is_a_problem{$item->{"type"}}
Truth table40%2/5
A or B or C or D
A= $item->{"pre"}B= $item->{"post"}C= $item->{"not_constant"}D= $ExtUtils::Constant::ProxySubs::type_is_a_problem{$item->{"type"}}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
115 or $type_is_a_problem{$item->{type}}) {
116 1 push @trouble, $item;
117 } else {
118 25 push @{$found{$item->{type}}}, $item;
119 }
120 }
121 # use Data::Dumper; print Dumper \%found;
122 1 (\%found, \@notfound, \@trouble);
123 }
124  
125 sub boottime_iterator {
126 8 ▶ my ($self, $type, $iterator, $hash, $subname, $push) = @_;
Subroutine boottime_iterator: called CC=4 SCAR=14.6
Pod undocumented
127 8 my $extractor = $type_from_struct{$type};
128 8 ▶ die "Can't find extractor code for type $type"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extractor 0 8 8
129 unless defined $extractor;
130 8 my $generator = $type_to_sv{$type};
131 8 ▶ die "Can't find generator code for type $type"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $generator 0 8 8
132 unless defined $generator;
133  
134 8 my $athx = $self->C_constant_prefix_param();
135  
136 8 ▶ if ($push) {
Branch: 1 branch
BranchTrueFalseTotal
if ($push) { } 0 8 8
137 0 return sprintf <<"EOBOOT", &$generator(&$extractor($iterator));
138 while ($iterator->name) {
139 he = $subname($athx $hash, $iterator->name,
140 $iterator->namelen, %s);
141 av_push(push, newSVhek(HeKEY_hek(he)));
142 ++$iterator;
143 }
144 EOBOOT
145 } else {
146 8 return sprintf <<"EOBOOT", &$generator(&$extractor($iterator));
147 while ($iterator->name) {
148 $subname($athx $hash, $iterator->name,
149 $iterator->namelen, %s);
150 ++$iterator;
151 }
152 EOBOOT
153 }
154 }
155  
156 sub name_len_value_macro {
157 46 ▶ my ($self, $item) = @_;
Subroutine name_len_value_macro: called CC=3 SCAR=11.2
Pod undocumented
158 46 my $name = $item->{name};
159 46 my $value = $item->{value};
160 46 ▶ $value = $item->{name} unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 33 13 46
161  
162 46 my $namelen = length $name;
163 46 ▶ if ($name =~ tr/\0-\377// != $namelen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ tr/\000-\377// != $namelen) 0 46 46
164 # the hash API signals UTF-8 by passing the length negated.
165 0 utf8::encode($name);
166 0 $namelen = -length $name;
167 }
168 46 $name = C_stringify($name);
169  
170 46 my $macro = $self->macro_from_item($item);
171 46 ($name, $namelen, $value, $macro);
172 }
173  
174 sub WriteConstants {
175 1 ▶ my $self = shift;
Subroutine WriteConstants: called CC=50 SCAR=45.3
Pod undocumented
176 1 my $ARGS = {@_};
177  
178 my ($c_fh, $xs_fh, $c_subname, $default_type, $package)
179 1 = @{$ARGS}{qw(C_FH XS_FH C_SUBNAME DEFAULT_TYPE NAME)};
180  
181 my $xs_subname
182 1 ▶ = exists $ARGS->{XS_SUBNAME} ? $ARGS->{XS_SUBNAME} : 'constant';
Branch: 1 branch
BranchTrueFalseTotal
exists $ARGS->{'XS_SUBNAME'} ? : 1 0 1
183  
184 1 my $options = $ARGS->{PROXYSUBS};
185 1 ▶ $options = {} unless ref $options;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $options 1 0 1
186 1 my $push = $options->{push};
187 1 my $explosives = $options->{croak_on_read};
188 1 my $croak_on_error = $options->{croak_on_error};
189 1 my $autoload = $options->{autoload};
190 {
191 1 my $exclusive = 0;
192 1 ▶ ++$exclusive if $explosives;
Branch: 1 branch
BranchTrueFalseTotal
if $explosives 0 1 1
193 1 ▶ ++$exclusive if $croak_on_error;
Branch: 1 branch
BranchTrueFalseTotal
if $croak_on_error 0 1 1
194 1 ▶ ++$exclusive if $autoload;
Branch: 1 branch
BranchTrueFalseTotal
if $autoload 0 1 1
195  
196 # Until someone patches this (with test cases):
197 1 ▶ carp ("PROXYSUBS options 'autoload', 'croak_on_read' and 'croak_on_error' cannot be used together")
Branch: 1 branch
BranchTrueFalseTotal
if $exclusive > 1 0 1 1
198 if $exclusive > 1;
199 }
200 # Strictly it requires Perl_caller_cx
201 1 ▶ carp ("PROXYSUBS option 'croak_on_error' requires v5.13.5 or later")
Branch: 1 branch
BranchTrueFalseTotal
if $croak_on_error and $^V < v5.13.5 0 1 1
Condition33%1/3
$croak_on_error and $^V < v5.13.5
!ll&&!rl&&r
100
MC/DC0%0/2
$croak_on_error and $^V < v5.13.5
$croak_on_error $^V < v5.13.5
Truth table33%1/3
A and B
A= $croak_on_errorB= $^V < v5.13.5
ABresult
0X0
100
111
202 if $croak_on_error && $^V < v5.13.5;
203 # Strictly this is actually 5.8.9, but it's not well tested there
204 1 my $can_do_pcs = $] >= 5.009;
205 # Until someone patches this (with test cases)
206 1 ▶ carp ("PROXYSUBS option 'push' requires v5.10 or later")
Branch: 1 branch
BranchTrueFalseTotal
if $push and not $can_do_pcs 0 1 1
Condition33%1/3
$push and not $can_do_pcs
!ll&&!rl&&r
100
MC/DC0%0/2
$push and not $can_do_pcs
$push not $can_do_pcs
Truth table33%1/3
A and not(B)
A= $pushB= not $can_do_pcs
ABresult
0X0
100
111
207 if $push && !$can_do_pcs;
208 # Until someone patches this (with test cases)
209 1 ▶ carp ("PROXYSUBS options 'push' and 'croak_on_read' cannot be used together")
Branch: 1 branch
BranchTrueFalseTotal
if $explosives and $push 0 1 1
Condition33%1/3
$explosives and $push
!ll&&!rl&&r
100
MC/DC0%0/2
$explosives and $push
$explosives $push
Truth table33%1/3
A and B
A= $explosivesB= $push
ABresult
0X0
100
111
210 if $explosives && $push;
211  
212 # If anyone is insane enough to suggest a package name containing %
213 1 my $package_sprintf_safe = $package;
214 1 $package_sprintf_safe =~ s/%/%%/g;
215  
216 # All the types we see
217 1 my $what = {};
218 # A hash to lookup items with.
219 1 my $items = {};
220  
221 my @items = $self->normalise_items ({disable_utf8_duplication => 1},
222 $default_type, $what, $items,
223 1 @{$ARGS->{NAMES}});
224  
225 # Partition the values by type. Also include any defaults in here
226 # Everything that doesn't have a default needs alternative code for
227 # "I'm missing"
228 # And everything that has pre or post code ends up in a private block
229 1 my ($found, $notfound, $trouble)
230 = $self->partition_names($default_type, @items);
231  
232 1 my $pthx = $self->C_constant_prefix_param_defintion();
233 1 my $athx = $self->C_constant_prefix_param();
234 1 my $symbol_table = C_stringify($package) . '::';
235 1 ▶ $push = C_stringify($package . '::' . $push) if $push;
Branch: 1 branch
BranchTrueFalseTotal
if $push 0 1 1
236 1 ▶ my $cast_CONSTSUB = $] < 5.010 ? '(char *)' : '';
Branch: 1 branch
BranchTrueFalseTotal
$] < 5.01 ? : 0 1 1
237  
238 1 print $c_fh $self->header();
239 1 ▶ if ($autoload || $croak_on_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($autoload or $croak_on_error) 0 1 1
Condition33%1/3
$autoload or $croak_on_error
l!l&&r!l&&!r
001
MC/DC0%0/2
$autoload or $croak_on_error
$autoload $croak_on_error
Truth table33%1/3
A or B
A= $autoloadB= $croak_on_error
ABresult
1X1
011
000
240 0 print $c_fh <<'EOC';
241  
242 /* This allows slightly more efficient code on !USE_ITHREADS: */
243 #ifdef USE_ITHREADS
244 # define COP_FILE(c) CopFILE(c)
245 # define COP_FILE_F "s"
246 #else
247 # define COP_FILE(c) CopFILESV(c)
248 # define COP_FILE_F SVf
249 #endif
250 EOC
251 }
252  
253 1 ▶ my $return_type = $push ? 'HE *' : 'void';
Branch: 1 branch
BranchTrueFalseTotal
$push ? : 0 1 1
254  
255 1 print $c_fh <<"EOADD";
256  
257 static $return_type
258 ${c_subname}_add_symbol($pthx HV *hash, const char *name, I32 namelen, SV *value) {
259 EOADD
260 1 ▶ if (!$can_do_pcs) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $can_do_pcs) { } 0 1 1
261 0 print $c_fh <<'EO_NOPCS';
262 if (namelen == namelen) {
263 EO_NOPCS
264 } else {
265 1 print $c_fh <<"EO_PCS";
266 HE *he = (HE*) hv_common_key_len(hash, name, namelen, HV_FETCH_LVALUE, NULL,
267 0);
268 SV *sv;
269  
270 if (!he) {
271 croak("Couldn't add key '%s' to %%$package_sprintf_safe\::",
272 name);
273 }
274 sv = HeVAL(he);
275 if (SvOK(sv) || SvTYPE(sv) == SVt_PVGV) {
276 /* Someone has been here before us - have to make a real sub. */
277 EO_PCS
278 }
279 # This piece of code is common to both
280 1 print $c_fh <<"EOADD";
281 newCONSTSUB(hash, ${cast_CONSTSUB}name, value);
282 EOADD
283 1 ▶ if ($can_do_pcs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can_do_pcs) { } 1 0 1
284 1 print $c_fh <<'EO_PCS';
285 } else {
286 SvUPGRADE(sv, SVt_RV);
287 SvRV_set(sv, value);
288 SvROK_on(sv);
289 SvREADONLY_on(value);
290 }
291 EO_PCS
292 } else {
293 0 print $c_fh <<'EO_NOPCS';
294 }
295 EO_NOPCS
296 }
297 1 ▶ print $c_fh " return he;\n" if $push;
Branch: 1 branch
BranchTrueFalseTotal
if $push 0 1 1
298 1 print $c_fh <<'EOADD';
299 }
300  
301 EOADD
302  
303 1 ▶ print $c_fh $explosives ? <<"EXPLODE" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
$explosives ? : 0 1 1
304  
305 static int
306 Im_sorry_Dave(pTHX_ SV *sv, MAGIC *mg)
307 {
308 PERL_UNUSED_ARG(mg);
309 croak("Your vendor has not defined $package_sprintf_safe macro %"SVf
310 " used", sv);
311 NORETURN_FUNCTION_END;
312 }
313  
314 static MGVTBL not_defined_vtbl = {
315 Im_sorry_Dave, /* get - I'm afraid I can't do that */
316 Im_sorry_Dave, /* set */
317 0, /* len */
318 0, /* clear */
319 0, /* free */
320 0, /* copy */
321 0, /* dup */
322 };
323  
324 EXPLODE
325  
326 {
327 1 my $key = $symbol_table;
328 # Just seems tidier (and slightly more space efficient) not to have keys
329 # such as Fcntl::
330 1 $key =~ s/::$//;
331 1 my $key_len = length $key;
332  
333 1 print $c_fh <<"MISSING";
334  
335 #ifndef SYMBIAN
336  
337 /* Store a hash of all symbols missing from the package. To avoid trampling on
338 the package namespace (uninvited) put each package's hash in our namespace.
339 To avoid creating lots of typeblogs and symbol tables for sub-packages, put
340 each package's hash into one hash in our namespace. */
341  
342 static HV *
343 get_missing_hash(pTHX) {
344 HV *const parent
345 = get_hv("ExtUtils::Constant::ProxySubs::Missing", GVf_MULTI);
346 /* We could make a hash of hashes directly, but this would confuse anything
347 at Perl space that looks at us, and as we're visible in Perl space,
348 best to play nice. */
349 SV *const *const ref
350 = hv_fetch(parent, "$key", $key_len, TRUE);
351 HV *new_hv;
352  
353 if (!ref)
354 return NULL;
355  
356 if (SvROK(*ref))
357 return (HV*) SvRV(*ref);
358  
359 new_hv = newHV();
360 SvUPGRADE(*ref, SVt_RV);
361 SvRV_set(*ref, (SV *)new_hv);
362 SvROK_on(*ref);
363 return new_hv;
364 }
365  
366 #endif
367  
368 MISSING
369  
370 }
371  
372 1 print $xs_fh <<"EOBOOT";
373 BOOT:
374 {
375 #if defined(dTHX) && !defined(PERL_NO_GET_CONTEXT)
376 dTHX;
377 #endif
378 HV *symbol_table = get_hv("$symbol_table", GV_ADD);
379 EOBOOT
380 1 ▶ if ($push) {
Branch: 1 branch
BranchTrueFalseTotal
if ($push) 0 1 1
381 0 print $xs_fh <<"EOC";
382 AV *push = get_av(\"$push\", GV_ADD);
383 HE *he;
384 EOC
385 }
386  
387 1 my %iterator;
388  
389 $found->{''}
390 1 = [map {{%$_, type=>'', invert_macro => 1}} @$notfound];
391  
392 1 foreach my $type (sort keys %$found) {
393 9 my $struct = $type_to_struct{$type};
394 9 my $type_to_value = $self->type_to_C_value($type);
395 9 my $number_of_args = $type_num_args{$type};
396 9 ▶ die "Can't find structure definition for type $type"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $struct 0 9 9
397 unless defined $struct;
398  
399 9 ▶ my $lc_type = $type ? lc($type) : 'notfound';
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 8 1 9
400 9 my $struct_type = $lc_type . '_s';
401 9 my $array_name = 'values_for_' . $lc_type;
402 9 $iterator{$type} = 'value_for_' . $lc_type;
403 # Give the notfound struct file scope. The others are scoped within the
404 # BOOT block
405 9 ▶ my $struct_fh = $type ? $xs_fh : $c_fh;
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 8 1 9
406  
407 9 print $c_fh "struct $struct_type $struct;\n";
408  
409 9 print $struct_fh <<"EOBOOT";
410  
411 static const struct $struct_type $array_name\[] =
412 {
413 EOBOOT
414  
415  
416 9 foreach my $item (@{$found->{$type}}) {
417 45 my ($name, $namelen, $value, $macro)
418 = $self->name_len_value_macro($item);
419  
420 45 my $ifdef = $self->macro_to_ifdef($macro);
421 45 ▶ if (!$ifdef && $item->{invert_macro}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ifdef and $item->{"invert_macro"}) 0 45 45
Condition66%2/3
not $ifdef and $item->{"invert_macro"}
!ll&&!rl&&r
4140
MC/DC0%0/2
not $ifdef and $item->{"invert_macro"}
not $ifdef $item->{"invert_macro"}
Truth table66%2/3
not(A) and B
A= not $ifdefB= $item->{"invert_macro"}
ABresult
0X0
100
111
422 0 carp("Attempting to supply a default for '$name' which has no conditional macro");
423 0 next;
424 }
425 45 ▶ if ($item->{invert_macro}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{'invert_macro'}) { } 21 24 45
426 21 print $struct_fh $self->macro_to_ifndef($macro);
427 21 ▶ print $struct_fh
Branch: 1 branch
BranchTrueFalseTotal
if $type 1 20 21
428 " /* This is the default value: */\n" if $type;
429 } else {
430 24 print $struct_fh $ifdef;
431 }
432 45 print $struct_fh " { ", join (', ', "\"$name\"", $namelen,
433 &$type_to_value($value)),
434 " },\n",
435 $self->macro_to_endif($macro);
436 }
437  
438 # Terminate the list with a NULL
439 9 print $struct_fh " { NULL, 0", (", 0" x $number_of_args), " } };\n";
440  
441 9 ▶ print $xs_fh <<"EOBOOT" if $type;
Branch: 1 branch
BranchTrueFalseTotal
if $type 8 1 9
442 const struct $struct_type *$iterator{$type} = $array_name;
443 EOBOOT
444 }
445  
446 1 delete $found->{''};
447  
448 1 my $add_symbol_subname = $c_subname . '_add_symbol';
449 1 foreach my $type (sort keys %$found) {
450 8 print $xs_fh $self->boottime_iterator($type, $iterator{$type},
451 'symbol_table',
452 $add_symbol_subname, $push);
453 }
454  
455 1 print $xs_fh <<"EOBOOT";
456 if (C_ARRAY_LENGTH(values_for_notfound) > 1) {
457 #ifndef SYMBIAN
458 HV *const ${c_subname}_missing = get_missing_hash(aTHX);
459 #endif
460 const struct notfound_s *value_for_notfound = values_for_notfound;
461 do {
462 EOBOOT
463  
464 1 ▶ print $xs_fh $explosives ? <<"EXPLODE" : << "DONT";
Branch: 1 branch
BranchTrueFalseTotal
$explosives ? : 0 1 1
465 SV *tripwire = newSV(0);
466
467 sv_magicext(tripwire, 0, PERL_MAGIC_ext, &not_defined_vtbl, 0, 0);
468 SvPV_set(tripwire, (char *)value_for_notfound->name);
469 if(value_for_notfound->namelen >= 0) {
470 SvCUR_set(tripwire, value_for_notfound->namelen);
471 } else {
472 SvCUR_set(tripwire, -value_for_notfound->namelen);
473 SvUTF8_on(tripwire);
474 }
475 SvPOKp_on(tripwire);
476 SvREADONLY_on(tripwire);
477 assert(SvLEN(tripwire) == 0);
478  
479 $add_symbol_subname($athx symbol_table, value_for_notfound->name,
480 value_for_notfound->namelen, tripwire);
481 EXPLODE
482  
483 /* Need to add prototypes, else parsing will vary by platform. */
484 HE *he = (HE*) hv_common_key_len(symbol_table,
485 value_for_notfound->name,
486 value_for_notfound->namelen,
487 HV_FETCH_LVALUE, NULL, 0);
488 SV *sv;
489 #ifndef SYMBIAN
490 HEK *hek;
491 #endif
492 if (!he) {
493 croak("Couldn't add key '%s' to %%$package_sprintf_safe\::",
494 value_for_notfound->name);
495 }
496 sv = HeVAL(he);
497 if (!SvOK(sv) && SvTYPE(sv) != SVt_PVGV) {
498 /* Nothing was here before, so mark a prototype of "" */
499 sv_setpvn(sv, "", 0);
500 } else if (SvPOK(sv) && SvCUR(sv) == 0) {
501 /* There is already a prototype of "" - do nothing */
502 } else {
503 /* Someone has been here before us - have to make a real
504 typeglob. */
505 /* It turns out to be incredibly hard to deal with all the
506 corner cases of sub foo (); and reporting errors correctly,
507 so lets cheat a bit. Start with a constant subroutine */
508 CV *cv = newCONSTSUB(symbol_table,
509 ${cast_CONSTSUB}value_for_notfound->name,
510 &PL_sv_yes);
511 /* and then turn it into a non constant declaration only. */
512 SvREFCNT_dec(CvXSUBANY(cv).any_ptr);
513 CvCONST_off(cv);
514 CvXSUB(cv) = NULL;
515 CvXSUBANY(cv).any_ptr = NULL;
516 }
517 #ifndef SYMBIAN
518 hek = HeKEY_hek(he);
519 if (!hv_common(${c_subname}_missing, NULL, HEK_KEY(hek),
520 HEK_LEN(hek), HEK_FLAGS(hek), HV_FETCH_ISSTORE,
521 &PL_sv_yes, HEK_HASH(hek)))
522 croak("Couldn't add key '%s' to missing_hash",
523 value_for_notfound->name);
524 #endif
525 DONT
526  
527 1 ▶ print $xs_fh " av_push(push, newSVhek(hek));\n"
Branch: 1 branch
BranchTrueFalseTotal
if $push 0 1 1
528 if $push;
529  
530 1 print $xs_fh <<"EOBOOT";
531 } while ((++value_for_notfound)->name);
532 }
533 EOBOOT
534  
535 1 foreach my $item (@$trouble) {
536 1 my ($name, $namelen, $value, $macro)
537 = $self->name_len_value_macro($item);
538 1 my $ifdef = $self->macro_to_ifdef($macro);
539 1 my $type = $item->{type};
540 1 my $type_to_value = $self->type_to_C_value($type);
541  
542 1 print $xs_fh $ifdef;
543 1 ▶ if ($item->{invert_macro}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"invert_macro"}) 0 1 1
544 0 ▶ print $xs_fh
Branch: 1 branch
BranchTrueFalseTotal
if $type 0 0 0
545 " /* This is the default value: */\n" if $type;
546 0 print $xs_fh "#else\n";
547 }
548 1 my $generator = $type_to_sv{$type};
549 1 ▶ die "Can't find generator code for type $type"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $generator 0 1 1
550 unless defined $generator;
551  
552 1 print $xs_fh " {\n";
553 # We need to use a temporary value because some really troublesome
554 # items use C pre processor directives in their values, and in turn
555 # these don't fit nicely in the macro-ised generator functions
556 1 my $counter = 0;
557 printf $xs_fh " %s temp%d;\n", $_, $counter++
558 1 foreach @{$type_temporary{$type}};
559  
560 1 ▶ print $xs_fh " $item->{pre}\n" if $item->{pre};
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"pre"} 1 0 1
561  
562 # And because the code in pre might be both declarations and
563 # statements, we can't declare and assign to the temporaries in one.
564 1 $counter = 0;
565 printf $xs_fh " temp%d = %s;\n", $counter++, $_
566 1 foreach &$type_to_value($value);
567  
568 1 my @tempvarnames = map {sprintf 'temp%d', $_} 0 .. $counter - 1;
569 1 printf $xs_fh <<"EOBOOT", $name, &$generator(@tempvarnames);
570 ${c_subname}_add_symbol($athx symbol_table, "%s",
571 $namelen, %s);
572 EOBOOT
573 1 ▶ print $xs_fh " $item->{post}\n" if $item->{post};
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"post"} 0 1 1
574 1 print $xs_fh " }\n";
575  
576 1 print $xs_fh $self->macro_to_endif($macro);
577 }
578  
579 1 ▶ if ($] >= 5.009) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.009) { } 1 0 1
580 1 print $xs_fh <<EOBOOT;
581 /* As we've been creating subroutines, we better invalidate any cached
582 methods */
583 mro_method_changed_in(symbol_table);
584 }
585 EOBOOT
586 } else {
587 0 print $xs_fh <<EOBOOT;
588 /* As we've been creating subroutines, we better invalidate any cached
589 methods */
590 ++PL_sub_generation;
591 }
592 EOBOOT
593 }
594  
595 1 ▶ return if !defined $xs_subname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $xs_subname 0 1 1
596  
597 1 ▶ if ($croak_on_error || $autoload) {
Branch: 1 branch
BranchTrueFalseTotal
if ($croak_on_error or $autoload) { } 0 1 1
Condition33%1/3
$croak_on_error or $autoload
l!l&&r!l&&!r
001
MC/DC0%0/2
$croak_on_error or $autoload
$croak_on_error $autoload
Truth table33%1/3
A or B
A= $croak_on_errorB= $autoload
ABresult
1X1
011
000
598 0 ▶ print $xs_fh $croak_on_error ? <<"EOC" : <<'EOA';
Branch: 1 branch
BranchTrueFalseTotal
$croak_on_error ? : 0 0 0
599  
600 void
601 $xs_subname(sv)
602 INPUT:
603 SV * sv;
604 PREINIT:
605 const PERL_CONTEXT *cx = caller_cx(0, NULL);
606 /* cx is NULL if we've been called from the top level. PL_curcop isn't
607 ideal, but it's much cheaper than other ways of not going SEGV. */
608 const COP *cop = cx ? cx->blk_oldcop : PL_curcop;
609 EOC
610  
611 void
612 AUTOLOAD()
613 PROTOTYPE: DISABLE
614 PREINIT:
615 SV *sv = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SVs_TEMP | SvUTF8(cv));
616 const COP *cop = PL_curcop;
617 EOA
618 0 print $xs_fh <<"EOC";
619 PPCODE:
620 #ifndef SYMBIAN
621 /* It's not obvious how to calculate this at C pre-processor time.
622 However, any compiler optimiser worth its salt should be able to
623 remove the dead code, and hopefully the now-obviously-unused static
624 function too. */
625 HV *${c_subname}_missing = (C_ARRAY_LENGTH(values_for_notfound) > 1)
626 ? get_missing_hash(aTHX) : NULL;
627 if ((C_ARRAY_LENGTH(values_for_notfound) > 1)
628 ? hv_exists_ent(${c_subname}_missing, sv, 0) : 0) {
629 sv = newSVpvf("Your vendor has not defined $package_sprintf_safe macro %" SVf
630 ", used at %" COP_FILE_F " line %" UVuf "\\n",
631 sv, COP_FILE(cop), (UV)CopLINE(cop));
632 } else
633 #endif
634 {
635 sv = newSVpvf("%" SVf
636 " is not a valid $package_sprintf_safe macro at %"
637 COP_FILE_F " line %" UVuf "\\n",
638 sv, COP_FILE(cop), (UV)CopLINE(cop));
639 }
640 croak_sv(sv_2mortal(sv));
641 EOC
642 } else {
643 1 ▶ print $xs_fh $explosives ? <<"EXPLODE" : <<"DONT";
Branch: 1 branch
BranchTrueFalseTotal
$explosives ? : 0 1 1
644  
645 void
646 $xs_subname(sv)
647 INPUT:
648 SV * sv;
649 PPCODE:
650 sv = newSVpvf("Your vendor has not defined $package_sprintf_safe macro %" SVf
651 ", used", sv);
652 PUSHs(sv_2mortal(sv));
653 EXPLODE
654  
655 void
656 $xs_subname(sv)
657 INPUT:
658 SV * sv;
659 PPCODE:
660 #ifndef SYMBIAN
661 /* It's not obvious how to calculate this at C pre-processor time.
662 However, any compiler optimiser worth its salt should be able to
663 remove the dead code, and hopefully the now-obviously-unused static
664 function too. */
665 HV *${c_subname}_missing = (C_ARRAY_LENGTH(values_for_notfound) > 1)
666 ? get_missing_hash(aTHX) : NULL;
667 if ((C_ARRAY_LENGTH(values_for_notfound) > 1)
668 ? hv_exists_ent(${c_subname}_missing, sv, 0) : 0) {
669 sv = newSVpvf("Your vendor has not defined $package_sprintf_safe macro %" SVf
670 ", used", sv);
671 } else
672 #endif
673 {
674 sv = newSVpvf("%" SVf " is not a valid $package_sprintf_safe macro",
675 sv);
676 }
677 PUSHs(sv_2mortal(sv));
678 DONT
679 }
680 }
681  
682 1 1;
↑ Summary blib/lib/ExtUtils/Constant.pm »