line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::Library; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
787
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
45
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
43
|
|
5
|
2
|
|
|
2
|
|
7
|
use Carp qw( croak ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
68
|
|
6
|
2
|
|
|
2
|
|
6
|
use FFI; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
692
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.12'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
if ($^O eq 'MSWin32') { |
11
|
|
|
|
|
|
|
require Win32; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
else { |
14
|
|
|
|
|
|
|
require DynaLoader; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
19
|
0
|
|
|
|
|
|
my $libname = shift; |
20
|
0
|
0
|
|
|
|
|
scalar(@_) <= 1 |
21
|
|
|
|
|
|
|
or croak 'Usage: $lib = new FFI::Library($filename [, $flags])'; |
22
|
0
|
|
|
|
|
|
my $lib; |
23
|
0
|
0
|
|
|
|
|
if ($^O eq 'MSWin32') { |
24
|
0
|
0
|
|
|
|
|
$lib = Win32::LoadLibrary($libname) or return undef; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
0
|
|
|
|
|
|
my $so = $libname; |
28
|
0
|
0
|
0
|
|
|
|
-e $so or $so = DynaLoader::dl_findfile($libname) || $libname; |
29
|
0
|
0
|
|
|
|
|
$lib = DynaLoader::dl_load_file($so, @_) |
30
|
|
|
|
|
|
|
or return undef; |
31
|
|
|
|
|
|
|
} |
32
|
0
|
|
|
|
|
|
bless \$lib, $class; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub DESTROY { |
36
|
0
|
0
|
|
0
|
|
|
if ($^O eq 'MSWin32') { |
37
|
0
|
|
|
|
|
|
Win32::FreeLibrary(${$_[0]}); |
|
0
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
0
|
0
|
|
|
|
|
DynaLoader::dl_free_file(${$_[0]}) |
|
0
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
if defined (&DynaLoader::dl_free_file); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub function { |
46
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
47
|
0
|
|
|
|
|
|
my $name = shift; |
48
|
0
|
|
|
|
|
|
my $sig = shift; |
49
|
0
|
|
|
|
|
|
my $addr; |
50
|
0
|
0
|
|
|
|
|
if ($^O eq 'MSWin32') { |
51
|
0
|
|
|
|
|
|
$addr = Win32::GetProcAddress(${$self}, $name); |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
|
$addr = DynaLoader::dl_find_symbol(${$self}, $name); |
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
56
|
0
|
0
|
|
|
|
|
croak "Unknown function $name" unless defined $addr; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
0
|
|
|
sub { FFI::call($addr, $sig, @_); } |
59
|
0
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
__END__ |