line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::C; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
445667
|
use strict; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
56
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
45
|
|
5
|
2
|
|
|
2
|
|
54
|
use 5.008001; |
|
2
|
|
|
|
|
7
|
|
6
|
2
|
|
|
2
|
|
9
|
use Carp (); |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
39
|
|
7
|
2
|
|
|
2
|
|
1044
|
use Ref::Util qw( is_ref is_plain_arrayref is_plain_hashref ); |
|
2
|
|
|
|
|
3325
|
|
|
2
|
|
|
|
|
2012
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: C data types for FFI |
10
|
|
|
|
|
|
|
our $VERSION = '0.14'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %ffi; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _ffi_get |
16
|
|
|
|
|
|
|
{ |
17
|
14
|
|
|
14
|
|
28
|
my($filename) = @_; |
18
|
14
|
|
66
|
|
|
93
|
$ffi{$filename} ||= do { |
19
|
2
|
|
|
|
|
738
|
require FFI::Platypus; |
20
|
2
|
|
|
|
|
7908
|
FFI::Platypus->new( api => 1 ); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub ffi |
25
|
|
|
|
|
|
|
{ |
26
|
4
|
|
|
4
|
1
|
14410
|
my($class, $new) = @_; |
27
|
4
|
|
|
|
|
13
|
my(undef, $filename) = caller; |
28
|
|
|
|
|
|
|
|
29
|
4
|
100
|
|
|
|
14
|
if($new) |
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
Carp::croak("Already have an FFI::Platypus instance for $filename") |
32
|
2
|
100
|
|
|
|
177
|
if defined $ffi{$filename}; |
33
|
1
|
|
|
|
|
8
|
return $ffi{$filename} = $new; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
8
|
_ffi_get($filename); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our $def_class; |
41
|
|
|
|
|
|
|
sub _gen |
42
|
|
|
|
|
|
|
{ |
43
|
10
|
|
|
10
|
|
18
|
shift; |
44
|
10
|
|
|
|
|
37
|
my($class, $filename) = caller; |
45
|
|
|
|
|
|
|
|
46
|
10
|
|
|
|
|
17
|
my($name, $members); |
47
|
|
|
|
|
|
|
|
48
|
10
|
50
|
|
|
|
31
|
my %extra = is_plain_hashref $_[-1] ? %{ pop() } : (); |
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
|
50
|
10
|
100
|
66
|
|
|
75
|
if(@_ == 2 && !is_ref $_[0] && is_plain_arrayref $_[1]) |
|
|
50
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
51
|
|
|
|
|
|
|
{ |
52
|
4
|
|
|
|
|
11
|
($name, $members) = @_; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif(@_ == 1 && is_plain_arrayref $_[0]) |
55
|
|
|
|
|
|
|
{ |
56
|
6
|
|
|
|
|
36
|
$name = lcfirst [split /::/, $class]->[-1]; |
57
|
6
|
|
|
|
|
41
|
$name =~ s/([A-Z]+)/'_' . lc($1)/ge; |
|
7
|
|
|
|
|
38
|
|
58
|
6
|
|
|
|
|
15
|
$name .= "_t"; |
59
|
6
|
|
|
|
|
15
|
($members) = @_; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
|
|
|
|
0
|
my($method) = map { lc $_ } $def_class =~ /::([A-Za-z]+)Def$/; |
|
0
|
|
|
|
|
0
|
|
64
|
0
|
|
|
|
|
0
|
Carp::croak("usage: FFI::C->$method([\$name], \\\@members)"); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
10
|
|
|
|
|
24
|
$def_class->new( |
68
|
|
|
|
|
|
|
_ffi_get($filename), |
69
|
|
|
|
|
|
|
%extra, |
70
|
|
|
|
|
|
|
name => $name, |
71
|
|
|
|
|
|
|
class => $class, |
72
|
|
|
|
|
|
|
members => $members, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub struct |
77
|
|
|
|
|
|
|
{ |
78
|
6
|
|
|
6
|
1
|
3314
|
require FFI::C::StructDef; |
79
|
6
|
|
|
|
|
16
|
$def_class = 'FFI::C::StructDef'; |
80
|
6
|
|
|
|
|
24
|
goto &_gen; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub union |
85
|
|
|
|
|
|
|
{ |
86
|
2
|
|
|
2
|
1
|
443
|
require FFI::C::UnionDef; |
87
|
2
|
|
|
|
|
5
|
$def_class = 'FFI::C::UnionDef'; |
88
|
2
|
|
|
|
|
6
|
goto &_gen; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub array |
93
|
|
|
|
|
|
|
{ |
94
|
2
|
|
|
2
|
1
|
505
|
require FFI::C::ArrayDef; |
95
|
2
|
|
|
|
|
7
|
$def_class = 'FFI::C::ArrayDef'; |
96
|
2
|
|
|
|
|
8
|
goto &_gen; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub enum |
101
|
|
|
|
|
|
|
{ |
102
|
2
|
|
|
2
|
1
|
7210
|
(undef) = shift; |
103
|
2
|
50
|
33
|
|
|
18
|
my $name = defined $_[0] && !is_ref $_[0] ? shift : undef; |
104
|
2
|
50
|
33
|
|
|
11
|
my @values = defined $_[0] && is_plain_arrayref $_[0] ? @{shift()} : (); |
|
2
|
|
|
|
|
10
|
|
105
|
2
|
100
|
66
|
|
|
25
|
my %config = defined $_[0] && is_plain_hashref $_[0] ? %{shift()} : (); |
|
1
|
|
|
|
|
6
|
|
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
9
|
my($class, $filename) = caller; |
108
|
|
|
|
|
|
|
|
109
|
2
|
50
|
|
|
|
5
|
unless(defined $name) |
110
|
|
|
|
|
|
|
{ |
111
|
2
|
|
|
|
|
11
|
$name = lcfirst [split /::/, $class]->[-1]; |
112
|
2
|
|
|
|
|
24
|
$name =~ s/([A-Z]+)/'_' . lc($1)/ge; |
|
2
|
|
|
|
|
14
|
|
113
|
2
|
|
|
|
|
11
|
$name .= "_t"; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $ffi = _ffi_get($filename), |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
33
|
|
|
4
|
$config{package} ||= $class; |
119
|
2
|
|
|
|
|
4
|
my @maps; |
120
|
2
|
|
|
|
|
6
|
$config{maps} = \@maps; |
121
|
2
|
|
100
|
|
|
9
|
my $rev = $config{rev} ||= 'str'; |
122
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
8
|
$ffi->load_custom_type('::Enum', $name, \%config, @values); |
124
|
|
|
|
|
|
|
|
125
|
2
|
|
|
|
|
2609
|
my($str_lookup, $int_lookup, $type) = @maps; |
126
|
|
|
|
|
|
|
|
127
|
2
|
|
|
|
|
517
|
require FFI::C::Def; |
128
|
2
|
|
|
|
|
15
|
$ffi->def('FFI::C::EnumDef', $name, |
129
|
|
|
|
|
|
|
FFI::C::EnumDef->new( |
130
|
|
|
|
|
|
|
str_lookup => $str_lookup, |
131
|
|
|
|
|
|
|
int_lookup => $int_lookup, |
132
|
|
|
|
|
|
|
type => $type, |
133
|
|
|
|
|
|
|
rev => $rev, |
134
|
|
|
|
|
|
|
) |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |