line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::Library; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
103663
|
use strict; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
90
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
72
|
|
5
|
3
|
|
|
3
|
|
14
|
use Carp (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
173
|
|
6
|
3
|
|
|
3
|
|
16
|
use constant _is_win => $^O =~ /^(MSWin32|cygwin|msys2?)$/; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2213
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Perl Access to Dynamically Loaded Libraries |
9
|
|
|
|
|
|
|
our $VERSION = '1.15'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
12
|
|
|
|
|
|
|
{ |
13
|
8
|
|
|
8
|
1
|
38609
|
my($class, $libname, $flags) = @_; |
14
|
8
|
100
|
|
|
|
215
|
Carp::croak('Usage: $lib = FFI::Library->new($filename [, $flags ])') |
15
|
|
|
|
|
|
|
unless @_ <= 3; |
16
|
|
|
|
|
|
|
|
17
|
7
|
|
50
|
|
|
64
|
$flags ||= 0; |
18
|
|
|
|
|
|
|
|
19
|
7
|
100
|
66
|
|
|
132
|
if(! defined $libname) |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
20
|
|
|
|
|
|
|
{ |
21
|
1
|
|
|
|
|
6
|
return bless { |
22
|
|
|
|
|
|
|
impl => 'null', |
23
|
|
|
|
|
|
|
}, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif(ref $libname and int($libname) == int(\$0)) |
26
|
|
|
|
|
|
|
{ |
27
|
2
|
|
|
|
|
9
|
return $class->_dl_impl(undef, undef); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
elsif(_is_win) |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
|
|
0
|
return $class->_dl_impl($libname, undef); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif(-e $libname) |
34
|
|
|
|
|
|
|
{ |
35
|
3
|
50
|
|
|
|
22
|
return $class->_dl_impl( |
36
|
|
|
|
|
|
|
$libname, |
37
|
|
|
|
|
|
|
$flags == 0x01 ? FFI::Platypus::Lang::DL::RTLD_GLOBAL() : undef, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else |
41
|
|
|
|
|
|
|
{ |
42
|
1
|
|
|
|
|
11
|
require DynaLoader; |
43
|
1
|
|
33
|
|
|
402
|
my $so = DynaLoader::dl_findfile($libname) || $libname; |
44
|
1
|
|
50
|
|
|
267
|
my $handle = DynaLoader::dl_load_file($so, $flags || 0); |
45
|
1
|
50
|
|
|
|
10
|
return unless $handle; |
46
|
0
|
|
|
|
|
0
|
return bless { |
47
|
|
|
|
|
|
|
impl => 'dynaloader', |
48
|
|
|
|
|
|
|
handle => $handle, |
49
|
|
|
|
|
|
|
}, $class; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _dl_impl |
54
|
|
|
|
|
|
|
{ |
55
|
5
|
|
|
5
|
|
16
|
my($class, $path, $flags) = @_; |
56
|
5
|
|
|
|
|
1139
|
require FFI::Platypus::DL; |
57
|
5
|
50
|
|
|
|
7904
|
$flags = FFI::Platypus::DL::RTLD_PLATYPUS_DEFAULT() |
58
|
|
|
|
|
|
|
unless defined $flags; |
59
|
5
|
|
|
|
|
366
|
my $handle = FFI::Platypus::DL::dlopen($path, $flags); |
60
|
5
|
50
|
|
|
|
22
|
return unless defined $handle; |
61
|
5
|
|
|
|
|
41
|
bless { impl => 'dl', handle => $handle }, $class; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub address |
65
|
|
|
|
|
|
|
{ |
66
|
11
|
|
|
11
|
1
|
1436
|
my($self, $name) = @_; |
67
|
|
|
|
|
|
|
|
68
|
11
|
50
|
|
|
|
41
|
if($self->{impl} eq 'dl') |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
69
|
|
|
|
|
|
|
{ |
70
|
11
|
|
|
|
|
92
|
return FFI::Platypus::DL::dlsym($self->{handle}, $name); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif($self->{impl} eq 'dynaloader') |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
|
|
0
|
return DynaLoader::dl_find_symbol($self->{handle}, $name); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
elsif($self->{impl} eq 'null') |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
0
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
|
|
0
|
Carp::croak("Unknown implementaton: @{[ $self->{impl} ]}"); |
|
0
|
|
|
|
|
0
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub function |
87
|
|
|
|
|
|
|
{ |
88
|
6
|
|
|
6
|
1
|
1883
|
my($self, $name, $sig) = @_; |
89
|
|
|
|
|
|
|
|
90
|
6
|
|
|
|
|
18
|
my $addr = $self->address($name); |
91
|
|
|
|
|
|
|
|
92
|
6
|
100
|
|
|
|
264
|
Carp::croak("Unknown function $name") |
93
|
|
|
|
|
|
|
unless defined $addr; |
94
|
|
|
|
|
|
|
|
95
|
4
|
|
|
|
|
524
|
require FFI; |
96
|
4
|
|
|
5
|
|
24
|
sub { FFI::call($addr, $sig, @_) }; |
|
5
|
|
|
|
|
2339
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub DESTROY |
100
|
|
|
|
|
|
|
{ |
101
|
6
|
|
|
6
|
|
9053
|
my($self) = @_; |
102
|
|
|
|
|
|
|
|
103
|
6
|
100
|
|
|
|
31
|
if($self->{impl} eq 'dl') |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
104
|
|
|
|
|
|
|
{ |
105
|
5
|
|
|
|
|
163
|
FFI::Platypus::DL::dlclose($self->{handle}); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
elsif($self->{impl} eq 'dynaloader') |
108
|
|
|
|
|
|
|
{ |
109
|
|
|
|
|
|
|
DynaLoader::dl_free_file($self->{handle}) |
110
|
0
|
0
|
|
|
|
|
if defined &DynaLoader::dl_free_file; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
elsif($self->{impl} eq 'null') |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
# do nothing |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else |
117
|
|
|
|
|
|
|
{ |
118
|
0
|
|
|
|
|
|
Carp::croak("Unknown implementaton: @{[ $self->{impl} ]}"); |
|
0
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |