| 1 | package FFI::Probe; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use File::Basename qw( dirname ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Data::Dumper (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use FFI::Probe::Runner; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use FFI::Build; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use FFI::Build::File::C; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Capture::Tiny qw( capture_merged capture ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use FFI::Temp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # ABSTRACT: System detection and probing for FFI extensions. | ||||||||||||||||||||||||||||
| 15 | 3 | our $VERSION = '2.12'; # VERSION | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub new | ||||||||||||||||||||||||||||
| 19 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 3 | my($class, %args) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | ▶ | $args{log} ||= "ffi-probe.log"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"log"} ||= "ffi-probe.log"
MC/DC0%0/1
$args{"log"} ||= "ffi-probe.log"
$args{"log"}
Truth table50%1/2
A
A= $args{"log"}
| |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | $args{data_filename} ||= "ffi-probe.pl"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"data_filename"} ||= "ffi-probe.pl"
MC/DC0%0/1
$args{"data_filename"} ||= "ffi-probe.pl"
$args{"data_filename"}
Truth table50%1/2
A
A= $args{"data_filename"}
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | unless(ref $args{log}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 3 | my $fn = $args{log}; | |||||||||||||||||||||||||||
| 28 | 3 | my $fh; | |||||||||||||||||||||||||||
| 29 | 3 | open $fh, '>>', $fn; | |||||||||||||||||||||||||||
| 30 | 3 | $args{log} = $fh; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | my $data; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 3 | ▶ | if(-r $args{data_filename}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | 1 | my $fn = $args{data_filename}; | |||||||||||||||||||||||||||
| 38 | 1 | ▶ | unless($data = do $fn) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | die "couldn't parse configuration $fn $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | die "couldn't do $fn $!" if $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | die "bad or missing config file $fn"; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | $data ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$data ||= {}
MC/DC100%1/1
$data ||= {}
$data
Truth table100%2/2
A
A= $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 | ▶ | }, $class; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'alien'} || []
MC/DC0%0/1
$args{'alien'} || []
$args{'alien'}
Truth table50%1/2
A
A= $args{'alien'}
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | $self; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub _runner | ||||||||||||||||||||||||||||
| 65 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_runner: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||
| 66 | 5 | my($self) = @_; | |||||||||||||||||||||||||||
| 67 | 5 | ▶ | $self->{runner} ||= FFI::Probe::Runner->new; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"runner"} ||= "FFI::Probe::Runner"->new
MC/DC0%0/2
$self->{"runner"} ||= "FFI::Probe::Runner"->new
$self->{"runner"}
"FFI::Probe::Runner"->new
Truth table33%1/3
A ||= B
A= $self->{"runner"}B= "FFI::Probe::Runner"->new
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub check_header | ||||||||||||||||||||||||||||
| 72 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_header: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 7 | my($self, $header) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 7 | ▶ | return if defined $self->{data}->{header}->{$header}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 3 | my $code = ''; | |||||||||||||||||||||||||||
| 78 | 3 | $code .= "#include <$_>\n" for @{ $self->{headers} }, $header; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | 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 | ); | |||||||||||||||||||||||||||
| 87 | my $file = FFI::Build::File::C->new( | ||||||||||||||||||||||||||||
| 88 | \$code, | ||||||||||||||||||||||||||||
| 89 | dir => $self->{dir}, | ||||||||||||||||||||||||||||
| 90 | 3 | build => $build, | |||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | 3 | ▶ | my($out, $o) = capture_merged { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 93 | 3 | eval { $file->build_item }; | |||||||||||||||||||||||||||
| 94 | 3 | }; | |||||||||||||||||||||||||||
| 95 | 3 | $self->log_code($code); | |||||||||||||||||||||||||||
| 96 | 3 | $self->log($out); | |||||||||||||||||||||||||||
| 97 | 3 | ▶ | if($o) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 2 | $self->set('header', $header => 1); | |||||||||||||||||||||||||||
| 100 | 2 | push @{ $self->{headers} }, $header; | |||||||||||||||||||||||||||
| 101 | 2 | return 1; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | else | ||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | 1 | $self->set('header', $header => 0); | |||||||||||||||||||||||||||
| 106 | 1 | return; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub check_cpp | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_cpp: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 0 | my($self, $code) = @_; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 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 | ); | |||||||||||||||||||||||||||
| 122 | my $file = FFI::Build::File::C->new( | ||||||||||||||||||||||||||||
| 123 | \$code, | ||||||||||||||||||||||||||||
| 124 | dir => $self->{dir}, | ||||||||||||||||||||||||||||
| 125 | 0 | build => $build, | |||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my($out, $i) = capture_merged { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 128 | 0 | eval { $file->build_item_cpp }; | |||||||||||||||||||||||||||
| 129 | 0 | }; | |||||||||||||||||||||||||||
| 130 | 0 | $self->log_code($code); | |||||||||||||||||||||||||||
| 131 | 0 | $self->log($out); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if($i && -f $i->path) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i and -f $i->path
MC/DC0%0/2
$i and -f $i->path
$i
-f $i->path
Truth table0%0/3
A and B
A= $iB= -f $i->path
| |||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||
| 135 | 0 | return $i->slurp; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | else | ||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 0 | return; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | sub check_eval | ||||||||||||||||||||||||||||
| 145 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_eval: called CC=13 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 5 | my($self, %args) = @_; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 5 | ▶ | my $code = $args{_template} || $self->template; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{'_template'} || $self->template
MC/DC0%0/2
$args{'_template'} || $self->template
$args{'_template'}
$self->template
Truth table33%1/3
A || B
A= $args{'_template'}B= $self->template
| |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 5 | ▶ | my $headers = join "", map { "#include <$_>\n" } (@{ $self->{headers} }, @{ $args{headers} || [] }); | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'headers'} || []
MC/DC0%0/1
$args{'headers'} || []
$args{'headers'}
Truth table50%1/2
A
A= $args{'headers'}
| |||||||||||||||||||||||||||||
| 151 | 5 | ▶ | my @decl = @{ $args{decl} || [] }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args{'decl'} || []
MC/DC100%1/1
$args{'decl'} || []
$args{'decl'}
Truth table100%2/2
A
A= $args{'decl'}
| |||||||||||||||||||||||||||||
| 152 | 5 | ▶ | my @stmt = @{ $args{stmt} || [] }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args{'stmt'} || []
MC/DC100%1/1
$args{'stmt'} || []
$args{'stmt'}
Truth table100%2/2
A
A= $args{'stmt'}
| |||||||||||||||||||||||||||||
| 153 | 5 | ▶ | my %eval = %{ $args{eval} || {} }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'eval'} || {}
MC/DC0%0/1
$args{'eval'} || {}
$args{'eval'}
Truth table50%1/2
A
A= $args{'eval'}
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 5 | $code =~ s/##HEADERS##/$headers/; | |||||||||||||||||||||||||||
| 156 | 5 | $code =~ s/##DECL##/join "\n", @decl/e; | |||||||||||||||||||||||||||
| 157 | 5 | $code =~ s/##STMT##/join "\n", @stmt/e; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 5 | my $eval = ''; | |||||||||||||||||||||||||||
| 160 | 5 | my $i=0; | |||||||||||||||||||||||||||
| 161 | 5 | my %map; | |||||||||||||||||||||||||||
| 162 | 5 | foreach my $key (sort keys %eval) | |||||||||||||||||||||||||||
| 163 | { | ||||||||||||||||||||||||||||
| 164 | 9 | $i++; | |||||||||||||||||||||||||||
| 165 | 9 | $map{$key} = "eval$i"; | |||||||||||||||||||||||||||
| 166 | 9 | my($format,$expression) = @{ $eval{$key} }; | |||||||||||||||||||||||||||
| 167 | 9 | $eval .= " printf(\"eval$i=<<<$format>>>\\n\", $expression);\n"; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 5 | $code =~ s/##EVAL##/$eval/; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 5 | 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 | export => ['dlmain'], | |||||||||||||||||||||||||||
| 179 | ); | ||||||||||||||||||||||||||||
| 180 | $build->source( | ||||||||||||||||||||||||||||
| 181 | FFI::Build::File::C->new( | ||||||||||||||||||||||||||||
| 182 | \$code, | ||||||||||||||||||||||||||||
| 183 | dir => $self->{dir}, | ||||||||||||||||||||||||||||
| 184 | 5 | build => $build, | |||||||||||||||||||||||||||
| 185 | ), | ||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 5 | my $lib = do { | |||||||||||||||||||||||||||
| 189 | 5 | ▶ | my($out, $lib, $error) = capture_merged { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 190 | 5 | my $lib = eval { | |||||||||||||||||||||||||||
| 191 | 5 | $build->build; | |||||||||||||||||||||||||||
| 192 | }; | ||||||||||||||||||||||||||||
| 193 | 5 | ($lib, $@); | |||||||||||||||||||||||||||
| 194 | 5 | }; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 5 | $self->log_code($code); | |||||||||||||||||||||||||||
| 197 | 5 | $self->log("[build]"); | |||||||||||||||||||||||||||
| 198 | 5 | $self->log($out); | |||||||||||||||||||||||||||
| 199 | 5 | ▶ | if($error) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||
| 201 | 0 | $self->log("exception: $error"); | |||||||||||||||||||||||||||
| 202 | 0 | return; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | elsif(!$lib) | ||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||
| 206 | 0 | $self->log("failed"); | |||||||||||||||||||||||||||
| 207 | 0 | return; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | 5 | $lib; | |||||||||||||||||||||||||||
| 210 | }; | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 5 | my $result = $self->_runner->run($lib->path); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 5 | $self->log("[stdout]"); | |||||||||||||||||||||||||||
| 215 | 5 | $self->log($result->stdout); | |||||||||||||||||||||||||||
| 216 | 5 | $self->log("[stderr]"); | |||||||||||||||||||||||||||
| 217 | 5 | $self->log($result->stderr); | |||||||||||||||||||||||||||
| 218 | 5 | $self->log("rv = @{[ $result->rv ]}"); | |||||||||||||||||||||||||||
| 219 | 0 | ▶ | $self->log("sig = @{[ $result->signal ]}") if $result->signal; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 5 | ▶ | if($result->pass) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||
| 223 | 5 | foreach my $key (sort keys %eval) | |||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||
| 225 | 9 | my $eval = $map{$key}; | |||||||||||||||||||||||||||
| 226 | 9 | ▶ | if($result->stdout =~ /$eval=<<<(.*?)>>>/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||
| 228 | 9 | my $value = $1; | |||||||||||||||||||||||||||
| 229 | 9 | my @key = split /\./, $key; | |||||||||||||||||||||||||||
| 230 | 9 | $self->set(@key, $value); | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | 5 | return 1; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | else | ||||||||||||||||||||||||||||
| 236 | { | ||||||||||||||||||||||||||||
| 237 | 0 | return; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | sub check | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 244 | 0 | my($self, $name, $code) = @_; | |||||||||||||||||||||||||||
| 245 | 0 | ▶ | if($self->check_eval(_template => $code)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | { | ||||||||||||||||||||||||||||
| 247 | 0 | $self->set('probe', $name, 1); | |||||||||||||||||||||||||||
| 248 | 0 | return 1; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | else | ||||||||||||||||||||||||||||
| 251 | { | ||||||||||||||||||||||||||||
| 252 | 0 | $self->set('probe', $name, 0); | |||||||||||||||||||||||||||
| 253 | 0 | return; | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | sub check_type_int | ||||||||||||||||||||||||||||
| 259 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_type_int: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 260 | 1 | my($self, $type) = @_; | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 1 | $self->check_header('stddef.h'); | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 1 | 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 | ▶ | return unless $ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 1 | my $size = $self->data->{type}->{$type}->{size}; | |||||||||||||||||||||||||||
| 279 | 1 | my $sign = $self->data->{type}->{$type}->{sign}; | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 1 | ▶ | sprintf("%sint%d", $sign eq 'signed' ? 's' : 'u', $size*8); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | sub check_type_enum | ||||||||||||||||||||||||||||
| 286 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_type_enum: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 287 | 0 | my($self) = @_; | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | $self->check_header('stddef.h'); | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 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 | ▶ | return unless $ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 0 | my $size = $self->data->{type}->{enum}->{size}; | |||||||||||||||||||||||||||
| 307 | 0 | my $sign = $self->data->{type}->{enum}->{sign}; | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | sprintf("%sint%d", $sign eq 'signed' ? 's' : 'u', $size*8); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | sub check_type_signed_enum | ||||||||||||||||||||||||||||
| 314 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_type_signed_enum: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 315 | 0 | my($self) = @_; | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 0 | $self->check_header('stddef.h'); | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 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 | ▶ | return unless $ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | my $size = $self->data->{type}->{senum}->{size}; | |||||||||||||||||||||||||||
| 335 | 0 | my $sign = $self->data->{type}->{senum}->{sign}; | |||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sprintf("%sint%d", $sign eq 'signed' ? 's' : 'u', $size*8); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | sub check_type_float | ||||||||||||||||||||||||||||
| 342 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_type_float: called CC=7 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||
| 343 | 1 | my($self, $type) = @_; | |||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 1 | $self->check_header('stddef.h'); | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 1 | 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 | ▶ | return unless $ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 1 | my $size = $self->data->{type}->{$type}->{size}; | |||||||||||||||||||||||||||
| 360 | 1 | my $complex = !!($type =~ /complex/); | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 1 | ▶ | if($complex) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 0 | $size /= 2; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 1 | my $t; | |||||||||||||||||||||||||||
| 367 | 1 | ▶ | if($size == 4) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 368 | 1 | { $t = 'float' } | |||||||||||||||||||||||||||
| 369 | elsif($size == 8) | ||||||||||||||||||||||||||||
| 370 | 0 | { $t = 'double' } | |||||||||||||||||||||||||||
| 371 | elsif($size > 9) | ||||||||||||||||||||||||||||
| 372 | 0 | { $t = 'longdouble' } | |||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 1 | ▶ | $t = "complex_$t" if $complex; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 1 | $t; | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | sub check_type_pointer | ||||||||||||||||||||||||||||
| 381 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_type_pointer: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 382 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 1 | $self->check_header('stddef.h'); | |||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 1 | 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 | ▶ | return unless $ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 397 | 1 | 'pointer'; | |||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | sub _set | ||||||||||||||||||||||||||||
| 401 | 33 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_set: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 402 | 33 | my($data, $value, @key) = @_; | |||||||||||||||||||||||||||
| 403 | 33 | my $key = shift @key; | |||||||||||||||||||||||||||
| 404 | 33 | ▶ | if(@key > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | { | ||||||||||||||||||||||||||||
| 406 | 21 | ▶ | _set($data->{$key} ||= {}, $value, @key); | ||||||||||||||||||||||||||
|
Condition100%2/2
$data->{$key} ||= {}
MC/DC100%1/1
$data->{$key} ||= {}
$data->{$key}
Truth table100%2/2
A
A= $data->{$key}
| |||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | else | ||||||||||||||||||||||||||||
| 409 | { | ||||||||||||||||||||||||||||
| 410 | 12 | $data->{$key} = $value; | |||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | sub set | ||||||||||||||||||||||||||||
| 416 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||
| 417 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 418 | 12 | my $value = pop; | |||||||||||||||||||||||||||
| 419 | 12 | my @key = @_; | |||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 12 | my $print_value = $value; | |||||||||||||||||||||||||||
| 422 | 12 | ▶ | if(ref $print_value) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | { | ||||||||||||||||||||||||||||
| 424 | 0 | my $d = Data::Dumper->new([$value], [qw($value)]); | |||||||||||||||||||||||||||
| 425 | 0 | $d->Indent(0); | |||||||||||||||||||||||||||
| 426 | 0 | $d->Terse(1); | |||||||||||||||||||||||||||
| 427 | 0 | $print_value = $d->Dump; | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 12 | ▶ | my $key = join ".", map { /\./ ? "\"$_\"" : $_ } @key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | 12 | print "PR $key=$print_value\n"; | |||||||||||||||||||||||||||
| 432 | 12 | $self->log("$key=$print_value"); | |||||||||||||||||||||||||||
| 433 | 12 | _set($self->{data}, $value, @key); | |||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | sub save | ||||||||||||||||||||||||||||
| 438 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
save: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 439 | 4 | my($self) = @_; | |||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 4 | my $dir = dirname($self->{data_filename}); | |||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 4 | 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 | ▶ | mkpath( $dir, 0, oct(755) ) unless -d $dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | 4 | my $fh; | |||||||||||||||||||||||||||
| 453 | 0 | ▶ | open($fh, '>', $self->{data_filename}) || die "error writing @{[ $self->{data_filename} ]}"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 454 | 4 | print $fh 'do { my '; | |||||||||||||||||||||||||||
| 455 | 4 | print $fh $dd; | |||||||||||||||||||||||||||
| 456 | 4 | print $fh '$x;}'; | |||||||||||||||||||||||||||
| 457 | 4 | close $fh; | |||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 18 | ▶ | sub data { shift->{data} } | ||||||||||||||||||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | sub log | ||||||||||||||||||||||||||||
| 465 | 132 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 466 | 132 | my($self, $string) = @_; | |||||||||||||||||||||||||||
| 467 | 132 | my $fh = $self->{log}; | |||||||||||||||||||||||||||
| 468 | 132 | chomp $string; | |||||||||||||||||||||||||||
| 469 | 132 | print $fh $string, "\n"; | |||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | sub log_code | ||||||||||||||||||||||||||||
| 474 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
log_code: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 475 | 8 | my($self, $code) = @_; | |||||||||||||||||||||||||||
| 476 | 8 | my @code = split /\n/, $code; | |||||||||||||||||||||||||||
| 477 | 8 | chomp for @code; | |||||||||||||||||||||||||||
| 478 | 8 | $self->log("code: $_") for @code; | |||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | sub DESTROY | ||||||||||||||||||||||||||||
| 482 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 483 | 3 | my($self) = @_; | |||||||||||||||||||||||||||
| 484 | 3 | $self->save; | |||||||||||||||||||||||||||
| 485 | 3 | my $fh = $self->{log}; | |||||||||||||||||||||||||||
| 486 | 3 | ▶ | return unless defined $fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 487 | 3 | close $fh; | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 3 | my $template; | |||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | sub template | ||||||||||||||||||||||||||||
| 494 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
template: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 495 | 5 | ▶ | unless(defined $template) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||
| 497 | 1 | local $/; | |||||||||||||||||||||||||||
| 498 | 1 | $template = <DATA>; | |||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 5 | $template; | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 3 | 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.12 | ||||||||||||||||||||||||||||
| 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<FFI::Platypus> 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<dlmain> 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<check_eval> and other | ||||||||||||||||||||||||||||
| 645 | C<check_> methods. | ||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | Author: Graham Ollis E<lt>plicease@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 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 | Lukas Mai (MAUKE) | ||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||
| 695 | This software is copyright (c) 2015-2022 by Graham Ollis. | ||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||
| 697 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 698 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||
| 700 | =cut | ||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||
| 702 | __DATA__ | ||||||||||||||||||||||||||||