line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::Platypus::Record::StringArray; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
189821
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
47
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
39
|
|
5
|
2
|
|
|
2
|
|
27
|
use 5.008001; |
|
2
|
|
|
|
|
6
|
|
6
|
2
|
|
|
2
|
|
782
|
use FFI::Platypus::Memory qw( strdup calloc free ); |
|
2
|
|
|
|
|
25305
|
|
|
2
|
|
|
|
|
157
|
|
7
|
2
|
|
|
2
|
|
16
|
use constant _ptr_size => FFI::Platypus->new->sizeof('opaque'); |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
12
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Array of strings for your FFI record |
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $ffi; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
1
|
5801
|
my $class = shift; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
33
|
|
|
8
|
$ffi ||= FFI::Platypus->new( lib => [undef] ); |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
925
|
my $size = @_; |
22
|
1
|
100
|
|
|
|
3
|
my $array = [map { defined $_ ? strdup($_) : undef } @_, undef]; |
|
5
|
|
|
|
|
20
|
|
23
|
1
|
|
|
|
|
5
|
my $opaque = calloc($size, _ptr_size); |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
9
|
$ffi->function( |
26
|
|
|
|
|
|
|
memcpy => [ 'opaque', "opaque[$size]", 'size_t' ] => 'opaque', |
27
|
|
|
|
|
|
|
)->call($opaque, $array, $size * _ptr_size); |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
404
|
my $self = bless { |
30
|
|
|
|
|
|
|
array => $array, |
31
|
|
|
|
|
|
|
opaque => $opaque, |
32
|
|
|
|
|
|
|
}, $class; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub opaque |
37
|
|
|
|
|
|
|
{ |
38
|
3
|
|
|
3
|
1
|
1335
|
my($self) = @_; |
39
|
3
|
|
|
|
|
17
|
$self->{opaque}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub size |
44
|
|
|
|
|
|
|
{ |
45
|
1
|
|
|
1
|
1
|
449
|
my($self) = @_; |
46
|
1
|
|
|
|
|
2
|
scalar @{ $self->{array} } - 1; |
|
1
|
|
|
|
|
8
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub element |
51
|
|
|
|
|
|
|
{ |
52
|
4
|
|
|
4
|
1
|
1207
|
my($self, $index) = @_; |
53
|
4
|
|
|
|
|
16
|
$ffi->cast( 'opaque' => 'string', $self->{array}->[$index] ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub DESTROY |
57
|
|
|
|
|
|
|
{ |
58
|
1
|
|
|
1
|
|
952
|
my($self) = @_; |
59
|
1
|
|
|
|
|
3
|
free($_) for grep { defined $_ } @{ $self->{array} }; |
|
5
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
6
|
|
60
|
1
|
|
|
|
|
6
|
free($self->{opaque}); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |