Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (43 sloc) 1.442 kb
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
Jump to Line
Something went wrong with that request. Please try again.