Debian Codegraph @

corpus/memory/arg_pointer.pl

raw
1 use Test2::V0 -no_srand => 1;
2 use FFI::Platypus;
3 use Math::Complex;
4 use Test::LeakTrace qw( no_leaks_ok );
5
6 my @types = map { "$_*" } ( 'float', 'double', 'longdouble',
7 map { ( "sint$_" , "uint$_" ) }
8 qw( 8 16 32 64 ));
9
10 foreach my $type (@types)
11 {
12 subtest $type => sub {
13 my $ffi = FFI::Platypus->new;
14 my $f = $ffi->function(0 => [ $type ] => 'void' );
15 no_leaks_ok {
16 my $val = 129;
17 $f->call(\$val)
18 };
19 no_leaks_ok { $f->call(undef) };
20 }
21 }
22
23 subtest 'opaque' => sub {
24 my $ffi = FFI::Platypus->new( lib => [undef] );
25 my $malloc = $ffi->function( malloc => [ 'size_t' ] => 'opaque' );
26 my $free = $ffi->function( free => [ 'opaque' ] => 'void' );
27 my $ptr = $malloc->call(200);
28 my $f = $ffi->function(0 => [ 'opaque*' ] => 'void' );
29
30 no_leaks_ok { $f->call(\$ptr) };
31 $free->call($ptr);
32 no_leaks_ok { $f->call(undef) };
33 };
34
35 subtest 'string' => sub {
36 my $ffi = FFI::Platypus->new;
37 my $f = $ffi->function(0 => [ 'string*' ] => 'void' );
38 no_leaks_ok { $f->call(\"hello world") };
39 my $str = "hello world";
40 no_leaks_ok { $f->call(\$str) };
41 no_leaks_ok { $f->call(undef) };
42 };
43
44 subtest 'complex' => sub {
45
46 foreach my $type (qw( complex_float* complex_double* ))
47 {
48 subtest $type => sub {
49 my $ffi = FFI::Platypus->new;
50 my $f = $ffi->function(0 => [ $type ] => 'void' );
51
52 {
53 my $c = [1.0,2.0];
54 no_leaks_ok { $f->call(\$c) };
55 }
56
57 {
58 my $c = Math::Complex->make(1.0,2.0);
59 no_leaks_ok { $f->call(\$c) };
60 }
61 no_leaks_ok { $f->call(undef) };
62 };
63 }
64
65 };
66
67 done_testing;