Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 55 lines (43 sloc) 1.442 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
use lib '.';
use t::CompileTestLib;
use NativeCall;
use Test;

plan 8;

compile_test_lib('07-writebarrier');

class IntPtr is repr('CPointer') {
    sub _deref(IntPtr $x) returns int is native('./07-writebarrier') { * }
    method deref() { return _deref(self); }
}

class Structy is repr('CStruct') {
    has IntPtr $.ptr;

    method set($ptr) {
        $!ptr := $ptr;
    }
}

sub make_ptr() returns IntPtr is native('./07-writebarrier') { * }
sub array_twiddle(CArray[IntPtr] $a) is native('./07-writebarrier') { * }
sub struct_twiddle(Structy $s) is native('./07-writebarrier') { * }
sub dummy(CArray[OpaquePointer] $a) is native('./07-writebarrier') { * }
sub save_ref(Structy $s) is native('./07-writebarrier') { * }
sub atadistance() is native('./07-writebarrier') { * }

my Structy $s .= new;
$s.set(make_ptr);

is $s.ptr.deref, 32, 'pointer in struct before twiddle';
struct_twiddle($s);
is $s.ptr.deref, 9, 'pointer in struct after twiddle';

my @arr := CArray[IntPtr].new;
@arr[0] = make_ptr;
@arr[1] = make_ptr;
@arr[2] = make_ptr;
array_twiddle(@arr);
is @arr[0].deref, 1, 'array element 1 after twiddle';
is @arr[1].deref, 2, 'array element 2 after twiddle';
is @arr[2].deref, 3, 'array element 3 after twiddle';

dummy(CArray);
pass 'ignore NULL arguments';

save_ref($s);
atadistance();
isnt($s.ptr.deref, 42, 'struct value before refresh');
refresh($s);
is($s.ptr.deref, 42, 'struct value before refresh');

# vim:ft=perl6
Something went wrong with that request. Please try again.