Browse files

Expose refresh op through function, tests for refresh().

  • Loading branch information...
1 parent 79429d9 commit 3bf67129e44711e71714a14452dce2deca574c4b @arnsholt arnsholt committed Aug 3, 2012
Showing with 26 additions and 2 deletions.
  1. +5 −0 lib/NativeCall.pm6
  2. +11 −0 t/07-writebarrier.c
  3. +10 −2 t/07-writebarrier.t
View
5 lib/NativeCall.pm6
@@ -261,4 +261,9 @@ multi explicitly-manage(Str $x is rw, :$encoding = 'utf8') is export {
$x.cstr = pir::repr_box_str__PsP(nqp::unbox_s($x), CStr[$encoding]);
}
+multi refresh($obj) is export {
+ nqp::nativecallrefresh($obj);
+ 1;
+}
+
# vim:ft=perl6
View
11 t/07-writebarrier.c
@@ -4,6 +4,8 @@ typedef struct {
long *ptr;
} Structy;
+static Structy *saved = NULL;
+
long _deref(long *ptr) {
return *ptr;
}
@@ -32,3 +34,12 @@ void array_twiddle(long **arr) {
void dummy(void **arr) {
/* dummy */
}
+
+void save_ref(Structy *s) {
+ saved = s;
+}
+
+void atadistance(void) {
+ saved->ptr = (long *) malloc(sizeof(long));
+ *(saved->ptr) = 42;
+}
View
12 t/07-writebarrier.t
@@ -3,7 +3,7 @@ use t::CompileTestLib;
use NativeCall;
use Test;
-plan 6;
+plan 8;
compile_test_lib('07-writebarrier');
@@ -24,6 +24,8 @@ 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);
@@ -42,6 +44,12 @@ 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'
+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

0 comments on commit 3bf6712

Please sign in to comment.