line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::Probe; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
236309
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
18
|
use 5.008004; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
8
|
use File::Basename qw( dirname ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
96
|
|
7
|
1
|
|
|
1
|
|
699
|
use Data::Dumper (); |
|
1
|
|
|
|
|
6745
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
419
|
use FFI::Probe::Runner; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
1
|
|
|
1
|
|
446
|
use FFI::Build; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
424
|
use FFI::Build::File::C; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
11
|
1
|
|
|
1
|
|
6
|
use Capture::Tiny qw( capture_merged capture ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
12
|
1
|
|
|
1
|
|
5
|
use FFI::Temp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2938
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# ABSTRACT: System detection and probing for FFI extensions. |
15
|
|
|
|
|
|
|
our $VERSION = '2.08'; # VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
3
|
|
|
3
|
1
|
4006
|
my($class, %args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
50
|
|
|
14
|
$args{log} ||= "ffi-probe.log"; |
23
|
3
|
|
50
|
|
|
10
|
$args{data_filename} ||= "ffi-probe.pl"; |
24
|
|
|
|
|
|
|
|
25
|
3
|
50
|
|
|
|
10
|
unless(ref $args{log}) |
26
|
|
|
|
|
|
|
{ |
27
|
3
|
|
|
|
|
6
|
my $fn = $args{log}; |
28
|
3
|
|
|
|
|
6
|
my $fh; |
29
|
3
|
|
|
|
|
219
|
open $fh, '>>', $fn; |
30
|
3
|
|
|
|
|
35
|
$args{log} = $fh; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
5
|
my $data; |
34
|
|
|
|
|
|
|
|
35
|
3
|
100
|
|
|
|
79
|
if(-r $args{data_filename}) |
36
|
|
|
|
|
|
|
{ |
37
|
1
|
|
|
|
|
6
|
my $fn = $args{data_filename}; |
38
|
1
|
50
|
|
|
|
973
|
unless($data = do $fn) |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
0
|
|
|
|
0
|
die "couldn't parse configuration $fn $@" if $@; |
41
|
0
|
0
|
|
|
|
0
|
die "couldn't do $fn $!" if $!; |
42
|
0
|
|
|
|
|
0
|
die "bad or missing config file $fn"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
100
|
|
|
26
|
$data ||= {}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $self = bless { |
49
|
|
|
|
|
|
|
headers => [], |
50
|
|
|
|
|
|
|
log => $args{log}, |
51
|
|
|
|
|
|
|
data_filename => $args{data_filename}, |
52
|
|
|
|
|
|
|
data => $data, |
53
|
|
|
|
|
|
|
dir => FFI::Temp->newdir( TEMPLATE => 'ffi-probe-XXXXXX' ), |
54
|
|
|
|
|
|
|
counter => 0, |
55
|
|
|
|
|
|
|
runner => $args{runner}, |
56
|
|
|
|
|
|
|
alien => $args{alien} || [], |
57
|
|
|
|
|
|
|
cflags => $args{cflags}, |
58
|
|
|
|
|
|
|
libs => $args{libs}, |
59
|
3
|
|
50
|
|
|
42
|
}, $class; |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
|
|
1440
|
$self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _runner |
65
|
|
|
|
|
|
|
{ |
66
|
5
|
|
|
5
|
|
38
|
my($self) = @_; |
67
|
5
|
|
33
|
|
|
120
|
$self->{runner} ||= FFI::Probe::Runner->new; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub check_header |
72
|
|
|
|
|
|
|
{ |
73
|
7
|
|
|
7
|
1
|
3676
|
my($self, $header) = @_; |
74
|
|
|
|
|
|
|
|
75
|
7
|
100
|
|
|
|
67
|
return if defined $self->{data}->{header}->{$header}; |
76
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
29
|
my $code = ''; |
78
|
3
|
|
|
|
|
6
|
$code .= "#include <$_>\n" for @{ $self->{headers} }, $header; |
|
3
|
|
|
|
|
32
|
|
79
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
72
|
my $build = FFI::Build->new("hcheck@{[ ++$self->{counter} ]}", |
81
|
|
|
|
|
|
|
verbose => 2, |
82
|
|
|
|
|
|
|
dir => $self->{dir}, |
83
|
|
|
|
|
|
|
alien => $self->{alien}, |
84
|
|
|
|
|
|
|
cflags => $self->{cflags}, |
85
|
|
|
|
|
|
|
libs => $self->{libs}, |
86
|
3
|
|
|
|
|
13
|
); |
87
|
|
|
|
|
|
|
my $file = FFI::Build::File::C->new( |
88
|
|
|
|
|
|
|
\$code, |
89
|
|
|
|
|
|
|
dir => $self->{dir}, |
90
|
3
|
|
|
|
|
55
|
build => $build, |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
my($out, $o) = capture_merged { |
93
|
3
|
|
|
3
|
|
3693
|
eval { $file->build_item }; |
|
3
|
|
|
|
|
23
|
|
94
|
3
|
|
|
|
|
183
|
}; |
95
|
3
|
|
|
|
|
2805
|
$self->log_code($code); |
96
|
3
|
|
|
|
|
23
|
$self->log($out); |
97
|
3
|
100
|
|
|
|
21
|
if($o) |
98
|
|
|
|
|
|
|
{ |
99
|
2
|
|
|
|
|
36
|
$self->set('header', $header => 1); |
100
|
2
|
|
|
|
|
15
|
push @{ $self->{headers} }, $header; |
|
2
|
|
|
|
|
13
|
|
101
|
2
|
|
|
|
|
67
|
return 1; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else |
104
|
|
|
|
|
|
|
{ |
105
|
1
|
|
|
|
|
18
|
$self->set('header', $header => 0); |
106
|
1
|
|
|
|
|
6
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub check_cpp |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
0
|
1
|
0
|
my($self, $code) = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
my $build = FFI::Build->new("hcheck@{[ ++$self->{counter} ]}", |
116
|
|
|
|
|
|
|
verbose => 2, |
117
|
|
|
|
|
|
|
dir => $self->{dir}, |
118
|
|
|
|
|
|
|
alien => $self->{alien}, |
119
|
|
|
|
|
|
|
cflags => $self->{cflags}, |
120
|
|
|
|
|
|
|
libs => $self->{libs}, |
121
|
0
|
|
|
|
|
0
|
); |
122
|
|
|
|
|
|
|
my $file = FFI::Build::File::C->new( |
123
|
|
|
|
|
|
|
\$code, |
124
|
|
|
|
|
|
|
dir => $self->{dir}, |
125
|
0
|
|
|
|
|
0
|
build => $build, |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
my($out, $i) = capture_merged { |
128
|
0
|
|
|
0
|
|
0
|
eval { $file->build_item_cpp }; |
|
0
|
|
|
|
|
0
|
|
129
|
0
|
|
|
|
|
0
|
}; |
130
|
0
|
|
|
|
|
0
|
$self->log_code($code); |
131
|
0
|
|
|
|
|
0
|
$self->log($out); |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
0
|
|
|
0
|
if($i && -f $i->path) |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
|
|
0
|
return $i->slurp; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else |
138
|
|
|
|
|
|
|
{ |
139
|
0
|
|
|
|
|
0
|
return; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub check_eval |
145
|
|
|
|
|
|
|
{ |
146
|
5
|
|
|
5
|
1
|
2571
|
my($self, %args) = @_; |
147
|
|
|
|
|
|
|
|
148
|
5
|
|
33
|
|
|
118
|
my $code = $args{_template} || $self->template; |
149
|
|
|
|
|
|
|
|
150
|
5
|
50
|
|
|
|
19
|
my $headers = join "", map { "#include <$_>\n" } (@{ $self->{headers} }, @{ $args{headers} || [] }); |
|
3
|
|
|
|
|
44
|
|
|
5
|
|
|
|
|
23
|
|
|
5
|
|
|
|
|
52
|
|
151
|
5
|
100
|
|
|
|
20
|
my @decl = @{ $args{decl} || [] }; |
|
5
|
|
|
|
|
30
|
|
152
|
5
|
100
|
|
|
|
19
|
my @stmt = @{ $args{stmt} || [] }; |
|
5
|
|
|
|
|
40
|
|
153
|
5
|
50
|
|
|
|
11
|
my %eval = %{ $args{eval} || {} }; |
|
5
|
|
|
|
|
42
|
|
154
|
|
|
|
|
|
|
|
155
|
5
|
|
|
|
|
79
|
$code =~ s/##HEADERS##/$headers/; |
156
|
5
|
|
|
|
|
65
|
$code =~ s/##DECL##/join "\n", @decl/e; |
|
5
|
|
|
|
|
42
|
|
157
|
5
|
|
|
|
|
49
|
$code =~ s/##STMT##/join "\n", @stmt/e; |
|
5
|
|
|
|
|
28
|
|
158
|
|
|
|
|
|
|
|
159
|
5
|
|
|
|
|
19
|
my $eval = ''; |
160
|
5
|
|
|
|
|
23
|
my $i=0; |
161
|
5
|
|
|
|
|
15
|
my %map; |
162
|
5
|
|
|
|
|
29
|
foreach my $key (sort keys %eval) |
163
|
|
|
|
|
|
|
{ |
164
|
9
|
|
|
|
|
22
|
$i++; |
165
|
9
|
|
|
|
|
27
|
$map{$key} = "eval$i"; |
166
|
9
|
|
|
|
|
15
|
my($format,$expression) = @{ $eval{$key} }; |
|
9
|
|
|
|
|
24
|
|
167
|
9
|
|
|
|
|
45
|
$eval .= " printf(\"eval$i=<<<$format>>>\\n\", $expression);\n"; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
5
|
|
|
|
|
49
|
$code =~ s/##EVAL##/$eval/; |
171
|
|
|
|
|
|
|
|
172
|
5
|
|
|
|
|
209
|
my $build = FFI::Build->new("eval@{[ ++$self->{counter} ]}", |
173
|
|
|
|
|
|
|
verbose => 2, |
174
|
|
|
|
|
|
|
dir => $self->{dir}, |
175
|
|
|
|
|
|
|
alien => $self->{alien}, |
176
|
|
|
|
|
|
|
cflags => $self->{cflags}, |
177
|
|
|
|
|
|
|
libs => $self->{libs}, |
178
|
5
|
|
|
|
|
21
|
export => ['dlmain'], |
179
|
|
|
|
|
|
|
); |
180
|
|
|
|
|
|
|
$build->source( |
181
|
|
|
|
|
|
|
FFI::Build::File::C->new( |
182
|
|
|
|
|
|
|
\$code, |
183
|
|
|
|
|
|
|
dir => $self->{dir}, |
184
|
5
|
|
|
|
|
87
|
build => $build, |
185
|
|
|
|
|
|
|
), |
186
|
|
|
|
|
|
|
); |
187
|
|
|
|
|
|
|
|
188
|
5
|
|
|
|
|
14
|
my $lib = do { |
189
|
|
|
|
|
|
|
my($out, $lib, $error) = capture_merged { |
190
|
5
|
|
|
5
|
|
5575
|
my $lib = eval { |
191
|
5
|
|
|
|
|
57
|
$build->build; |
192
|
|
|
|
|
|
|
}; |
193
|
5
|
|
|
|
|
83
|
($lib, $@); |
194
|
5
|
|
|
|
|
253
|
}; |
195
|
|
|
|
|
|
|
|
196
|
5
|
|
|
|
|
4821
|
$self->log_code($code); |
197
|
5
|
|
|
|
|
23
|
$self->log("[build]"); |
198
|
5
|
|
|
|
|
25
|
$self->log($out); |
199
|
5
|
50
|
|
|
|
77
|
if($error) |
|
|
50
|
|
|
|
|
|
200
|
|
|
|
|
|
|
{ |
201
|
0
|
|
|
|
|
0
|
$self->log("exception: $error"); |
202
|
0
|
|
|
|
|
0
|
return; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
elsif(!$lib) |
205
|
|
|
|
|
|
|
{ |
206
|
0
|
|
|
|
|
0
|
$self->log("failed"); |
207
|
0
|
|
|
|
|
0
|
return; |
208
|
|
|
|
|
|
|
} |
209
|
5
|
|
|
|
|
26
|
$lib; |
210
|
|
|
|
|
|
|
}; |
211
|
|
|
|
|
|
|
|
212
|
5
|
|
|
|
|
64
|
my $result = $self->_runner->run($lib->path); |
213
|
|
|
|
|
|
|
|
214
|
5
|
|
|
|
|
104
|
$self->log("[stdout]"); |
215
|
5
|
|
|
|
|
112
|
$self->log($result->stdout); |
216
|
5
|
|
|
|
|
31
|
$self->log("[stderr]"); |
217
|
5
|
|
|
|
|
73
|
$self->log($result->stderr); |
218
|
5
|
|
|
|
|
17
|
$self->log("rv = @{[ $result->rv ]}"); |
|
5
|
|
|
|
|
52
|
|
219
|
5
|
50
|
|
|
|
55
|
$self->log("sig = @{[ $result->signal ]}") if $result->signal; |
|
0
|
|
|
|
|
0
|
|
220
|
|
|
|
|
|
|
|
221
|
5
|
50
|
|
|
|
53
|
if($result->pass) |
222
|
|
|
|
|
|
|
{ |
223
|
5
|
|
|
|
|
75
|
foreach my $key (sort keys %eval) |
224
|
|
|
|
|
|
|
{ |
225
|
9
|
|
|
|
|
55
|
my $eval = $map{$key}; |
226
|
9
|
50
|
|
|
|
36
|
if($result->stdout =~ /$eval=<<<(.*?)>>>/) |
227
|
|
|
|
|
|
|
{ |
228
|
9
|
|
|
|
|
75
|
my $value = $1; |
229
|
9
|
|
|
|
|
91
|
my @key = split /\./, $key; |
230
|
9
|
|
|
|
|
79
|
$self->set(@key, $value); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
} |
233
|
5
|
|
|
|
|
253
|
return 1; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
else |
236
|
|
|
|
|
|
|
{ |
237
|
0
|
|
|
|
|
0
|
return; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub check |
243
|
|
|
|
|
|
|
{ |
244
|
0
|
|
|
0
|
1
|
0
|
my($self, $name, $code) = @_; |
245
|
0
|
0
|
|
|
|
0
|
if($self->check_eval(_template => $code)) |
246
|
|
|
|
|
|
|
{ |
247
|
0
|
|
|
|
|
0
|
$self->set('probe', $name, 1); |
248
|
0
|
|
|
|
|
0
|
return 1; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
else |
251
|
|
|
|
|
|
|
{ |
252
|
0
|
|
|
|
|
0
|
$self->set('probe', $name, 0); |
253
|
0
|
|
|
|
|
0
|
return; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub check_type_int |
259
|
|
|
|
|
|
|
{ |
260
|
1
|
|
|
1
|
1
|
1458
|
my($self, $type) = @_; |
261
|
|
|
|
|
|
|
|
262
|
1
|
|
|
|
|
34
|
$self->check_header('stddef.h'); |
263
|
|
|
|
|
|
|
|
264
|
1
|
|
|
|
|
69
|
my $ret = $self->check_eval( |
265
|
|
|
|
|
|
|
decl => [ |
266
|
|
|
|
|
|
|
'#define signed(type) (((type)-1) < 0) ? "signed" : "unsigned"', |
267
|
|
|
|
|
|
|
"struct align { char a; $type b; };", |
268
|
|
|
|
|
|
|
], |
269
|
|
|
|
|
|
|
eval => { |
270
|
|
|
|
|
|
|
"type.$type.size" => [ '%d' => "(int)sizeof($type)" ], |
271
|
|
|
|
|
|
|
"type.$type.sign" => [ '%s' => "signed($type)" ], |
272
|
|
|
|
|
|
|
"type.$type.align" => [ '%d' => '(int)offsetof(struct align, b)' ], |
273
|
|
|
|
|
|
|
}, |
274
|
|
|
|
|
|
|
); |
275
|
|
|
|
|
|
|
|
276
|
1
|
50
|
|
|
|
38
|
return unless $ret; |
277
|
|
|
|
|
|
|
|
278
|
1
|
|
|
|
|
19
|
my $size = $self->data->{type}->{$type}->{size}; |
279
|
1
|
|
|
|
|
26
|
my $sign = $self->data->{type}->{$type}->{sign}; |
280
|
|
|
|
|
|
|
|
281
|
1
|
50
|
|
|
|
31
|
sprintf("%sint%d", $sign eq 'signed' ? 's' : 'u', $size*8); |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
sub check_type_enum |
286
|
|
|
|
|
|
|
{ |
287
|
0
|
|
|
0
|
1
|
0
|
my($self) = @_; |
288
|
|
|
|
|
|
|
|
289
|
0
|
|
|
|
|
0
|
$self->check_header('stddef.h'); |
290
|
|
|
|
|
|
|
|
291
|
0
|
|
|
|
|
0
|
my $ret = $self->check_eval( |
292
|
|
|
|
|
|
|
decl => [ |
293
|
|
|
|
|
|
|
'#define signed(type) (((type)-1) < 0) ? "signed" : "unsigned"', |
294
|
|
|
|
|
|
|
"typedef enum { ONE, TWO } myenum;", |
295
|
|
|
|
|
|
|
"struct align { char a; myenum b; };", |
296
|
|
|
|
|
|
|
], |
297
|
|
|
|
|
|
|
eval => { |
298
|
|
|
|
|
|
|
"type.enum.size" => [ '%d' => '(int)sizeof(myenum)' ], |
299
|
|
|
|
|
|
|
"type.enum.sign" => [ '%s' => 'signed(myenum)' ], |
300
|
|
|
|
|
|
|
"type.enum.align" => [ '%d' => '(int)offsetof(struct align, b)' ], |
301
|
|
|
|
|
|
|
}, |
302
|
|
|
|
|
|
|
); |
303
|
|
|
|
|
|
|
|
304
|
0
|
0
|
|
|
|
0
|
return unless $ret; |
305
|
|
|
|
|
|
|
|
306
|
0
|
|
|
|
|
0
|
my $size = $self->data->{type}->{enum}->{size}; |
307
|
0
|
|
|
|
|
0
|
my $sign = $self->data->{type}->{enum}->{sign}; |
308
|
|
|
|
|
|
|
|
309
|
0
|
0
|
|
|
|
0
|
sprintf("%sint%d", $sign eq 'signed' ? 's' : 'u', $size*8); |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
sub check_type_signed_enum |
314
|
|
|
|
|
|
|
{ |
315
|
0
|
|
|
0
|
0
|
0
|
my($self) = @_; |
316
|
|
|
|
|
|
|
|
317
|
0
|
|
|
|
|
0
|
$self->check_header('stddef.h'); |
318
|
|
|
|
|
|
|
|
319
|
0
|
|
|
|
|
0
|
my $ret = $self->check_eval( |
320
|
|
|
|
|
|
|
decl => [ |
321
|
|
|
|
|
|
|
'#define signed(type) (((type)-1) < 0) ? "signed" : "unsigned"', |
322
|
|
|
|
|
|
|
"typedef enum { NEG = -1, ONE = 1, TWO = 2 } myenum;", |
323
|
|
|
|
|
|
|
"struct align { char a; myenum b; };", |
324
|
|
|
|
|
|
|
], |
325
|
|
|
|
|
|
|
eval => { |
326
|
|
|
|
|
|
|
"type.senum.size" => [ '%d' => '(int)sizeof(myenum)' ], |
327
|
|
|
|
|
|
|
"type.senum.sign" => [ '%s' => 'signed(myenum)' ], |
328
|
|
|
|
|
|
|
"type.senum.align" => [ '%d' => '(int)offsetof(struct align, b)' ], |
329
|
|
|
|
|
|
|
}, |
330
|
|
|
|
|
|
|
); |
331
|
|
|
|
|
|
|
|
332
|
0
|
0
|
|
|
|
0
|
return unless $ret; |
333
|
|
|
|
|
|
|
|
334
|
0
|
|
|
|
|
0
|
my $size = $self->data->{type}->{senum}->{size}; |
335
|
0
|
|
|
|
|
0
|
my $sign = $self->data->{type}->{senum}->{sign}; |
336
|
|
|
|
|
|
|
|
337
|
0
|
0
|
|
|
|
0
|
sprintf("%sint%d", $sign eq 'signed' ? 's' : 'u', $size*8); |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
sub check_type_float |
342
|
|
|
|
|
|
|
{ |
343
|
1
|
|
|
1
|
1
|
1367
|
my($self, $type) = @_; |
344
|
|
|
|
|
|
|
|
345
|
1
|
|
|
|
|
20
|
$self->check_header('stddef.h'); |
346
|
|
|
|
|
|
|
|
347
|
1
|
|
|
|
|
23
|
my $ret = $self->check_eval( |
348
|
|
|
|
|
|
|
decl => [ |
349
|
|
|
|
|
|
|
"struct align { char a; $type b; };", |
350
|
|
|
|
|
|
|
], |
351
|
|
|
|
|
|
|
eval => { |
352
|
|
|
|
|
|
|
"type.$type.size" => [ '%d' => "(int)sizeof($type)" ], |
353
|
|
|
|
|
|
|
"type.$type.align" => [ '%d' => '(int)offsetof(struct align, b)' ], |
354
|
|
|
|
|
|
|
}, |
355
|
|
|
|
|
|
|
); |
356
|
|
|
|
|
|
|
|
357
|
1
|
50
|
|
|
|
51
|
return unless $ret; |
358
|
|
|
|
|
|
|
|
359
|
1
|
|
|
|
|
31
|
my $size = $self->data->{type}->{$type}->{size}; |
360
|
1
|
|
|
|
|
12
|
my $complex = !!$type =~ /complex/; |
361
|
|
|
|
|
|
|
|
362
|
1
|
50
|
|
|
|
18
|
if($complex) { |
363
|
0
|
|
|
|
|
0
|
$size /= 2; |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
|
366
|
1
|
|
|
|
|
4
|
my $t; |
367
|
1
|
50
|
|
|
|
25
|
if($size == 4) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
368
|
1
|
|
|
|
|
4
|
{ $t = 'float' } |
369
|
|
|
|
|
|
|
elsif($size == 8) |
370
|
0
|
|
|
|
|
0
|
{ $t = 'double' } |
371
|
|
|
|
|
|
|
elsif($size > 9) |
372
|
0
|
|
|
|
|
0
|
{ $t = 'longdouble' } |
373
|
|
|
|
|
|
|
|
374
|
1
|
50
|
|
|
|
11
|
$t = "complex_$t" if $complex; |
375
|
|
|
|
|
|
|
|
376
|
1
|
|
|
|
|
19
|
$t; |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
sub check_type_pointer |
381
|
|
|
|
|
|
|
{ |
382
|
1
|
|
|
1
|
1
|
1377
|
my($self) = @_; |
383
|
|
|
|
|
|
|
|
384
|
1
|
|
|
|
|
81
|
$self->check_header('stddef.h'); |
385
|
|
|
|
|
|
|
|
386
|
1
|
|
|
|
|
26
|
my $ret = $self->check_eval( |
387
|
|
|
|
|
|
|
decl => [ |
388
|
|
|
|
|
|
|
"struct align { char a; void* b; };", |
389
|
|
|
|
|
|
|
], |
390
|
|
|
|
|
|
|
eval => { |
391
|
|
|
|
|
|
|
"type.pointer.size" => [ '%d' => '(int)sizeof(void *)' ], |
392
|
|
|
|
|
|
|
"type.pointer.align" => [ '%d' => '(int)offsetof(struct align, b)' ], |
393
|
|
|
|
|
|
|
}, |
394
|
|
|
|
|
|
|
); |
395
|
|
|
|
|
|
|
|
396
|
1
|
50
|
|
|
|
37
|
return unless $ret; |
397
|
1
|
|
|
|
|
37
|
'pointer'; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
sub _set |
401
|
|
|
|
|
|
|
{ |
402
|
33
|
|
|
33
|
|
198
|
my($data, $value, @key) = @_; |
403
|
33
|
|
|
|
|
93
|
my $key = shift @key; |
404
|
33
|
100
|
|
|
|
130
|
if(@key > 0) |
405
|
|
|
|
|
|
|
{ |
406
|
21
|
|
100
|
|
|
260
|
_set($data->{$key} ||= {}, $value, @key); |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
else |
409
|
|
|
|
|
|
|
{ |
410
|
12
|
|
|
|
|
140
|
$data->{$key} = $value; |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
sub set |
416
|
|
|
|
|
|
|
{ |
417
|
12
|
|
|
12
|
1
|
36
|
my $self = shift; |
418
|
12
|
|
|
|
|
42
|
my $value = pop; |
419
|
12
|
|
|
|
|
64
|
my @key = @_; |
420
|
|
|
|
|
|
|
|
421
|
12
|
|
|
|
|
26
|
my $print_value = $value; |
422
|
12
|
50
|
|
|
|
71
|
if(ref $print_value) |
423
|
|
|
|
|
|
|
{ |
424
|
0
|
|
|
|
|
0
|
my $d = Data::Dumper->new([$value], [qw($value)]); |
425
|
0
|
|
|
|
|
0
|
$d->Indent(0); |
426
|
0
|
|
|
|
|
0
|
$d->Terse(1); |
427
|
0
|
|
|
|
|
0
|
$print_value = $d->Dump; |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
|
430
|
12
|
100
|
|
|
|
35
|
my $key = join ".", map { /\./ ? "\"$_\"" : $_ } @key; |
|
33
|
|
|
|
|
260
|
|
431
|
12
|
|
|
|
|
505
|
print "PR $key=$print_value\n"; |
432
|
12
|
|
|
|
|
104
|
$self->log("$key=$print_value"); |
433
|
12
|
|
|
|
|
166
|
_set($self->{data}, $value, @key); |
434
|
|
|
|
|
|
|
} |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
sub save |
438
|
|
|
|
|
|
|
{ |
439
|
4
|
|
|
4
|
1
|
23
|
my($self) = @_; |
440
|
|
|
|
|
|
|
|
441
|
4
|
|
|
|
|
324
|
my $dir = dirname($self->{data_filename}); |
442
|
|
|
|
|
|
|
|
443
|
4
|
|
|
|
|
108
|
my $dd = Data::Dumper->new([$self->{data}],['x']) |
444
|
|
|
|
|
|
|
->Indent(1) |
445
|
|
|
|
|
|
|
->Terse(0) |
446
|
|
|
|
|
|
|
->Purity(1) |
447
|
|
|
|
|
|
|
->Sortkeys(1) |
448
|
|
|
|
|
|
|
->Dump; |
449
|
|
|
|
|
|
|
|
450
|
4
|
50
|
|
|
|
1053
|
mkpath( $dir, 0, oct(755) ) unless -d $dir; |
451
|
|
|
|
|
|
|
|
452
|
4
|
|
|
|
|
17
|
my $fh; |
453
|
4
|
50
|
|
|
|
360
|
open($fh, '>', $self->{data_filename}) || die "error writing @{[ $self->{data_filename} ]}"; |
|
0
|
|
|
|
|
0
|
|
454
|
4
|
|
|
|
|
45
|
print $fh 'do { my '; |
455
|
4
|
|
|
|
|
15
|
print $fh $dd; |
456
|
4
|
|
|
|
|
10
|
print $fh '$x;}'; |
457
|
4
|
|
|
|
|
356
|
close $fh; |
458
|
|
|
|
|
|
|
} |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
|
461
|
18
|
|
|
18
|
1
|
5472
|
sub data { shift->{data} } |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
sub log |
465
|
|
|
|
|
|
|
{ |
466
|
132
|
|
|
132
|
1
|
367
|
my($self, $string) = @_; |
467
|
132
|
|
|
|
|
199
|
my $fh = $self->{log}; |
468
|
132
|
|
|
|
|
178
|
chomp $string; |
469
|
132
|
|
|
|
|
480
|
print $fh $string, "\n"; |
470
|
|
|
|
|
|
|
} |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
sub log_code |
474
|
|
|
|
|
|
|
{ |
475
|
8
|
|
|
8
|
1
|
85
|
my($self, $code) = @_; |
476
|
8
|
|
|
|
|
79
|
my @code = split /\n/, $code; |
477
|
8
|
|
|
|
|
50
|
chomp for @code; |
478
|
8
|
|
|
|
|
60
|
$self->log("code: $_") for @code; |
479
|
|
|
|
|
|
|
} |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
sub DESTROY |
482
|
|
|
|
|
|
|
{ |
483
|
3
|
|
|
3
|
|
1821
|
my($self) = @_; |
484
|
3
|
|
|
|
|
20
|
$self->save; |
485
|
3
|
|
|
|
|
28
|
my $fh = $self->{log}; |
486
|
3
|
50
|
|
|
|
18
|
return unless defined $fh; |
487
|
3
|
|
|
|
|
165
|
close $fh; |
488
|
|
|
|
|
|
|
} |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
my $template; |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
sub template |
494
|
|
|
|
|
|
|
{ |
495
|
5
|
100
|
|
5
|
1
|
36
|
unless(defined $template) |
496
|
|
|
|
|
|
|
{ |
497
|
1
|
|
|
|
|
9
|
local $/; |
498
|
1
|
|
|
|
|
40
|
$template = ; |
499
|
|
|
|
|
|
|
} |
500
|
|
|
|
|
|
|
|
501
|
5
|
|
|
|
|
40
|
$template; |
502
|
|
|
|
|
|
|
} |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
1; |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
=pod |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
=encoding UTF-8 |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=head1 NAME |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
FFI::Probe - System detection and probing for FFI extensions. |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
=head1 VERSION |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
version 2.08 |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
=head1 SYNOPSIS |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
use FFI::Probe; |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
my $probe = FFI::Probe->new; |
523
|
|
|
|
|
|
|
$probe->check_header('foo.h'); |
524
|
|
|
|
|
|
|
... |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
=head1 DESCRIPTION |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
This class provides an interface for probing for system |
529
|
|
|
|
|
|
|
capabilities. It is used internally as part of the |
530
|
|
|
|
|
|
|
L build process, but it may also be useful |
531
|
|
|
|
|
|
|
for extensions that use Platypus as well. |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
=head2 new |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
my $probe = FFI::Probe->new(%args); |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
Creates a new instance. |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
=over 4 |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
=item log |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
Path to a log or file handle to write to. |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
=item data_filename |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
Path to a file which will be used to store/cache results. |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
=back |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
=head1 METHODS |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
=head2 check_header |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
my $bool = $probe->check_header($header); |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
Checks that the given C header file is available. |
560
|
|
|
|
|
|
|
Stores the result, and returns a true/false value. |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=head2 check_cpp |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
=head2 check_eval |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
my $bool = $probe>check_eval(%args); |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
=over 4 |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
=item headers |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
Any additional headers. |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
=item decl |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
Any C declarations that need to be made before the C function. |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=item stmt |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
Any C statements that should be made before the evaluation. |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
=item eval |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
Any evaluations that should be returned. |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
=back |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
=head2 check |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
=head2 check_type_int |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
my $type = $probe->check_type_int($type); |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
=head2 check_type_enum |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
my $type = $probe->check_type_enum; |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
=head2 check_type_enum |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
my $type = $probe->check_type_enum; |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
=head2 check_type_float |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
my $type = $probe->check_type_float($type); |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
=head2 check_type_pointer |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
my $type = $probe->check_type_pointer; |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
=head2 set |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
$probe->set(@key, $value); |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
Used internally to store a value. |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
=head2 save |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
$probe->save; |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
Saves the values already detected. |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=head2 data |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
my $data = $probe->data; |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
Returns a hashref of the data already detected. |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
=head2 log |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
$probe->log($string); |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
Sends the given string to the log. |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
=head2 log_code |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
$prbe->log_code($string); |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
Sends the given multi-line code block to the log. |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
=head2 template |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
my $template = $probe->template; |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
Returns the C code template used for C and other |
645
|
|
|
|
|
|
|
C methods. |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
=head1 AUTHOR |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
Author: Graham Ollis Eplicease@cpan.orgE |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
Contributors: |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
Bakkiaraj Murugesan (bakkiaraj) |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
Dylan Cali (calid) |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
pipcet |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
Zaki Mughal (zmughal) |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
Fitz Elliott (felliott) |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
Vickenty Fesunov (vyf) |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
Gregor Herrmann (gregoa) |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
Shlomi Fish (shlomif) |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
Damyan Ivanov |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
Ilya Pavlov (Ilya33) |
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
Petr Písař (ppisar) |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
Mohammad S Anwar (MANWAR) |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
Håkon Hægland (hakonhagland, HAKONH) |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
Meredith (merrilymeredith, MHOWARD) |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
Diab Jerius (DJERIUS) |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
Eric Brine (IKEGAMI) |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
szTheory |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
José Joaquín Atria (JJATRIA) |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
Pete Houston (openstrike, HOUSTON) |
690
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
This software is copyright (c) 2015-2022 by Graham Ollis. |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
696
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
=cut |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
__DATA__ |