XSBuilder/TypeMap.pm

filter: Statementstmt 7.6% 31 / 406 Branchbran 0.0% 0 / 164 Conditioncond 0.0% 0 / 91 MC/DCmcdc 0.0% 0 / 55 Subroutinesub 16.6% 7 / 42 Podpod 0.0% 0 / 34 totaltotal 4.8% 38 / 792 CC 130 SCAR 49.6
CC
130
Cov
5%
map_structure
380.0
sv_convert_code
380.0
parse
210.0
CRAP 143.0
« XSBuilder/FunctionMap.pm ↑ Summary XSBuilder/StructureMap.pm »
1 package ExtUtils::XSBuilder::TypeMap;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use ExtUtils::XSBuilder::FunctionMap ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use ExtUtils::XSBuilder::CallbackMap ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use ExtUtils::XSBuilder::StructureMap ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use ExtUtils::XSBuilder::MapUtil qw(list_first function_table structure_table callback_table callback_hash);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper ;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our @ISA = qw(ExtUtils::XSBuilder::MapBase);
13  
14 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my $class = shift;
16 0 my $self = bless { INCLUDE => [], wrapxs => shift }, $class;
17  
18 $self->{function_map} = ExtUtils::XSBuilder::FunctionMap ->new ($self -> {wrapxs}),
19 $self->{structure_map} = ExtUtils::XSBuilder::StructureMap->new ($self -> {wrapxs}),
20 0 $self->{callback_map} = ExtUtils::XSBuilder::CallbackMap ->new ($self -> {wrapxs}),
21  
22 $self->get;
23 0 $self;
24 }
25  
26 1 my %special = map { $_, 1 } qw(UNDEFINED NOTIMPL CALLBACK);
27  
28 0 ▶sub special {
Subroutine special: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my($self, $class) = @_;
30 0 return $special{$class};
31 }
32  
33 0 ▶sub function_map { shift->{function_map}->get }
Subroutine function_map: not called CC=1 SCAR=6.9
Pod undocumented
34 0 ▶sub structure_map { shift->{structure_map}->get }
Subroutine structure_map: not called CC=1 SCAR=6.9
Pod undocumented
35 0 ▶sub callback_map { shift->{callback_map}->get }
Subroutine callback_map: not called CC=1 SCAR=6.9
Pod undocumented
36  
37 0 ▶sub parse {
Subroutine parse: not called CC=14 SCAR=53.5
Pod undocumented
38 0 my($self, $fh, $map) = @_;
39  
40 0 ▶ while ($fh->readline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->readline) 0 0 0
41 0 ▶ if (/E=/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/E=/) 0 0 0
42 0 my %args = $self->parse_keywords($_);
43 0 ▶ while (my($key,$val) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
44 0 push @{ $self->{$key} }, $val;
45 }
46 0 next;
47 }
48  
49 0 my @aliases;
50 0 my($type, $class, $typemapid, $aliastypes, $malloctype) = split /\s*\|\s*/, $_, 5;
51 0 ▶ if (!$typemapid && $class)
Branch: 1 branch
BranchTrueFalseTotal
if (not $typemapid and $class) 0 0 0
Condition0%0/3
not $typemapid and $class
!ll&&!rl&&r
000
MC/DC0%0/2
not $typemapid and $class
not $typemapid $class
Truth table0%0/3
not(A) and B
A= not $typemapidB= $class
ABresult
0X0
100
111
52 {
53 0 ▶ if ($class =~ /::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /::/) { } 0 0 0
54 0 $typemapid = 'T_PTROBJ';
55 }
56 else {
57 0 $typemapid = "T_$class";
58 }
59 }
60 0 ▶ $class ||= 'UNDEFINED';
Condition0%0/2
$class ||= "UNDEFINED"
l!l
00
MC/DC0%0/1
$class ||= "UNDEFINED"
$class
Truth table0%0/2
A
A= $class
Aresult
11
00
61  
62 0 ▶ if ($type =~ s/^struct\s+(.*)/$1/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ s/^struct\s+(.*)/$1/) { } 0 0 0
elsif ($type =~ /_t$/) { } 0 0 0
63 0 push @aliases,
64 "$type *", "const $type *",
65 $type, "const $type",
66 "struct $type", "const struct $type",
67 "struct $type *", "const struct $type *",
68 "$type **", "const $type **" ;
69  
70 0 my $cname = $class;
71 0 ▶ if ($cname =~ s/::/__/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cname =~ s/::/__/g) 0 0 0
72 0 push @{ $self->{typedefs} }, [$type, $cname];
73 }
74 }
75 elsif ($type =~ /_t$/) {
76 0 push @aliases, $type, "$type *", "const $type *";
77 }
78 else {
79 0 push @aliases, $type;
80 }
81  
82 0 my $t = { class => $class,
83 typemapid => $typemapid } ;
84 0 ▶ $t -> {aliastypes} = [ split (/\s*,\s*/, $aliastypes) ] if ($aliastypes) ;
Branch: 1 branch
BranchTrueFalseTotal
if $aliastypes 0 0 0
85 0 ▶ $t -> {malloctype} = $malloctype if ($malloctype) ;
Branch: 1 branch
BranchTrueFalseTotal
if $malloctype 0 0 0
86  
87 0 for (@aliases) {
88 0 $map->{$_} = $t ;
89 }
90 }
91 }
92  
93 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
Pod undocumented
94 0 my $self = shift;
95  
96 0 ▶ $self->{map} ||= $self->parse_map_files;
Condition0%0/3
$self->{"map"} ||= $self->parse_map_files
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"map"} ||= $self->parse_map_files
$self->{"map"} $self->parse_map_files
Truth table0%0/3
A ||= B
A= $self->{"map"}B= $self->parse_map_files
ABresult
1X1
011
000
97 }
98  
99 1 my $ignore = join '|', qw{
100 ap_LINK ap_HOOK _ UINT union._
101 union.block_hdr cleanup process_chain
102 iovec struct.rlimit Sigfunc in_addr_t
103 };
104  
105 0 ▶sub should_ignore {
Subroutine should_ignore: not called CC=2 SCAR=17.9
Pod undocumented
106 0 my($self, $type) = @_;
107 0 ▶ return 1 if $type =~ /^($ignore)/o;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /^($ignore)/o 0 0 0
108 }
109  
110 0 ▶sub is_callback {
Subroutine is_callback: not called CC=3 SCAR=24.8
Pod undocumented
111 0 my($self, $type) = @_;
112 0 ▶ return 1 if $type =~ /\(/ and $type =~ /\)/; #XXX: callback
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /\(/ and $type =~ /\)/ 0 0 0
Condition0%0/3
$type =~ /\(/ and $type =~ /\)/
!ll&&!rl&&r
000
MC/DC0%0/2
$type =~ /\(/ and $type =~ /\)/
$type =~ /\(/ $type =~ /\)/
Truth table0%0/3
A and B
A= $type =~ /\(/B= $type =~ /\)/
ABresult
0X0
100
111
113 }
114  
115 0 ▶sub exists {
Subroutine exists: not called CC=3 SCAR=24.8
Pod undocumented
116 0 my($self, $type) = @_;
117  
118 0 ▶ return 1 if $self->is_callback($type) || $self->should_ignore($type);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_callback($type) or $self->should_ignore($type) 0 0 0
Condition0%0/3
$self->is_callback($type) or $self->should_ignore($type)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->is_callback($type) or $self->should_ignore($type)
$self->is_callback($type) $self->should_ignore($type)
Truth table0%0/3
A or B
A= $self->is_callback($type)B= $self->should_ignore($type)
ABresult
1X1
011
000
119  
120 0 $type =~ s/\[\d+\]$//; #char foo[64]
121  
122 0 return exists $self->get->{$type};
123 }
124  
125 0 ▶sub map_type {
Subroutine map_type: not called CC=6 SCAR=37.4
Pod undocumented
126 0 my($self, $type, $quiet) = @_;
127 0 my $t = $self->get->{$type};
128 0 my $class = $t -> {class} ;
129  
130 0 ▶ unless ($class and ! $self->special($class))
Branch: 1 branch
BranchTrueFalseTotal
unless ($class and not $self->special($class)) 0 0 0
Condition0%0/3
$class and not $self->special($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class and not $self->special($class)
$class not $self->special($class)
Truth table0%0/3
A and not(B)
A= $classB= not $self->special($class)
ABresult
0X0
100
111
131 {
132 0 ▶ print "WARNING: Type '$type' not in mapfile\n" if (!$quiet);
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 0 0
133 0 return undef ;
134 }
135 0 ▶ if ($class =~ /(.*?)::$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /(.*?)::$/) 0 0 0
136 0 return $1 ;
137 }
138 0 ▶ if ($class =~ /::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /::/) { } 0 0 0
139 0 return $class;
140 }
141 else {
142 0 return $type;
143 }
144 }
145  
146 0 ▶sub map_malloc_type {
Subroutine map_malloc_type: not called CC=1 SCAR=6.9
Pod undocumented
147 0 my($self, $type) = @_;
148 0 my $t = $self->get->{$type};
149 0 return $t -> {malloctype} ;
150 }
151  
152 0 ▶sub map_class {
Subroutine map_class: not called CC=4 SCAR=30.0
Pod undocumented
153 0 my($self, $type) = @_;
154 0 my $t = $self->get->{$type};
155 0 my $class = $t -> {class} ;
156  
157 0 ▶ return unless $class and ! $self->special($class);
Branch: 1 branch
BranchTrueFalseTotal
unless $class and not $self->special($class) 0 0 0
Condition0%0/3
$class and not $self->special($class)
!ll&&!rl&&r
000
MC/DC0%0/2
$class and not $self->special($class)
$class not $self->special($class)
Truth table0%0/3
A and not(B)
A= $classB= not $self->special($class)
ABresult
0X0
100
111
158 0 ▶ if ($class =~ /(.*?)::$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /(.*?)::$/) 0 0 0
159 0 return $1 ;
160 }
161 0 return $class ;
162 }
163  
164 0 ▶sub null_type {
Subroutine null_type: not called CC=3 SCAR=24.8
Pod undocumented
165 0 my($self, $type) = @_;
166 0 my $t = $self->get->{$type};
167 0 my $class = $t -> {class} ;
168  
169 0 ▶ if ($class =~ /^[INU]V/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class =~ /^[INU]V/) { } 0 0 0
elsif ($class =~ /^(U_)?CHAR$/) { } 0 0 0
170 0 return '0';
171 }
172 elsif ($class =~ /^(U_)?CHAR$/) {
173 0 return '0'; # xsubpp seems to mangle q{'\0'}
174 }
175 else {
176 0 return 'NULL';
177 }
178 }
179  
180 0 ▶sub can_map {
Subroutine can_map: not called CC=7 SCAR=40.3
Pod undocumented
181 0 my $self = shift;
182 0 my $map = shift;
183 0 my $return_type = shift ;
184  
185 0 ▶ if (!$self->map_type($return_type))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->map_type($return_type)) 0 0 0
186 {
187 0 ▶ print "WARNING: Cannot map return type $return_type for function ", $map->{name} || '???', "\n" ;
Condition0%0/2
$map->{'name'} || '???'
l!l
00
MC/DC0%0/1
$map->{'name'} || '???'
$map->{'name'}
Truth table0%0/2
A
A= $map->{'name'}
Aresult
11
00
188 0 return undef ;
189 }
190  
191 0 ▶ return 1 if ($map->{argspec}) ;
Branch: 1 branch
BranchTrueFalseTotal
if $map->{"argspec"} 0 0 0
192  
193 0 for (@_) {
194 0 ▶ if (!$self->map_type($_))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->map_type($_)) 0 0 0
195 {
196 0 ▶ print "WARNING: Cannot map type $_ for function ", $map->{name} || '???', "\n" ;
Condition0%0/2
$map->{'name'} || '???'
l!l
00
MC/DC0%0/1
$map->{'name'} || '???'
$map->{'name'}
Truth table0%0/2
A
A= $map->{'name'}
Aresult
11
00
197 0 return undef ;
198 }
199 }
200  
201 0 return 1;
202 }
203  
204 0 ▶sub map_arg {
Subroutine map_arg: not called CC=3 SCAR=24.8
Pod undocumented
205 0 my($self, $arg) = @_;
206 #print Dumper ($arg), 'map ', $self->map_type($arg->{type}), "\n" ;
207 return {
208 name => $arg->{name},
209 default => $arg->{default},
210 type => $self->map_type($arg->{type}) || $arg->{type},
211 rtype => $arg->{type},
212 0 ▶ class => $self->{map}->{$arg->{type}}->{class} || "",
Condition0%0/5
$self->map_type($arg->{'type'}) || $arg->{'type'}
l!l&&r!l&&!r
000
$self->{'map'}{$arg->{'type'}}{'class'} || ''
l!l
00
MC/DC0%0/2
$self->map_type($arg->{'type'}) || $arg->{'type'}
$self->map_type($arg->{'type'}) $arg->{'type'}
MC/DC0%0/1
$self->{'map'}{$arg->{'type'}}{'class'} || ''
$self->{'map'}{$arg->{'type'}}{'class'}
Truth table0%0/3
A || B
A= $self->map_type($arg->{'type'})B= $arg->{'type'}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $self->{'map'}{$arg->{'type'}}{'class'}
Aresult
11
00
213 }
214 }
215  
216 0 ▶sub map_args {
Subroutine map_args: not called CC=11 SCAR=48.8
Pod undocumented
217 0 my($self, $func, $entry) = @_;
218  
219 #my $entry = $self->function_map->{ $func->{name} };
220 0 my $argspec = $entry->{argspec};
221 0 my $args = [];
222 0 my $retargs = [];
223  
224 0 ▶ if ($argspec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($argspec) { } 0 0 0
225 0 $entry->{orig_args} = [ map $_->{name}, @{ $func->{args} } ];
226  
227 #print "argspec ", Dumper($argspec) ;
228 0 for my $arg (@$argspec) {
229 0 my $default;
230 my $return ;
231 0 ▶ if ($arg =~ /^<(.*?)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^<(.*?)$/) 0 0 0
232 0 $arg = $1 ;
233 0 $return = 1 ;
234 }
235
236 0 ($arg, $default) = split /=/, $arg, 2;
237 0 my($type, $name) ;
238 0 ▶ if ($arg =~ /^(.+)\s*:\s*(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^(.+)\s*:\s*(.+)$/) 0 0 0
239 {
240 0 $type = $1 ;
241 0 $name = $2 ;
242 }
243  
244 #my($type, $name) = split /:(?:[^:])/, $arg, 2;
245  
246 0 my $arghash ;
247 0 ▶ if ($type and $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $name) { } 0 0 0
Condition0%0/3
$type and $name
!ll&&!rl&&r
000
MC/DC0%0/2
$type and $name
$type $name
Truth table0%0/3
A and B
A= $typeB= $name
ABresult
0X0
100
111
248 0 $arghash = {
249 name => $name,
250 type => $type,
251 default => $default,
252 };
253 }
254 else {
255 0 ▶ my $e = list_first { $_->{name} eq $arg } @{ $func->{args} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
256 0 ▶ if ($e) {
Branch: 2 branches
BranchTrueFalseTotal
if ($e) { } 0 0 0
elsif ($arg eq '...') { } 0 0 0
257 0 $arghash = { %$e, default => $default};
258 }
259 elsif ($arg eq '...') {
260 0 $arghash = { name => '...', type => 'SV *'};
261 }
262 else {
263 0 warn "bad argspec: $func->{name} ($arg)\n", Dumper ($func->{args}) ;
264 }
265 }
266 0 ▶ if ($arghash){
Branch: 1 branch
BranchTrueFalseTotal
if ($arghash) 0 0 0
267 0 ▶ if ($return) {
Branch: 1 branch
BranchTrueFalseTotal
if ($return) { } 0 0 0
268 0 $arghash -> {return} = 1 ;
269 0 $arghash -> {type} =~ s/\s*\*$// ;
270 0 push @$retargs, $arghash ;
271 }
272 else {
273 0 push @$args, $arghash ;
274 }
275 }
276 }
277 }
278 else {
279 0 $args = $func->{args};
280 }
281  
282 0 return ([ map $self->map_arg($_), @$args ], [ map $self->map_arg($_), @$retargs ]) ;
283 }
284  
285 # ============================================================================
286  
287 0 ▶sub map_cb_or_func {
Subroutine map_cb_or_func: not called CC=12 SCAR=50.5
Pod undocumented
288 0 my($self, $func, $map, $class) = @_;
289  
290 0 ▶ return unless $map;
Branch: 1 branch
BranchTrueFalseTotal
unless $map 0 0 0
291  
292 return unless $self->can_map($map, $func->{return_type} || 'void',
293 0 ▶ map $_->{type}, @{ $func->{args} });
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can_map($map, $func->{"return_type"} || "void", map($_->{"type"}, @{$$func{"args"};})) 0 0 0
Condition0%0/2
$func->{'return_type'} || 'void'
l!l
00
MC/DC0%0/1
$func->{'return_type'} || 'void'
$func->{'return_type'}
Truth table0%0/2
A
A= $func->{'return_type'}
Aresult
11
00
294 0 my ($mfargs, $mfretargs) = $self->map_args($func, $map) ;
295  
296 my $mf = {
297 name => $func->{name},
298 comment => $func->{comment},
299 return_type => $self->map_type($map->{return_type} ||
300 $func->{return_type} || 'void'),
301 args => $mfargs,
302 retargs => $mfretargs,
303 perl_name => $map->{name},
304 0 ▶ };
Condition0%0/5
$map->{'return_type'} || $func->{'return_type'} || 'void'
l!l
00
$map->{"return_type"} or $func->{"return_type"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$map->{'return_type'} || $func->{'return_type'} || 'void'
$map->{"return_type"} $func->{"return_type"}
Truth table0%0/3
A or B
A= $map->{"return_type"}B= $func->{"return_type"}
ABresult
1X1
011
000
305  
306 0 for (qw(dispatch argspec dispatch_argspec orig_args prefix)) {
307 0 $mf->{$_} = $map->{$_};
308 }
309  
310 0 ▶ $mf->{class} = $class if ($class) ;
Branch: 1 branch
BranchTrueFalseTotal
if $class 0 0 0
311  
312 0 ▶ unless ($mf->{class}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mf->{"class"}) 0 0 0
313 0 ▶ $mf->{class} = $map->{class} || $self->first_class($mf);
Condition0%0/3
$map->{'class'} || $self->first_class($mf)
l!l&&r!l&&!r
000
MC/DC0%0/2
$map->{'class'} || $self->first_class($mf)
$map->{'class'} $self->first_class($mf)
Truth table0%0/3
A || B
A= $map->{'class'}B= $self->first_class($mf)
ABresult
1X1
011
000
314 #print "GUESS class=$mf->{class} for $mf->{name}\n";
315 }
316  
317 0 ▶ $mf->{prefix} ||= $self -> {function_map} -> guess_prefix($mf);
Condition0%0/3
$mf->{"prefix"} ||= $self->{"function_map"}->guess_prefix($mf)
l!l&&r!l&&!r
000
MC/DC0%0/2
$mf->{"prefix"} ||= $self->{"function_map"}->guess_prefix($mf)
$mf->{"prefix"} $self->{"function_map"}->guess_prefix($mf)
Truth table0%0/3
A ||= B
A= $mf->{"prefix"}B= $self->{"function_map"}->guess_prefix($mf)
ABresult
1X1
011
000
318  
319 0 ▶ $mf->{module} = $map->{module} || $mf->{class};
Condition0%0/3
$map->{'module'} || $mf->{'class'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$map->{'module'} || $mf->{'class'}
$map->{'module'} $mf->{'class'}
Truth table0%0/3
A || B
A= $map->{'module'}B= $mf->{'class'}
ABresult
1X1
011
000
320  
321 0 $mf;
322 }
323  
324 # ============================================================================
325  
326 0 ▶sub map_function {
Subroutine map_function: not called CC=2 SCAR=17.9
Pod undocumented
327 0 my($self, $func) = @_;
328  
329 0 my $map = $self->function_map->{ $func->{name} };
330 0 ▶ return unless $map;
Branch: 1 branch
BranchTrueFalseTotal
unless $map 0 0 0
331  
332 0 return $self -> map_cb_or_func ($func, $map) ;
333 }
334  
335 # ============================================================================
336  
337 0 ▶sub map_callback {
Subroutine map_callback: not called CC=9 SCAR=45.0
Pod undocumented
338 0 my($self, $callb, $class) = @_;
339  
340 0 my $name = $callb -> {type} ;
341 0 my $callback = callback_hash ($self -> {wrapxs}) -> {$name} ;
342 #print $callb -> {name} || '???' ," $name -> ", $callback || '-', "\n" ;
343 0 ▶ return unless $callback;
Branch: 1 branch
BranchTrueFalseTotal
unless $callback 0 0 0
344  
345 0 my $map = $self->callback_map->{ $name };
346 #print "$name -> map=", $map || '-', "\n" ;
347 0 ▶ return unless $map;
Branch: 1 branch
BranchTrueFalseTotal
unless $map 0 0 0
348  
349 0 my $cb = $self -> map_cb_or_func ($callback, $map, $class) ;
350  
351 0 ▶ return unless $cb ;
Branch: 1 branch
BranchTrueFalseTotal
unless $cb 0 0 0
352  
353 0 my $orig_args = $cb -> {orig_args} ;
354 0 ▶ $orig_args = [ map $_->{name}, @{ $cb->{args} } ] if (!$orig_args) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $orig_args 0 0 0
355
356 0 my %args = map { $_->{name} => $_ } @{ $cb->{args} } ;
357 0 my %retargs = map { $_->{name} => $_ } @{ $cb->{retargs} } ;
358  
359 #print "mcb ", Dumper($cb), " cba ", Dumper($callback->{args}) , " args ", Dumper(\%args) ;
360  
361 $cb -> {orig_args} = [ map ($retargs{$_}?"\&$_":(($args{$_}{type} !~ /::/) || ($args{$_}{rtype} =~ /\*$/)?
362 0 ▶ $_:"*$_"), @{ $orig_args }) ];
Branch: 2 branches
BranchTrueFalseTotal
$retargs{$_} ? : 0 0 0
!($args{$_}{'type'} =~ /::/) || $args{$_}{'rtype'} =~ /\*$/ ? : 0 0 0
Condition0%0/3
not $args{$_}{"type"} =~ /::/ or $args{$_}{"rtype"} =~ /\*$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $args{$_}{"type"} =~ /::/ or $args{$_}{"rtype"} =~ /\*$/
not $args{$_}{"type"} =~ /::/ $args{$_}{"rtype"} =~ /\*$/
Truth table0%0/3
not(A) or B
A= not $args{$_}{"type"} =~ /::/B= $args{$_}{"rtype"} =~ /\*$/
ABresult
1X1
011
000
363  
364 0 my $cbargs = [ { type => $class, name => '__self'} ] ;
365 0 ▶ push @$cbargs, @{ $cb->{args} } if (@{ $cb->{args}}) ;
Branch: 1 branch
BranchTrueFalseTotal
if @{$cb->{"args"};} 0 0 0
366 0 $cb->{args} = $cbargs ;
367  
368 #print 'func', Dumper($callback), 'map', Dumper($map), 'cb', Dumper($cb) ;
369  
370 0 return $cb ;
371 }
372  
373 # ============================================================================
374  
375 0 ▶sub map_structure {
Subroutine map_structure: not called CC=19 SCAR=59.4
Pod undocumented
376 0 my($self, $struct) = @_;
377  
378 0 my($class, @elts);
379 0 my $stype = $struct->{type};
380  
381 0 ▶ return unless ($class = $self->map_type($stype)) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $class = $self->map_type($stype) 0 0 0
382  
383 0 ▶ my $module = $self->{structure_map}->{MODULES}->{$stype} || $class ;
Condition0%0/3
$self->{'structure_map'}{'MODULES'}{$stype} || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'structure_map'}{'MODULES'}{$stype} || $class
$self->{'structure_map'}{'MODULES'}{$stype} $class
Truth table0%0/3
A || B
A= $self->{'structure_map'}{'MODULES'}{$stype}B= $class
ABresult
1X1
011
000
384 0 for my $e (@{ $struct->{elts} }) {
385 0 my($name, $type) = ($e->{name}, $e->{type});
386 0 my $rtype;
387 my $mapping ;
388  
389 0 ▶ if (!exists ($self->structure_map->{$stype}->{$name}))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->structure_map->{$stype}{$name}) 0 0 0
390 {
391 0 ▶ if (!$name)
Branch: 1 branch
BranchTrueFalseTotal
if (not $name) { } 0 0 0
392 {
393 0 print "WARNING: The following struct element is not in mapfile and has no name\n", Dumper ($e) ;
394 }
395 else
396 {
397 0 print "WARNING: $name not in mapfile\n" ;
398 }
399 0 next ;
400 }
401 0 ▶ if (!($mapping = $self->structure_map->{$stype}->{$name}))
Branch: 1 branch
BranchTrueFalseTotal
unless ($mapping = $self->structure_map->{$stype}{$name}) 0 0 0
402 {
403 0 print "WARNING: $stype for $name not in mapfile\n" ;
404 0 next ;
405 }
406 0 my $mallocmap = $self->structure_map->{$stype}{-malloc} ;
407 0 my $freemap = $self->structure_map->{$stype}{-free} ;
408  
409 #print 'mapping: ', Dumper($mapping, $type) ;
410  
411 0 ▶ if ($rtype = $self->map_type($type, 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rtype = $self->map_type($type, 1)) { } 0 0 0
elsif ($rtype = $self->map_callback($e, $class)) { } 0 0 0
412 #print "rtype=$rtype\n" ;
413 0 my $malloctype = $self->map_malloc_type($type) ;
414 push @elts, {
415 name => $name,
416 perl_name => $mapping -> {perl_name} || $name,
417 comment => $e -> {comment},
418 type => $mapping -> {type} || $rtype,
419 rtype => $type,
420 default => $self->null_type($type),
421 pool => $self->class_pool($class),
422 class => $self->{map}->{$type}{class} || "",
423 $malloctype?(malloc => $mallocmap -> {$malloctype}):(),
424 0 ▶ $malloctype?(free => $freemap -> {$malloctype}):(),
Branch: 2 branches
BranchTrueFalseTotal
$malloctype ? : 0 0 0
$malloctype ? : 0 0 0
Condition0%0/8
$mapping->{'perl_name'} || $name
l!l&&r!l&&!r
000
$mapping->{'type'} || $rtype
l!l&&r!l&&!r
000
$self->{'map'}{$type}{'class'} || ''
l!l
00
MC/DC0%0/2
$mapping->{'perl_name'} || $name
$mapping->{'perl_name'} $name
MC/DC0%0/2
$mapping->{'type'} || $rtype
$mapping->{'type'} $rtype
MC/DC0%0/1
$self->{'map'}{$type}{'class'} || ''
$self->{'map'}{$type}{'class'}
Truth table0%0/3
A || B
A= $mapping->{'perl_name'}B= $name
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $mapping->{'type'}B= $rtype
ABresult
1X1
011
000
Truth table0%0/2
A
A= $self->{'map'}{$type}{'class'}
Aresult
11
00
425 };
426
427 #print Dumper($elts[-1], $stype, $mallocmap, $self->map_malloc_type($type)) ;
428 }
429 elsif ($rtype = $self->map_callback($e, $class)) {
430 push @elts, {
431 name => $name,
432 perl_name => $mapping -> {perl_name} || $name,
433 func => { %$rtype, name => $name, perl_name => $rtype->{alias} || $name, module => $module, dispatch => "(*__self->$name)", comment => $e -> {comment}},
434 0 ▶ rtype => $type,
Condition0%0/8
$mapping->{'perl_name'} || $name
l!l&&r!l&&!r
000
$rtype->{'alias'} || $name
l!l&&r!l&&!r
000
$class || ''
l!l
00
MC/DC0%0/2
$mapping->{'perl_name'} || $name
$mapping->{'perl_name'} $name
MC/DC0%0/2
$rtype->{'alias'} || $name
$rtype->{'alias'} $name
MC/DC0%0/1
$class || ''
$class
Truth table0%0/3
A || B
A= $mapping->{'perl_name'}B= $name
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $rtype->{'alias'}B= $name
ABresult
1X1
011
000
Truth table0%0/2
A
A= $class
Aresult
11
00
435 default => 'NULL',
436 #pool => $self->class_pool($class),
437 class => $class || "",
438 callback => 1,
439 };
440 }
441 else
442 {
443 0 print "WARNING: Type '$type' for struct memeber '$name' in not in types mapfile\n" ;
444 }
445  
446 }
447  
448 return {
449 module => $module,
450 class => $class,
451 type => $stype,
452 elts => \@elts,
453 has_new => $self->structure_map->{$stype}->{'new'}?1:0,
454 has_private => $self->structure_map->{$stype}->{'private'}?1:0,
455 comment => $struct -> {comment},
456  
457 0 ▶ };
Branch: 2 branches
BranchTrueFalseTotal
$self->structure_map->{$stype}{'new'} ? : 0 0 0
$self->structure_map->{$stype}{'private'} ? : 0 0 0
458 }
459  
460 0 ▶sub destructor {
Subroutine destructor: not called CC=1 SCAR=6.9
Pod undocumented
461 0 my($self, $prefix) = @_;
462 0 $self->function_map->{$prefix . 'DESTROY'};
463 }
464  
465  
466 0 ▶sub first_class_ok { 1 } ;
Subroutine first_class_ok: not called CC=1 SCAR=6.9
Pod undocumented
467  
468 0 ▶sub first_class {
Subroutine first_class: not called CC=7 SCAR=40.3
Pod undocumented
469 0 my($self, $func) = @_;
470 0 my $map = $self->get ;
471  
472 0 for my $e (@{ $func->{args} }) {
473 ###next unless $e->{type} =~ /::/;
474 # use map -> rtype to catch class::
475 0 ▶ next unless $map->{$e->{rtype}}{class} =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $$map{$e->{"rtype"}}{"class"} =~ /::/ 0 0 0
476
477 #there are alot of util functions that take an APR::Pool
478 #that do not belong in the APR::Pool class
479 ###next if (!$self -> first_class_ok ($func, $e)) ;
480 0 ▶ next if $e->{type} eq 'APR::Pool' and $func->{name} !~ /^apr_pool/;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"type"} eq "APR::Pool" and not $func->{"name"} =~ /^apr_pool/ 0 0 0
Condition0%0/3
$e->{"type"} eq "APR::Pool" and not $func->{"name"} =~ /^apr_pool/
!ll&&!rl&&r
000
MC/DC0%0/2
$e->{"type"} eq "APR::Pool" and not $func->{"name"} =~ /^apr_pool/
$e->{"type"} eq "APR::Pool" not $func->{"name"} =~ /^apr_pool/
Truth table0%0/3
A and not(B)
A= $e->{"type"} eq "APR::Pool"B= not $func->{"name"} =~ /^apr_pool/
ABresult
0X0
100
111
481 0 ▶ return $1 if ($e->{type} =~ /^(.*?)::$/) ;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"type"} =~ /^(.*?)::$/ 0 0 0
482 0 return $e->{type};
483 }
484  
485 0 ▶ return $func->{name} =~ /^apr_/ ? 'APR' : 'Apache';
Branch: 1 branch
BranchTrueFalseTotal
$func->{'name'} =~ /^apr_/ ? : 0 0 0
486 }
487  
488 0 ▶sub check {
Subroutine check: not called CC=10 SCAR=47.0
Pod undocumented
489 0 my $self = shift;
490  
491 0 my(@types, @missing, %seen);
492  
493 0 for my $entry (@{ structure_table($self -> {wrapxs}) }) {
494 0 push @types, map $_->{type}, @{ $entry->{elts} } ;
495 0 ▶ my $type = $entry -> {stype} || $entry->{type} ;
Condition0%0/3
$entry->{'stype'} || $entry->{'type'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$entry->{'stype'} || $entry->{'type'}
$entry->{'stype'} $entry->{'type'}
Truth table0%0/3
A || B
A= $entry->{'stype'}B= $entry->{'type'}
ABresult
1X1
011
000
496 0 ▶ push @types, $type =~/^struct\s+/?$type:"struct $type" ;
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /^struct\s+/ ? : 0 0 0
497 }
498  
499 0 for my $entry (@{ function_table($self -> {wrapxs}) }) {
500 0 push @types, grep { not $seen{$_}++ }
501 ($entry->{return_type},
502 0 map $_->{type}, @{ $entry->{args} })
503 }
504  
505 #printf "%d types\n", scalar @types;
506  
507 0 for my $type (@types) {
508 0 $type =~ s/\s*(\*\s*)+$// ;
509 0 $type =~ s/const\s*// ;
510 #$type =~ s/struct\s*// ;
511 0 ▶ push @missing, $type unless ($self->exists($type) || $type eq 'new' || $type eq 'private') ;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->exists($type) or $type eq "new" or $type eq "private" 0 0 0
Condition0%0/6
$self->exists($type) or $type eq "new" or $type eq "private"
l!l&&r!l&&!r
000
$self->exists($type) or $type eq "new"
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->exists($type) or $type eq "new" or $type eq "private"
$self->exists($type) $type eq "new" $type eq "private"
Truth table0%0/4
A or B or C
A= $self->exists($type)B= $type eq "new"C= $type eq "private"
ABCresult
1XX1
01X1
0011
0000
512 }
513  
514 0 ▶ return @missing ? \@missing : undef;
Branch: 1 branch
BranchTrueFalseTotal
@missing ? : 0 0 0
515 }
516  
517 #look for Apache/APR structures that do not exist in structure.map
518 1 my %ignore_check = map { $_,1 } qw{
519 module_struct cmd_how kill_conditions
520 regex_t regmatch_t pthread_mutex_t
521 unsigned void va_list ... iovec char int long const
522 gid_t uid_t time_t pid_t size_t
523 sockaddr hostent
524 SV
525 };
526  
527 0 ▶sub check_exists {
Subroutine check_exists: not called CC=7 SCAR=40.3
Pod undocumented
528 0 my $self = shift;
529  
530 0 my %structures = map { my $t = $_->{type}; $t =~ s/^struct\s+// ; ($_->{type} => 1, $t => 1) } @{ structure_table($self) };
531 0 my @missing = ();
532 0 my %seen;
533 #print Data::Dumper -> Dump ([\%structures, structure_table($self)]) ;
534  
535 0 for my $name (keys %{ $self->{map} }) {
536 0 ▶ 1 while $name =~ s/^\w+\s+(\w+)/$1/;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ s/^\w+\s+(\w+)/$1/ and do { '???' } 0 0 0
537 0 $name =~ s/\s+\**.*$//;
538 0 ▶ next if $seen{$name}++ or $structures{$name} or $ignore_check{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$name}++ or $structures{$name} or $ignore_check{$name} 0 0 0
Condition0%0/6
$seen{$name}++ or $structures{$name} or $ignore_check{$name}
l!l&&r!l&&!r
000
$seen{$name}++ or $structures{$name}
l!l&&r!l&&!r
000
MC/DC0%0/3
$seen{$name}++ or $structures{$name} or $ignore_check{$name}
$seen{$name}++ $structures{$name} $ignore_check{$name}
Truth table0%0/4
A or B or C
A= $seen{$name}++B= $structures{$name}C= $ignore_check{$name}
ABCresult
1XX1
01X1
0011
0000
539 0 push @missing, $name;
540 }
541  
542 0 ▶ return @missing ? \@missing : undef;
Branch: 1 branch
BranchTrueFalseTotal
@missing ? : 0 0 0
543 }
544  
545  
546 0 ▶sub checkmaps {
Subroutine checkmaps: not called CC=1 SCAR=6.9
Pod undocumented
547  
548 0 my $self = shift ;
549 0 my %result ;
550 0 $result{missing_functions} = $self->{function_map} -> check ;
551 0 $result{obsolete_functions} = $self->{function_map} -> check_exists ;
552 0 $result{missing_callbacks} = $self->{callback_map} -> check ;
553 0 $result{obsolete_callbacks} = $self->{callback_map} -> check_exists ;
554 0 $result{missing_structures} = $self->{structure_map} -> check ;
555 0 $result{obsolete_structures} = $self->{structure_map} -> check_exists ;
556 0 $result{missing_types} = $self-> check ;
557 0 $result{obsolete_types} = $self-> check_exists ;
558  
559 0 return \%result ;
560 }
561  
562 0 ▶sub writemaps {
Subroutine writemaps: not called CC=1 SCAR=6.9
Pod undocumented
563  
564 0 my $self = shift ;
565 0 my $result = shift ;
566 0 my $prefix = shift ;
567 0 $self->{function_map} -> write_map_file ($result -> {missing_functions}, $prefix) ;
568 0 $self->{callback_map} -> write_map_file ($result -> {missing_callbacks}, $prefix) ;
569 0 $self->{structure_map} -> write_map_file ($result -> {missing_structures}, $prefix) ;
570 0 $self -> write_map_file ($result -> {missing_types}) ;
571 }
572  
573  
574 0 ▶sub write {
Subroutine write: not called CC=3 SCAR=24.8
Pod undocumented
575 0 my ($self, $fh, $newentries) = @_ ;
576  
577 0 my %types ;
578 0 foreach my $type (@$newentries)
579 {
580 0 $type =~ s/\s*(\*\s*)+$// ;
581 0 $type =~ s/const\s*// ;
582 #$type =~ s/struct\s*// ;
583 0 $types{$type} = 1 ;
584 }
585
586 0 foreach my $type (sort keys %types)
587 {
588 0 $fh -> print ("$type\t|\n") ;
589 }
590 }
591  
592  
593 #XXX: generate this
594 my %class_pools = map {
595 1 (my $f = "mpxs_${_}_pool") =~ s/:/_/g;
596 3 $_, $f;
597 } qw{
598 Apache::RequestRec Apache::Connection Apache::URI
599 };
600  
601 0 ▶sub class_pool : lvalue {
Subroutine class_pool: not called CC=1 SCAR=6.9
Pod undocumented
602 0 my($self, $class) = @_;
603 0 $class_pools{$class};
604 }
605  
606  
607 0 ▶sub h_wrap {
Subroutine h_wrap: not called CC=1 SCAR=6.9
Pod undocumented
608 0 my($self, $file, $code) = @_;
609  
610 0 $file = $self -> {wrapxs} -> h_filename_prefix . $file;
611  
612 0 my $h_def = uc "${file}_h";
613 0 my $preamble = "\#ifndef $h_def\n\#define $h_def\n\n";
614 0 my $postamble = "\n\#endif /* $h_def */\n";
615  
616 0 return ("$file.h", $preamble . $code . $postamble);
617 }
618  
619 0 ▶sub typedefs_code {
Subroutine typedefs_code: not called CC=4 SCAR=30.0
Pod undocumented
620 0 my $self = shift;
621 0 my $map = $self->get;
622 0 my %seen;
623  
624 0 my $file = $self -> {wrapxs} -> h_filename_prefix . 'typedefs';
625 0 my $h_def = uc "${file}_h";
626 0 my $code = "";
627 0 my @includes ;
628  
629 0 for (@includes, @{ $self->{INCLUDE} }) {
630 0 $code .= qq{\#include "$_"\n}
631 }
632  
633 0 for my $t (@{ $self->{typedefs} }) {
634 0 ▶ next if $seen{ $t->[1] }++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$t->[1]}++ 0 0 0
635 0 my $class = $t->[1] ;
636 0 $class =~ s/__$// ;
637 0 $code .= "typedef $t->[0] * $class;\n";
638 }
639  
640 0 $code .= "typedef void * PTR;\n";
641 0 $code .= "#if PERL_VERSION > 5\n";
642 0 $code .= "typedef char * PV;\n";
643 0 $code .= "#endif\n";
644 0 $code .= "typedef char * PVnull;\n";
645  
646 0 $code .= q{
647 #ifndef pTHX_
648 #define pTHX_
649 #endif
650 #ifndef aTHX_
651 #define aTHX_
652 #endif
653 #ifndef pTHX
654 #define pTHX
655 #endif
656 #ifndef aTHX
657 #define aTHX
658 #endif
659  
660 #ifndef XSprePUSH
661 #define XSprePUSH (sp = PL_stack_base + ax - 1)
662 #endif
663  
664 } ;
665  
666 0 $self->h_wrap('typedefs', $code);
667 }
668  
669 0 ▶sub sv_convert_code {
Subroutine sv_convert_code: not called CC=19 SCAR=59.4
Pod undocumented
670 0 my $self = shift;
671 0 my $map = $self->get;
672 0 my %seen;
673 0 my $cnvprefix = $self -> {wrapxs} -> my_cnv_prefix ;
674 0 my $typemap_code = $self -> typemap_code ($cnvprefix);
675 0 my $code = q{
676
677 #ifndef aTHX_
678 /* let it work with 5.005 */
679 #define aTHX_
680 #endif
681 } ;
682  
683 0 ▶ while (my($ctype, $t) = each %$map) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$map) 0 0 0
684 0 my $ptype = $t -> {class} ;
685 0 ▶ next if $self->special($ptype);
Branch: 1 branch
BranchTrueFalseTotal
if $self->special($ptype) 0 0 0
686 0 ▶ next if ($ctype =~ /\s/) ;
Branch: 1 branch
BranchTrueFalseTotal
if $ctype =~ /\s/ 0 0 0
687 0 my $class = $ptype;
688 0 my $tmcode ;
689  
690 0 $ptype =~ s/:/_/g ;
691 0 $ptype =~ s/__$// ;
692 0 $class =~ s/::$// ;
693 0 ▶ next if $seen{$ptype}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$ptype}++ 0 0 0
694  
695 0 ▶ if ($typemap_code -> {$t -> {typemapid}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$typemap_code{$t->{'typemapid'}}) { } 0 0 0
696 0 my $alias;
697 0 my $expect = "expecting an $class derived object";
698 0 my $croak = "argument is not a blessed reference";
699  
700 #Perl -> C
701 0 my $define = "${cnvprefix}sv2_$ptype";
702  
703 0 ▶ if ($tmcode = $typemap_code -> {$t -> {typemapid}}{perl2c})
Branch: 1 branch
BranchTrueFalseTotal
if ($tmcode = $$typemap_code{$t->{'typemapid'}}{'perl2c'}) { } 0 0 0
704 {
705 0 $code .= "#define $define(sv) " . eval (qq[qq[$tmcode]]) . "\n" ;
706 }
707 else
708 {
709 0 print "WARNING no convert code for $t -> {typemapid}\n" ;
710 }
711 0 ▶ if ($alias = $t -> {typealiases}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias = $t->{"typealiases"}[0]) 0 0 0
712 0 $code .= "#define ${cnvprefix}sv2_$alias $define\n\n";
713 }
714  
715 #C -> Perl
716 0 $define = "${cnvprefix}${ptype}_2obj";
717 0 ▶ if ($tmcode = $typemap_code -> {$t -> {typemapid}}{c2perl})
Branch: 1 branch
BranchTrueFalseTotal
if ($tmcode = $$typemap_code{$t->{'typemapid'}}{'c2perl'}) { } 0 0 0
718 {
719 0 $code .= "#define $define(ptr) " . eval (qq[qq[$tmcode]]) . "\n" ;
720 }
721 else
722 {
723 0 print "WARNING no convert code for $t -> {typemapid}\n" ;
724 }
725 0 ▶ if ($alias) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias) 0 0 0
726 0 $code .= "#define ${cnvprefix}${alias}_2obj $define\n\n";
727 }
728  
729 #Create
730 0 $define = "${cnvprefix}${ptype}_create_obj";
731 0 ▶ if ($tmcode = $typemap_code -> {$t -> {typemapid}}{create})
Branch: 1 branch
BranchTrueFalseTotal
if ($tmcode = $$typemap_code{$t->{"typemapid"}}{"create"}) 0 0 0
732 {
733 0 $code .= "#define $define(p,sv,rv,alloc) " . eval (qq[qq[$tmcode]]) . "\n" ;
734 }
735  
736 0 ▶ if ($alias) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias) 0 0 0
737 0 $code .= "#define ${cnvprefix}${alias}_2obj $define\n\n";
738 }
739 #Destroy
740 0 $define = "${cnvprefix}${ptype}_free_obj";
741 0 ▶ if ($tmcode = $typemap_code -> {$t -> {typemapid}}{destroy})
Branch: 1 branch
BranchTrueFalseTotal
if ($tmcode = $$typemap_code{$t->{"typemapid"}}{"destroy"}) 0 0 0
742 {
743 0 $code .= "#define $define(ptr) " . eval (qq[qq[$tmcode]]) . "\n" ;
744 }
745  
746 0 ▶ if ($alias) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias) 0 0 0
747 0 $code .= "#define ${cnvprefix}${alias}_2obj $define\n\n";
748 }
749 }
750 else {
751 0 ▶ if (($ptype =~ /^(\wV)$/) && $ptype ne 'SV') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ptype =~ /^(\wV)$/ and $ptype ne "SV") 0 0 0
Condition0%0/3
$ptype =~ /^(\wV)$/ and $ptype ne "SV"
!ll&&!rl&&r
000
MC/DC0%0/2
$ptype =~ /^(\wV)$/ and $ptype ne "SV"
$ptype =~ /^(\wV)$/ $ptype ne "SV"
Truth table0%0/3
A and B
A= $ptype =~ /^(\wV)$/B= $ptype ne "SV"
ABresult
0X0
100
111
752 0 my $class = $1;
753 0 my $alias ;
754  
755 #Perl -> C
756 0 my $define = "${cnvprefix}sv2_$ctype";
757  
758 0 $code .= "#define $define(sv) ($ctype)Sv$class(sv)\n\n";
759  
760 0 ▶ if ($alias = $t -> {typealiases}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias = $t->{"typealiases"}[0]) 0 0 0
761 0 $code .= "#define ${cnvprefix}sv2_$alias $define\n\n";
762 }
763 #C -> Perl
764 0 $define = "${cnvprefix}${ctype}_2obj";
765 0 my $lcclass = lc($class) ;
766 0 ▶ my $l = $class eq 'PV'?',0':'' ;
Branch: 1 branch
BranchTrueFalseTotal
$class eq 'PV' ? : 0 0 0
767  
768 0 $code .= "#define $define(v) sv_2mortal(newSV$lcclass(v$l))\n\n";
769  
770 0 ▶ if ($alias) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias) 0 0 0
771 0 $code .= "#define ${cnvprefix}${alias}_2obj $define\n\n";
772 }
773 }
774 }
775 }
776  
777 0 $code .= "#define ${cnvprefix}sv2_SV(sv) (sv)\n\n";
778 0 $code .= "#define ${cnvprefix}SV_2obj(x) (x)\n\n";
779 0 $code .= "#define ${cnvprefix}sv2_SVPTR(sv) (sv)\n\n";
780 0 $code .= "#define ${cnvprefix}SVPTR_2obj(x) (x==NULL?&PL_sv_undef:sv_2mortal(SvREFCNT_inc(x)))\n\n";
781 0 $code .= "#define ${cnvprefix}sv2_PV(sv) (SvPV(sv, PL_na))\n\n";
782 0 $code .= "#define ${cnvprefix}PV_2obj(x) (sv_2mortal(newSVpv(x, 0)))\n\n";
783 0 $code .= "#define ${cnvprefix}sv2_PVnull(sv) (SvOK(sv)?SvPV(sv, PL_na):NULL)\n\n";
784 0 $code .= "#define ${cnvprefix}PVnull_2obj(x) (x==NULL?&PL_sv_undef:sv_2mortal(newSVpv(x, 0)))\n\n";
785 0 $code .= "#define ${cnvprefix}sv2_IV(sv) SvIV(sv)\n\n";
786 0 $code .= "#define ${cnvprefix}IV_2obj(x) sv_2mortal(newSViv(x))\n\n";
787 0 $code .= "#define ${cnvprefix}sv2_NV(sv) SvNV(sv)\n\n";
788 0 $code .= "#define ${cnvprefix}NV_2obj(x) sv_2mortal(newSVnv(x))\n\n";
789 0 $code .= "#define ${cnvprefix}sv2_UV(sv) SvUV(sv)\n\n";
790 0 $code .= "#define ${cnvprefix}UV_2obj(x) sv_2mortal(newSVuv(x))\n\n";
791 0 $code .= "#define ${cnvprefix}sv2_PTR(sv) (SvROK(sv)?((void *)SvIV(SvRV(sv))):NULL)\n\n";
792 0 $code .= "#define ${cnvprefix}PTR_2obj(x) (x?newRV_noinc(newSViv ((IV)x)):&PL_sv_undef)\n\n";
793 0 $code .= "#define ${cnvprefix}sv2_CHAR(sv) (char)SvNV(sv)\n\n";
794 0 $code .= "#define ${cnvprefix}CHAR_2obj(x) sv_2mortal(newSVnv(x))\n\n";
795 0 $code .= "#define ${cnvprefix}sv2_AVREF(sv) (AV*)SvRV(sv)\n\n";
796 0 $code .= "#define ${cnvprefix}AVREF_2obj(x) (x?sv_2mortal(newRV((SV*)x)):&PL_sv_undef)\n\n";
797 0 $code .= "#define ${cnvprefix}sv2_HVREF(sv) (HV*)SvRV(sv)\n\n";
798 0 $code .= "#define ${cnvprefix}HVREF_2obj(x) (x?sv_2mortal(newRV((SV*)x)):&PL_sv_undef)\n\n";
799  
800 0 $self->h_wrap('sv_convert', $code);
801 }
802  
803 # ============================================================================
804  
805 # NOTE: 'INPUT' code must not be ended with a ;
806  
807  
808 sub typemap_code
809  
810 0 ▶ {
Subroutine typemap_code: not called CC=1 SCAR=6.9
Pod undocumented
811 0 my $self = shift ;
812 0 my $cnvprefix = shift ;
813  
814 return
815 {
816 0 'T_MAGICHASH_SV' =>
817 {
818 'OUTPUT' => ' if ($var -> _perlsv) $arg = $var -> _perlsv ; else $arg = &sv_undef ;',
819  
820 'c2perl' => '(ptr->_perlsv?ptr->_perlsv:&sv_undef)',
821  
822 'INPUT' =>
823 q[ {
824 MAGIC * mg ;
825 if ((mg = mg_find (SvRV($arg), '~')))
826 $var = *(($type *)(mg -> mg_ptr)) ;
827 else
828 croak (\"$var is not of type $type\") ;
829 }
830 ],
831  
832 'perl2c' =>
833 q[(SvOK(sv)?((SvROK(sv) && SvMAGICAL(SvRV(sv))) \\\\
834 || (Perl_croak(aTHX_ "$croak ($expect)"),0) ? \\\\
835 *(($ctype **)(mg_find (SvRV(sv), '~') -> mg_ptr)) : ($ctype *)NULL):($ctype *)NULL)
836 ],
837  
838 'create' =>
839 q[ sv = (SV *)newHV () ; \\\\
840 p = alloc ; \\\\
841 memset (p, 0, sizeof($ctype)) ; \\\\
842 sv_magic ((SV *)sv, NULL, '~', (char *)&p, sizeof (p)) ; \\\\
843 rv = p -> _perlsv = newRV_noinc ((SV *)sv) ; \\\\
844 sv_bless (rv, gv_stashpv ("$class", 0)) ;
845
846 ],
847 'destroy' => ' free(ptr)',
848 },
849  
850 'T_PTROBJ' =>
851 {
852 'c2perl' => ' sv_setref_pv(sv_newmortal(), "$class", (void*)ptr)',
853  
854 'perl2c' =>
855 q[(SvOK(sv)?((SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVMG)) \\\\
856 || (Perl_croak(aTHX_ "$croak ($expect)"),0) ? \\\\
857 ($ctype *)SvIV((SV*)SvRV(sv)) : ($ctype *)NULL):($ctype *)NULL)
858 ],
859  
860 'create' =>
861 q[ rv = newSViv(0) ; \\\\
862 sv = newSVrv (rv, "$class") ; \\\\
863 SvUPGRADE(sv, SVt_PVIV) ; \\\\
864 SvGROW(sv, sizeof (*p)) ; \\\\
865 p = ($ctype *)SvPVX(sv) ;\\\\
866 memset(p, 0, sizeof (*p)) ;\\\\
867 SvIVX(sv) = (IV)p ;\\\\
868 SvIOK_on(sv) ;\\\\
869 SvPOK_on(sv) ;
870 ],
871  
872 },
873 'T_AVREF' =>
874 {
875 'OUTPUT' => " \$arg = SvREFCNT_inc (${cnvprefix}AVREF_2obj(\$var));",
876 'INPUT' => " \$var = ${cnvprefix}sv2_AVREF(\$arg)",
877 },
878 'T_HVREF' =>
879 {
880 'OUTPUT' => " \$arg = SvREFCNT_inc (${cnvprefix}HVREF_2obj(\$var));",
881 'INPUT' => " \$var = ${cnvprefix}sv2_HVREF(\$arg)",
882 },
883 'T_SVPTR' =>
884 {
885 'OUTPUT' => " \$arg = SvREFCNT_inc (${cnvprefix}SVPTR_2obj(\$var));",
886 'INPUT' => " \$var = (\$type)${cnvprefix}sv2_SVPTR(\$arg)",
887 },
888 'T_PVnull' =>
889 {
890 'OUTPUT' => " \$arg = SvREFCNT_inc (${cnvprefix}PVnull_2obj(\$var));",
891 'INPUT' => " \$var = (\$type)${cnvprefix}sv2_PVnull(\$arg)",
892 },
893  
894 },
895 }
896  
897  
898  
899  
900 1 1;
901 __END__
« XSBuilder/FunctionMap.pm ↑ Summary XSBuilder/StructureMap.pm »