Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
handle and test Bool as argument to C++ subs
  • Loading branch information
FROGGS committed Feb 24, 2015
1 parent 5bc251b commit 15f8a05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/NativeCall.pm
Expand Up @@ -118,7 +118,7 @@ augment class Pointer {
}
multi method PARAMETERIZE_TYPE(Mu:U \t) {
die "A typed pointer can only hold integers, numbers, strings, CStructs, CPointers or CArrays (not {t.^name})"
unless t ~~ Int || t ~~ Num || t === Str || t.REPR eq 'CStruct' | 'CUnion' | 'CPPStruct' | 'CPointer' | 'CArray';
unless t ~~ Int || t ~~ Num || t ~~ Bool || t === Str || t.REPR eq 'CStruct' | 'CUnion' | 'CPPStruct' | 'CPointer' | 'CArray';
my \typed := TypedPointer[t];
typed.HOW.make_pun(typed);
}
Expand All @@ -128,6 +128,7 @@ my constant OpaquePointer is export(:types, :DEFAULT) = Pointer;
# Gets the NCI type code to use based on a given Perl 6 type.
my %type_map =
'int8' => 'char',
'Bool' => 'char',
'int16' => 'short',
'int32' => 'int',
'long' => 'long',
Expand Down
10 changes: 5 additions & 5 deletions t/04-nativecall/13-cpp-mangling.t
Expand Up @@ -2,7 +2,7 @@ use v6;
use NativeCall;
use Test;

plan 18;
plan 20;

shell 'g++ --shared -fPIC -o 13-cpp-mangling.so t/04-nativecall/13-cpp-mangling.cpp';

Expand All @@ -11,7 +11,7 @@ class Foo is repr<CPPStruct> {

method new() is nativeconv('thisgnu') is native("./13-cpp-mangling") { * }
method TakeAVoid() returns int32 is native("./13-cpp-mangling") { * }
# method TakeABool(Bool) returns int32 is native("./13-cpp-mangling") { * }
method TakeABool(Bool) returns int32 is native("./13-cpp-mangling") { * }
method TakeAChar(int8) returns int32 is native("./13-cpp-mangling") { * }
method TakeAShort(int16) returns int32 is native("./13-cpp-mangling") { * }
method TakeAnInt(int32) returns int32 is native("./13-cpp-mangling") { * }
Expand All @@ -22,7 +22,7 @@ class Foo is repr<CPPStruct> {
method TakeAString(Str) returns int32 is native("./13-cpp-mangling") { * }
method TakeAnArray(CArray[int32]) returns int32 is native("./13-cpp-mangling") { * }
method TakeAPointer(Pointer) returns int32 is native("./13-cpp-mangling") { * }
# method TakeABoolPointer(Pointer[Bool]) returns int32 is native("./13-cpp-mangling") { * }
method TakeABoolPointer(Pointer[Bool]) returns int32 is native("./13-cpp-mangling") { * }
method TakeACharPointer(Pointer[int8]) returns int32 is native("./13-cpp-mangling") { * }
method TakeAShortPointer(Pointer[int16]) returns int32 is native("./13-cpp-mangling") { * }
method TakeAnIntPointer(Pointer[int32]) returns int32 is native("./13-cpp-mangling") { * }
Expand All @@ -35,7 +35,7 @@ class Foo is repr<CPPStruct> {
my $foo = Foo.new;

is $foo.TakeAVoid(), 0, 'void mangling';
#is $foo.TakeABool(True), 1, 'bool mangling';
is $foo.TakeABool(True), 1, 'bool mangling';
is $foo.TakeAChar(1), 2, 'char mangling';
is $foo.TakeAShort(1), 3, 'short mangling';
is $foo.TakeAnInt(1), 4, 'int mangling';
Expand All @@ -46,7 +46,7 @@ is $foo.TakeADouble(6e0), 8, 'double mangling';
is $foo.TakeAString("1"), 9, 'string mangling';
is $foo.TakeAnArray(CArray[int32].new), 10, 'CArray mangling';
is $foo.TakeAPointer, 11, 'Pointer mangling';
#is $foo.TakeABoolPointer(Pointer[Bool].new), 12, 'bool* mangling';
is $foo.TakeABoolPointer(Pointer[Bool].new), 12, 'bool* mangling';
is $foo.TakeACharPointer(Pointer[int8].new), 13, 'char* mangling';
is $foo.TakeAShortPointer(Pointer[int16].new), 14, 'short* mangling';
is $foo.TakeAnIntPointer(Pointer[int32].new), 15, 'int* mangling';
Expand Down

0 comments on commit 15f8a05

Please sign in to comment.