Skip to content

Instantly share code, notes, and snippets.

@timo
Created February 21, 2019 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timo/39af56a0a68282e5032188bb5f717187 to your computer and use it in GitHub Desktop.
Save timo/39af56a0a68282e5032188bb5f717187 to your computer and use it in GitHub Desktop.
diff --git a/t/04-nativecall/15-rw-args.c b/t/04-nativecall/15-rw-args.c
index 9549c7624..b66a12336 100644
--- a/t/04-nativecall/15-rw-args.c
+++ b/t/04-nativecall/15-rw-args.c
@@ -93,3 +93,17 @@ DLLEXPORT int SetPtrToPtr(int **ptr) {
*ptr = (int *)42;
return 1;
}
+
+short buffer[32];
+
+DLLEXPORT int ReturnPointerToArray(void **ptr) {
+ short index;
+ for(index = 0; index < 32; index++)
+ buffer[index] = 1;
+ *ptr = &buffer;
+ return 1;
+}
+
+DLLEXPORT long long int VerifyBufferChanged() {
+ return buffer[0] + buffer[1] + buffer[2] + buffer[3];
+}
diff --git a/t/04-nativecall/15-rw-args.t b/t/04-nativecall/15-rw-args.t
index 60010885d..e8ada9bfe 100644
--- a/t/04-nativecall/15-rw-args.t
+++ b/t/04-nativecall/15-rw-args.t
@@ -31,6 +31,9 @@ sub SetULongLong(ulonglong is rw) is native('./15-rw-args') { * }
sub PassULongLong(ulonglong is rw) returns ulonglong is native('./15-rw-args') { * }
sub SetPtrToPtr(Pointer is rw) returns int32 is native('./15-rw-args') { * }
+sub ReturnPointerToArray(CArray[uint8] is rw) returns long is native('./15-rw-args') { * }
+sub VerifyBufferChanged() returns int64 is native('./15-rw-args') { * }
+
my int8 $c; SetChar($c);
is $c, 97, 'Perl\'s rw variable was set by C (char)';
is PassChar($c), 97, 'Perl\'s rw variable was passed and returned by C (char)';
@@ -75,4 +78,14 @@ my Pointer $ptr .= new;
ok SetPtrToPtr($ptr), 'Can pass an instantiated pointer with rw-trait to C';
is +$ptr, 42, 'Perl\'s rw variable was set by C (pointer)';
+my CArray[uint8] $buffer .= new;
+
+ReturnPointerToArray($buffer);
+$buffer[0] = 2;
+$buffer[1] = 3;
+$buffer[2] = 4;
+$buffer[3] = 5;
+
+is VerifyBufferChanged(), 14, "buffer has changed";
+
# vim:ft=perl6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment