line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::Platypus::Memory; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
16005
|
use strict; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
258
|
|
4
|
10
|
|
|
10
|
|
40
|
use warnings; |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
197
|
|
5
|
10
|
|
|
10
|
|
133
|
use 5.008004; |
|
10
|
|
|
|
|
28
|
|
6
|
10
|
|
|
10
|
|
43
|
use FFI::Platypus; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
214
|
|
7
|
10
|
|
|
10
|
|
40
|
use Exporter qw( import ); |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
3805
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Memory functions for FFI |
10
|
|
|
|
|
|
|
our $VERSION = '2.07'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw( malloc free calloc realloc memcpy memset strdup strndup strcpy ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $ffi = FFI::Platypus->new( api => 2 ); |
16
|
|
|
|
|
|
|
$ffi->lib(undef); |
17
|
|
|
|
|
|
|
$ffi->bundle; |
18
|
1
|
|
|
1
|
|
76
|
sub _ffi { $ffi } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$ffi->attach(malloc => ['size_t'] => 'opaque' => '$'); |
21
|
|
|
|
|
|
|
$ffi->attach(free => ['opaque'] => 'void' => '$'); |
22
|
|
|
|
|
|
|
$ffi->attach(calloc => ['size_t', 'size_t'] => 'opaque' => '$$'); |
23
|
|
|
|
|
|
|
$ffi->attach(realloc => ['opaque', 'size_t'] => 'opaque' => '$$'); |
24
|
|
|
|
|
|
|
$ffi->attach(memcpy => ['opaque', 'opaque', 'size_t'] => 'opaque' => '$$$'); |
25
|
|
|
|
|
|
|
$ffi->attach(memset => ['opaque', 'int', 'size_t'] => 'opaque' => '$$$'); |
26
|
|
|
|
|
|
|
$ffi->attach(strcpy => ['opaque', 'string'] => 'opaque' => '$$'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $_strdup_impl = 'not-loaded'; |
29
|
2
|
|
|
2
|
|
2374
|
sub _strdup_impl { $_strdup_impl } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
eval { |
32
|
|
|
|
|
|
|
die "do not use c impl" if ($ENV{FFI_PLATYPUS_MEMORY_STRDUP_IMPL}||'libc') eq 'ffi'; |
33
|
|
|
|
|
|
|
$ffi->attach(strdup => ['string'] => 'opaque' => '$'); |
34
|
|
|
|
|
|
|
$_strdup_impl = 'libc'; |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
if($@ && $^O eq 'MSWin32') |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
eval { |
39
|
|
|
|
|
|
|
die "do not use c impl" if ($ENV{FFI_PLATYPUS_MEMORY_STRDUP_IMPL}||'libc') eq 'ffi'; |
40
|
|
|
|
|
|
|
$ffi->attach([ _strdup => 'strdup' ] => ['string'] => 'opaque' => '$'); |
41
|
|
|
|
|
|
|
$_strdup_impl = 'libc'; |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
if($@) |
45
|
|
|
|
|
|
|
{ |
46
|
|
|
|
|
|
|
warn "using bundled strdup"; |
47
|
|
|
|
|
|
|
$_strdup_impl = 'ffi'; |
48
|
|
|
|
|
|
|
$ffi->attach([ ffi_platypus_memory__strdup => 'strdup' ] => ['string'] => 'opaque' => '$'); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $_strndup_impl = 'not-loaded'; |
52
|
2
|
|
|
2
|
|
2255
|
sub _strndup_impl { $_strndup_impl } |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
eval { |
55
|
|
|
|
|
|
|
die "do not use c impl" if ($ENV{FFI_PLATYPUS_MEMORY_STRDUP_IMPL}||'libc') eq 'ffi'; |
56
|
|
|
|
|
|
|
$ffi->attach(strndup => ['string','size_t'] => 'opaque' => '$$'); |
57
|
|
|
|
|
|
|
$_strndup_impl = 'libc'; |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
if($@) |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
$_strndup_impl = 'ffi'; |
62
|
|
|
|
|
|
|
$ffi->attach([ ffi_platypus_memory__strndup => 'strndup' ] => ['string','size_t'] => 'opaque' => '$$'); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# used internally by FFI::Platypus::Type::WideString, may go away. |
66
|
|
|
|
|
|
|
eval { $ffi->attach( [ wcslen => '_wcslen' ] => [ 'opaque' ] => 'size_t' => '$' ) }; |
67
|
|
|
|
|
|
|
eval { $ffi->attach( [ wcsnlen => '_wcsnlen' ] => [ 'string', 'size_t' ] => 'size_t' => '$$' ) }; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |