line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::Platypus::Type::StringArray; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
51387
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
90
|
|
4
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
210
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Platypus custom type for arrays of strings |
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
50
|
33
|
|
|
1102
|
use constant _incantation => |
11
|
|
|
|
|
|
|
$^O eq 'MSWin32' && $Config::Config{archname} =~ /MSWin32-x64/ |
12
|
|
|
|
|
|
|
? 'Q' |
13
|
3
|
|
|
3
|
|
13
|
: 'L!'; |
|
3
|
|
|
|
|
4
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @stack; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub perl_to_native |
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
# this is the variable length version |
20
|
|
|
|
|
|
|
# and is actually simpler than the |
21
|
|
|
|
|
|
|
# fixed length version |
22
|
4
|
|
|
4
|
0
|
5827
|
my $count = scalar @{ $_[0] }; |
|
4
|
|
|
|
|
6
|
|
23
|
4
|
|
|
|
|
11
|
my $pointers = pack(('P' x $count)._incantation, @{ $_[0] }, 0); |
|
4
|
|
|
|
|
17
|
|
24
|
4
|
|
|
|
|
12
|
my $array_pointer = unpack _incantation, pack 'P', $pointers; |
25
|
4
|
|
|
|
|
9
|
push @stack, [ \$_[0], \$pointers ]; |
26
|
4
|
|
|
|
|
18
|
$array_pointer; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub perl_to_native_post |
30
|
|
|
|
|
|
|
{ |
31
|
16
|
|
|
16
|
0
|
13
|
pop @stack; |
32
|
16
|
|
|
|
|
80
|
(); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub ffi_custom_type_api_1 |
36
|
|
|
|
|
|
|
{ |
37
|
|
|
|
|
|
|
# arg0 = class |
38
|
|
|
|
|
|
|
# arg1 = FFI::Platypus instance |
39
|
|
|
|
|
|
|
# arg2 = array size |
40
|
|
|
|
|
|
|
# arg3 = default value |
41
|
3
|
|
|
3
|
0
|
124
|
my(undef, undef, $count, $default) = @_; |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
10
|
my $config = { |
44
|
|
|
|
|
|
|
native_type => 'opaque', |
45
|
|
|
|
|
|
|
perl_to_native => \&perl_to_native, |
46
|
|
|
|
|
|
|
perl_to_native_post => \&perl_to_native_post, |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
3
|
100
|
|
|
|
8
|
if(defined $count) |
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
$config->{perl_to_native} = sub { |
52
|
12
|
|
|
12
|
|
6934
|
my @list; |
53
|
12
|
|
|
|
|
15
|
my $incantation = ''; |
54
|
|
|
|
|
|
|
|
55
|
12
|
|
|
|
|
25
|
foreach my $i (0..($count-1)) |
56
|
|
|
|
|
|
|
{ |
57
|
60
|
|
|
|
|
58
|
my $item = $_[0]->[$i]; |
58
|
60
|
100
|
|
|
|
80
|
if(defined $item) |
|
|
100
|
|
|
|
|
|
59
|
|
|
|
|
|
|
{ |
60
|
48
|
|
|
|
|
46
|
push @list, $item; |
61
|
48
|
|
|
|
|
59
|
$incantation .= 'P'; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif(defined $default) |
64
|
|
|
|
|
|
|
{ |
65
|
6
|
|
|
|
|
6
|
push @list, $default; |
66
|
6
|
|
|
|
|
6
|
$incantation .= 'P'; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else |
69
|
|
|
|
|
|
|
{ |
70
|
6
|
|
|
|
|
5
|
push @list, 0; |
71
|
6
|
|
|
|
|
7
|
$incantation .= _incantation; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
12
|
|
|
|
|
13
|
push @list, 0; |
76
|
12
|
|
|
|
|
13
|
$incantation .= _incantation; |
77
|
12
|
|
|
|
|
39
|
my $pointers = pack $incantation, @list; |
78
|
12
|
|
|
|
|
24
|
my $array_pointer = unpack _incantation, pack 'P', $pointers; |
79
|
12
|
|
|
|
|
22
|
push @stack, [ \@list, $pointers ]; |
80
|
12
|
|
|
|
|
52
|
$array_pointer; |
81
|
2
|
|
|
|
|
7
|
}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
7
|
$config; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |