Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests and support functions for explicitly managing strings.

  • Loading branch information...
commit e94f45ca4dd5df3010ecb84051980f506e3cbe6d 1 parent 8619523
@arnsholt arnsholt authored
Showing with 31 additions and 1 deletion.
  1. +13 −0 lib/NativeCall.pm6
  2. +7 −0 t/02-simple-args.c
  3. +11 −1 t/02-simple-args.t
View
13 lib/NativeCall.pm6
@@ -4,6 +4,11 @@ module NativeCall;
# representation.
my class native_callsite is repr('NativeCall') { }
+class CStr is export is repr('CStr') { }
+role ExplicitlyManagedString {
+ has CStr $.cstr is rw;
+}
+
# Maps a chosen string encoding to a type recognized by the native call engine.
sub string_encoding_to_nci_type($enc) {
given $enc {
@@ -230,4 +235,12 @@ multi trait_mod:<is>(Routine $p, $name, :$encoded!) is export {
$p does NativeCallEncoded[$name];
}
+# TODO: Encodings
+multi explicitly-manage(Str $s) is export {
+ $s does ExplicitlyManagedString;
+ # repr_box_str
+ #$s.cstr = nqp::unbox_s($s);
+ $s.cstr = pir::repr_box_str__PsP(nqp::unbox_s($s), CStr);
+}
+
# vim:ft=perl6
View
7 t/02-simple-args.c
@@ -66,4 +66,11 @@ DLLEXPORT void TakeAString(char *pass_msg)
printf("%s\n", pass_msg);
}
+static char *cached_str = NULL;
+DLLEXPORT void SetString(char *str) {
+ cached_str = str;
+}
+DLLEXPORT void PrintString() {
+ printf("%s\n", cached_str);
+}
View
12 t/02-simple-args.t
@@ -1,7 +1,7 @@
use t::CompileTestLib;
use NativeCall;
-say "1..9";
+say "1..10";
compile_test_lib('02-simple-args');
@@ -22,3 +22,13 @@ TakeAFloat(4.2e0);
# String related
sub TakeAString(Str) is native('./02-simple-args') { * }
TakeAString('ok 9 - passed a string');
+
+# Explicitly managing strings
+sub SetString(Str) is native('./02-simple-args') { * }
+sub PrintString() is native('./02-simple-args') { * }
+my $str = 'ok 10 - delayed string print';
+explicitly-manage($str);
+SetString($str);
+PrintString();
+
+# vim:ft=perl6
Please sign in to comment.
Something went wrong with that request. Please try again.