Make (char*, size_t) typemap usable for strings of other types in Java.
Notably it now works for "unsigned char*" strings. Add a test to check that it now works in Java and also showing that it already worked for the other languages with support for this typemap.
This commit is contained in:
parent
95a08b3950
commit
a1bddd56eb
7 changed files with 37 additions and 3 deletions
|
|
@ -5,12 +5,16 @@ A test case for testing non null terminated char pointers.
|
|||
%module char_binary
|
||||
|
||||
%apply (char *STRING, size_t LENGTH) { (const char *str, size_t len) }
|
||||
%apply (char *STRING, size_t LENGTH) { (const unsigned char *str, size_t len) }
|
||||
|
||||
%inline %{
|
||||
struct Test {
|
||||
size_t strlen(const char *str, size_t len) {
|
||||
return len;
|
||||
}
|
||||
size_t ustrlen(const unsigned char *str, size_t len) {
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
||||
typedef char namet[5];
|
||||
|
|
|
|||
|
|
@ -20,5 +20,11 @@ public class char_binary_runme {
|
|||
|
||||
if (t.strlen(hil0) != 4)
|
||||
throw new RuntimeException("bad multi-arg typemap");
|
||||
|
||||
if (t.ustrlen(hile) != 4)
|
||||
throw new RuntimeException("bad multi-arg typemap");
|
||||
|
||||
if (t.ustrlen(hil0) != 4)
|
||||
throw new RuntimeException("bad multi-arg typemap");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,17 @@ if (t.strlen('hile') != 4) {
|
|||
print(t.strlen('hile'));
|
||||
throw("bad multi-arg typemap 1");
|
||||
}
|
||||
if (t.ustrlen('hile') != 4) {
|
||||
print(t.ustrlen('hile'));
|
||||
throw("bad multi-arg typemap 1");
|
||||
}
|
||||
|
||||
if (t.strlen('hil\0') != 4) {
|
||||
throw("bad multi-arg typemap 2");
|
||||
}
|
||||
if (t.ustrlen('hil\0') != 4) {
|
||||
throw("bad multi-arg typemap 2");
|
||||
}
|
||||
|
||||
/*
|
||||
* creating a raw char*
|
||||
|
|
@ -24,6 +31,9 @@ char_binary.pchar_setitem(pc, 4, 0);
|
|||
if (t.strlen(pc) != 4) {
|
||||
throw("bad multi-arg typemap (3)");
|
||||
}
|
||||
if (t.ustrlen(pc) != 4) {
|
||||
throw("bad multi-arg typemap (3)");
|
||||
}
|
||||
|
||||
char_binary.var_pchar = pc;
|
||||
if (char_binary.var_pchar != "hola") {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 7;
|
||||
use Test::More tests => 10;
|
||||
BEGIN { use_ok('char_binary') }
|
||||
require_ok('char_binary');
|
||||
|
||||
my $t = char_binary::Test->new();
|
||||
|
||||
is($t->strlen('hile'), 4, "string typemap");
|
||||
is($t->ustrlen('hile'), 4, "unsigned string typemap");
|
||||
|
||||
is($t->strlen("hil\0"), 4, "string typemap");
|
||||
is($t->ustrlen("hil\0"), 4, "unsigned string typemap");
|
||||
|
||||
#
|
||||
# creating a raw char*
|
||||
|
|
@ -22,6 +24,7 @@ char_binary::pchar_setitem($pc, 4, 0);
|
|||
|
||||
|
||||
is($t->strlen($pc), 4, "string typemap");
|
||||
is($t->ustrlen($pc), 4, "unsigned string typemap");
|
||||
|
||||
$char_binary::var_pchar = $pc;
|
||||
is($char_binary::var_pchar, "hola", "pointer case");
|
||||
|
|
|
|||
|
|
@ -4,9 +4,14 @@ t = Test()
|
|||
if t.strlen('hile') != 4:
|
||||
print t.strlen('hile')
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
if t.ustrlen('hile') != 4:
|
||||
print t.ustrlen('hile')
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
||||
if t.strlen('hil\0') != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
if t.ustrlen('hil\0') != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
||||
#
|
||||
# creating a raw char*
|
||||
|
|
@ -21,6 +26,8 @@ pchar_setitem(pc, 4, 0)
|
|||
|
||||
if t.strlen(pc) != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
if t.ustrlen(pc) != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
||||
cvar.var_pchar = pc
|
||||
if cvar.var_pchar != "hola":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue