Skip to content

Commit

Permalink
Support and test unsinged types in NativeCall.
Browse files Browse the repository at this point in the history
Tests pass on both MoarVM and JVM.
  • Loading branch information
jnthn committed Apr 4, 2015
1 parent 54d6aa0 commit f2b9e0c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/NativeCall.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ my %type_map =
'int64' => 'longlong',
'long' => 'long',
'int' => 'long',
'uint8' => 'uchar',
'uint16' => 'ushort',
'uint32' => 'uint',
'uint64' => 'ulonglong',
'ulong' => 'ulong',
'uint' => 'ulong',
'Int' => 'longlong',
'num32' => 'float',
'num64' => 'double',
Expand Down
21 changes: 21 additions & 0 deletions t/04-nativecall/02-simple-args.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,24 @@ DLLEXPORT int TakeInt64(int64_t x)
return 9;
return 0;
}

DLLEXPORT int TakeUint8(unsigned char x)
{
if (x == 0xFE)
return 10;
return 0;
}

DLLEXPORT int TakeUint16(unsigned short x)
{
if (x == 0xFFFE)
return 11;
return 0;
}

DLLEXPORT int TakeUint32(unsigned int x)
{
if (x == 0xFFFFFFFE)
return 12;
return 0;
}
10 changes: 9 additions & 1 deletion t/04-nativecall/02-simple-args.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lib 'lib';
use NativeCall;
use Test;

plan 9;
plan 12;

compile_test_lib('02-simple-args');

Expand Down Expand Up @@ -43,4 +43,12 @@ wrapper(42);
sub TakeInt64(int64) returns int32 is native('./02-simple-args') { * }
is TakeInt64(0xFFFFFFFFFF), 9, 'passed int64 0xFFFFFFFFFF';

# Unsigned integers.
sub TakeUint8(uint8) returns int32 is native('./02-simple-args') { * }
sub TakeUint16(uint16) returns int32 is native('./02-simple-args') { * }
sub TakeUint32(uint32) returns int32 is native('./02-simple-args') { * }
is TakeUint8(0xFE), 10, 'passed uint8 0xFE';
is TakeUint16(0xFFFE), 11, 'passed uint8 0xFFFE';
is TakeUint32(0xFFFFFFFE), 12, 'passed uint8 0xFFFFFFFE';

# vim:ft=perl6
15 changes: 15 additions & 0 deletions t/04-nativecall/03-simple-returns.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,18 @@ DLLEXPORT int64_t ReturnInt64()
{
return 0xFFFFFFFFFF;
}

DLLEXPORT unsigned char ReturnUint8()
{
return 0xFE;
}

DLLEXPORT unsigned short ReturnUint16()
{
return 0xFFFE;
}

DLLEXPORT unsigned int ReturnUint32()
{
return 0xFFFFFFFE;
}
11 changes: 10 additions & 1 deletion t/04-nativecall/03-simple-returns.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lib 'lib';
use NativeCall;
use Test;

plan(8);
plan(11);

compile_test_lib('03-simple-returns');

Expand All @@ -31,3 +31,12 @@ nok ReturnNullString().defined, 'returning null string pointer';

sub ReturnInt64() returns int64 is native('./03-simple-returns') { * }
is ReturnInt64(), 0xFFFFFFFFFF, 'returning int64 works';

sub ReturnUint8() returns uint8 is native('./03-simple-returns') { * }
is ReturnUint8(), 0xFE, 'returning uint8 works';

sub ReturnUint16() returns uint16 is native('./03-simple-returns') { * }
is ReturnUint16(), 0xFFFE, 'returning uint16 works';

sub ReturnUint32() returns uint32 is native('./03-simple-returns') { * }
is ReturnUint32(), 0xFFFFFFFE, 'returning uint32 works';

0 comments on commit f2b9e0c

Please sign in to comment.