blib/lib/FFI/Platypus/Memory.pm

filter: Statementstmt 83.9% 47 / 56 Branchbran 41.6% 5 / 12 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 70.0% 63 / 90 CC 1 SCAR 0.0
CC
1
Cov
71%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« xs/cast.c ↑ Summary xs/record_simple.c »
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
BranchTrueFalseTotal
if ($ENV{"FFI_PLATYPUS_MEMORY_STRDUP_IMPL"} || "libc") eq "ffi" 0 10 10
Condition50%1/2
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'} || 'libc'
l!l
010
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'}
Aresult
11
00
33 10 $ffi->attach(strdup => ['string'] => 'opaque' => '$');
34 10 $_strdup_impl = 'libc';
35 };
36 10 ▶if($@ && $^O eq 'MSWin32')
Branch: 1 branch
BranchTrueFalseTotal
if ($@ and $^O eq "MSWin32") 0 10 10
Condition33%1/3
$@ and $^O eq "MSWin32"
!ll&&!rl&&r
1000
MC/DC0%0/2
$@ and $^O eq "MSWin32"
$@ $^O eq "MSWin32"
Truth table33%1/3
A and B
A= $@B= $^O eq "MSWin32"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($ENV{"FFI_PLATYPUS_MEMORY_STRDUP_IMPL"} || "libc") eq "ffi" 0 0 0
Condition0%0/2
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'} || 'libc'
l!l
00
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'}
Aresult
11
00
40 0 $ffi->attach([ _strdup => 'strdup' ] => ['string'] => 'opaque' => '$');
41 0 $_strdup_impl = 'libc';
42 };
43 }
44 10 ▶if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 10 10
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
BranchTrueFalseTotal
if ($ENV{"FFI_PLATYPUS_MEMORY_STRDUP_IMPL"} || "libc") eq "ffi" 0 10 10
Condition50%1/2
$ENV{'FFI_PLATYPUS_MEMORY_STRDUP_IMPL'} || 'libc'
l!l
010
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'}
Aresult
11
00
56 10 $ffi->attach(strndup => ['string','size_t'] => 'opaque' => '$$');
57 10 $_strndup_impl = 'libc';
58 };
59 10 ▶if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 10 10
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__
« xs/cast.c ↑ Summary xs/record_simple.c »