| 1 | package FFI::Platypus::Memory; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use FFI::Platypus; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Memory functions for FFI | ||||||||||||||||||||||||||||
| 10 | 10 | our $VERSION = '2.12'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 10 | our @EXPORT = qw( malloc free calloc realloc memcpy memset strdup strndup strcpy ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 10 | my $ffi = FFI::Platypus->new( api => 2 ); | |||||||||||||||||||||||||||
| 16 | 10 | $ffi->lib(undef); | |||||||||||||||||||||||||||
| 17 | 10 | $ffi->bundle; | |||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub _ffi { $ffi } | ||||||||||||||||||||||||||
|
Subroutine
_ffi: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 10 | $ffi->attach(malloc => ['size_t'] => 'opaque' => '$'); | |||||||||||||||||||||||||||
| 21 | 10 | $ffi->attach(free => ['opaque'] => 'void' => '$'); | |||||||||||||||||||||||||||
| 22 | 10 | $ffi->attach(calloc => ['size_t', 'size_t'] => 'opaque' => '$$'); | |||||||||||||||||||||||||||
| 23 | 10 | $ffi->attach(realloc => ['opaque', 'size_t'] => 'opaque' => '$$'); | |||||||||||||||||||||||||||
| 24 | 10 | $ffi->attach(memcpy => ['opaque', 'opaque', 'size_t'] => 'opaque' => '$$$'); | |||||||||||||||||||||||||||
| 25 | 10 | $ffi->attach(memset => ['opaque', 'int', 'size_t'] => 'opaque' => '$$$'); | |||||||||||||||||||||||||||
| 26 | 10 | $ffi->attach(strcpy => ['opaque', 'string'] => 'opaque' => '$$'); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 10 | my $_strdup_impl = 'not-loaded'; | |||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub _strdup_impl { $_strdup_impl } | ||||||||||||||||||||||||||
|
Subroutine
_strdup_impl: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 10 | eval { | |||||||||||||||||||||||||||
| 32 | 10 | ▶ | die "do not use c impl" if ($ENV{FFI_PLATYPUS_MEMORY_STRDUP_IMPL}||'libc') eq 'ffi'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'} || 'libc'
MC/DC0%0/1
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'} || 'libc'
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'}
Truth table50%1/2
A
A= $ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'}
| |||||||||||||||||||||||||||||
| 33 | 10 | $ffi->attach(strdup => ['string'] => 'opaque' => '$'); | |||||||||||||||||||||||||||
| 34 | 10 | $_strdup_impl = 'libc'; | |||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | 10 | ▶ | if($@ && $^O eq 'MSWin32') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ and $^O eq "MSWin32"
MC/DC0%0/2
$@ and $^O eq "MSWin32"
$@
$^O eq "MSWin32"
Truth table33%1/3
A and B
A= $@B= $^O eq "MSWin32"
| |||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | 0 | eval { | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | die "do not use c impl" if ($ENV{FFI_PLATYPUS_MEMORY_STRDUP_IMPL}||'libc') eq 'ffi'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'} || 'libc'
MC/DC0%0/1
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'} || 'libc'
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'}
Truth table0%0/2
A
A= $ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'}
| |||||||||||||||||||||||||||||
| 40 | 0 | $ffi->attach([ _strdup => 'strdup' ] => ['string'] => 'opaque' => '$'); | |||||||||||||||||||||||||||
| 41 | 0 | $_strdup_impl = 'libc'; | |||||||||||||||||||||||||||
| 42 | }; | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 10 | ▶ | if($@) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | 0 | warn "using bundled strdup"; | |||||||||||||||||||||||||||
| 47 | 0 | $_strdup_impl = 'ffi'; | |||||||||||||||||||||||||||
| 48 | 0 | $ffi->attach([ ffi_platypus_memory__strdup => 'strdup' ] => ['string'] => 'opaque' => '$'); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 10 | my $_strndup_impl = 'not-loaded'; | |||||||||||||||||||||||||||
| 52 | 2 | ▶ | sub _strndup_impl { $_strndup_impl } | ||||||||||||||||||||||||||
|
Subroutine
_strndup_impl: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 10 | eval { | |||||||||||||||||||||||||||
| 55 | 10 | ▶ | die "do not use c impl" if ($ENV{FFI_PLATYPUS_MEMORY_STRDUP_IMPL}||'libc') eq 'ffi'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'} || 'libc'
MC/DC0%0/1
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'} || 'libc'
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'}
Truth table50%1/2
A
A= $ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'}
| |||||||||||||||||||||||||||||
| 56 | 10 | $ffi->attach(strndup => ['string','size_t'] => 'opaque' => '$$'); | |||||||||||||||||||||||||||
| 57 | 10 | $_strndup_impl = 'libc'; | |||||||||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||||||||||
| 59 | 10 | ▶ | if($@) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | 0 | $_strndup_impl = 'ffi'; | |||||||||||||||||||||||||||
| 62 | 0 | $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 | 10 | eval { $ffi->attach( [ wcslen => '_wcslen' ] => [ 'opaque' ] => 'size_t' => '$' ) }; | |||||||||||||||||||||||||||
| 67 | 10 | eval { $ffi->attach( [ wcsnlen => '_wcsnlen' ] => [ 'string', 'size_t' ] => 'size_t' => '$$' ) }; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 10 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||