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
|
|
@ -4,3 +4,7 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
|
|
||||||
Version 3.0.8 (in progress)
|
Version 3.0.8 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2015-08-05: vadz
|
||||||
|
[Java] Make (char* STRING, size_t LENGTH) typemaps usable for
|
||||||
|
strings of other types, e.g. "unsigned char*".
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,16 @@ A test case for testing non null terminated char pointers.
|
||||||
%module char_binary
|
%module char_binary
|
||||||
|
|
||||||
%apply (char *STRING, size_t LENGTH) { (const char *str, size_t len) }
|
%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 %{
|
%inline %{
|
||||||
struct Test {
|
struct Test {
|
||||||
size_t strlen(const char *str, size_t len) {
|
size_t strlen(const char *str, size_t len) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
size_t ustrlen(const unsigned char *str, size_t len) {
|
||||||
|
return len;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef char namet[5];
|
typedef char namet[5];
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,11 @@ public class char_binary_runme {
|
||||||
|
|
||||||
if (t.strlen(hil0) != 4)
|
if (t.strlen(hil0) != 4)
|
||||||
throw new RuntimeException("bad multi-arg typemap");
|
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'));
|
print(t.strlen('hile'));
|
||||||
throw("bad multi-arg typemap 1");
|
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) {
|
if (t.strlen('hil\0') != 4) {
|
||||||
throw("bad multi-arg typemap 2");
|
throw("bad multi-arg typemap 2");
|
||||||
}
|
}
|
||||||
|
if (t.ustrlen('hil\0') != 4) {
|
||||||
|
throw("bad multi-arg typemap 2");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* creating a raw char*
|
* creating a raw char*
|
||||||
|
|
@ -24,6 +31,9 @@ char_binary.pchar_setitem(pc, 4, 0);
|
||||||
if (t.strlen(pc) != 4) {
|
if (t.strlen(pc) != 4) {
|
||||||
throw("bad multi-arg typemap (3)");
|
throw("bad multi-arg typemap (3)");
|
||||||
}
|
}
|
||||||
|
if (t.ustrlen(pc) != 4) {
|
||||||
|
throw("bad multi-arg typemap (3)");
|
||||||
|
}
|
||||||
|
|
||||||
char_binary.var_pchar = pc;
|
char_binary.var_pchar = pc;
|
||||||
if (char_binary.var_pchar != "hola") {
|
if (char_binary.var_pchar != "hola") {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 7;
|
use Test::More tests => 10;
|
||||||
BEGIN { use_ok('char_binary') }
|
BEGIN { use_ok('char_binary') }
|
||||||
require_ok('char_binary');
|
require_ok('char_binary');
|
||||||
|
|
||||||
my $t = char_binary::Test->new();
|
my $t = char_binary::Test->new();
|
||||||
|
|
||||||
is($t->strlen('hile'), 4, "string typemap");
|
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->strlen("hil\0"), 4, "string typemap");
|
||||||
|
is($t->ustrlen("hil\0"), 4, "unsigned string typemap");
|
||||||
|
|
||||||
#
|
#
|
||||||
# creating a raw char*
|
# creating a raw char*
|
||||||
|
|
@ -22,6 +24,7 @@ char_binary::pchar_setitem($pc, 4, 0);
|
||||||
|
|
||||||
|
|
||||||
is($t->strlen($pc), 4, "string typemap");
|
is($t->strlen($pc), 4, "string typemap");
|
||||||
|
is($t->ustrlen($pc), 4, "unsigned string typemap");
|
||||||
|
|
||||||
$char_binary::var_pchar = $pc;
|
$char_binary::var_pchar = $pc;
|
||||||
is($char_binary::var_pchar, "hola", "pointer case");
|
is($char_binary::var_pchar, "hola", "pointer case");
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,14 @@ t = Test()
|
||||||
if t.strlen('hile') != 4:
|
if t.strlen('hile') != 4:
|
||||||
print t.strlen('hile')
|
print t.strlen('hile')
|
||||||
raise RuntimeError, "bad multi-arg typemap"
|
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:
|
if t.strlen('hil\0') != 4:
|
||||||
raise RuntimeError, "bad multi-arg typemap"
|
raise RuntimeError, "bad multi-arg typemap"
|
||||||
|
if t.ustrlen('hil\0') != 4:
|
||||||
|
raise RuntimeError, "bad multi-arg typemap"
|
||||||
|
|
||||||
#
|
#
|
||||||
# creating a raw char*
|
# creating a raw char*
|
||||||
|
|
@ -21,6 +26,8 @@ pchar_setitem(pc, 4, 0)
|
||||||
|
|
||||||
if t.strlen(pc) != 4:
|
if t.strlen(pc) != 4:
|
||||||
raise RuntimeError, "bad multi-arg typemap"
|
raise RuntimeError, "bad multi-arg typemap"
|
||||||
|
if t.ustrlen(pc) != 4:
|
||||||
|
raise RuntimeError, "bad multi-arg typemap"
|
||||||
|
|
||||||
cvar.var_pchar = pc
|
cvar.var_pchar = pc
|
||||||
if cvar.var_pchar != "hola":
|
if cvar.var_pchar != "hola":
|
||||||
|
|
|
||||||
|
|
@ -1330,8 +1330,8 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
|
||||||
%typemap(freearg) (char *STRING, size_t LENGTH) ""
|
%typemap(freearg) (char *STRING, size_t LENGTH) ""
|
||||||
%typemap(in) (char *STRING, size_t LENGTH) {
|
%typemap(in) (char *STRING, size_t LENGTH) {
|
||||||
if ($input) {
|
if ($input) {
|
||||||
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
|
$1 = ($1_ltype) JCALL2(GetByteArrayElements, jenv, $input, 0);
|
||||||
$2 = (size_t) JCALL1(GetArrayLength, jenv, $input);
|
$2 = ($2_type) JCALL1(GetArrayLength, jenv, $input);
|
||||||
} else {
|
} else {
|
||||||
$1 = 0;
|
$1 = 0;
|
||||||
$2 = 0;
|
$2 = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue