Added some missing multi-argument typemaps: (char *STRING, size_t LENGTH) and (char *STRING, int LENGTH) - Java patch is from Volker Grabsch. Elements of the primitive_types.i testcase for this moved into char_binary.i. Documentation for this enhanced.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12393 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9adb494558
commit
ef865e06d5
15 changed files with 194 additions and 37 deletions
29
Examples/test-suite/char_binary.i
Normal file
29
Examples/test-suite/char_binary.i
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
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) }
|
||||
|
||||
%inline %{
|
||||
struct Test {
|
||||
size_t strlen(const char *str, size_t len) {
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
||||
typedef char namet[5];
|
||||
namet var_namet;
|
||||
|
||||
typedef char* pchar;
|
||||
pchar var_pchar;
|
||||
%}
|
||||
|
||||
// Remove string handling typemaps and treat as pointer
|
||||
%typemap(freearg) SWIGTYPE * ""
|
||||
%apply SWIGTYPE * { char * }
|
||||
|
||||
%include "carrays.i"
|
||||
%array_functions(char, pchar);
|
||||
|
||||
24
Examples/test-suite/java/char_binary_runme.java
Normal file
24
Examples/test-suite/java/char_binary_runme.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import char_binary.*;
|
||||
|
||||
public class char_binary_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("char_binary");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
Test t = new Test();
|
||||
byte[] hile = "hile".getBytes();
|
||||
byte[] hil0 = "hil\0".getBytes();
|
||||
if (t.strlen(hile) != 4)
|
||||
throw new RuntimeException("bad multi-arg typemap");
|
||||
|
||||
if (t.strlen(hil0) != 4)
|
||||
throw new RuntimeException("bad multi-arg typemap");
|
||||
}
|
||||
}
|
||||
32
Examples/test-suite/perl5/char_binary_runme.pl
Executable file
32
Examples/test-suite/perl5/char_binary_runme.pl
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 7;
|
||||
BEGIN { use_ok('char_binary') }
|
||||
require_ok('char_binary');
|
||||
|
||||
my $t = char_binary::Test->new();
|
||||
|
||||
is($t->strlen('hile'), 4, "string typemap");
|
||||
|
||||
is($t->strlen("hil\0"), 4, "string typemap");
|
||||
|
||||
#
|
||||
# creating a raw char*
|
||||
#
|
||||
my $pc = char_binary::new_pchar(5);
|
||||
char_binary::pchar_setitem($pc, 0, 'h');
|
||||
char_binary::pchar_setitem($pc, 1, 'o');
|
||||
char_binary::pchar_setitem($pc, 2, 'l');
|
||||
char_binary::pchar_setitem($pc, 3, 'a');
|
||||
char_binary::pchar_setitem($pc, 4, 0);
|
||||
|
||||
|
||||
is($t->strlen($pc), 4, "string typemap");
|
||||
|
||||
$char_binary::var_pchar = $pc;
|
||||
is($char_binary::var_pchar, "hola", "pointer case");
|
||||
|
||||
$char_binary::var_namet = $pc;
|
||||
is($char_binary::var_namet, "hola", "pointer case");
|
||||
|
||||
char_binary::delete_pchar($pc);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 54;
|
||||
use Test::More tests => 51;
|
||||
BEGIN { use_ok('primitive_types') }
|
||||
require_ok('primitive_types');
|
||||
|
||||
|
|
@ -179,11 +179,6 @@ $t->{var_namet} = 'hol';
|
|||
is($t->{var_namet}, 'hol', "namet");
|
||||
|
||||
|
||||
is($t->strlen('hile'), 4, "string typemap");
|
||||
|
||||
is($t->strlen("hil\0"), 4, "string typemap");
|
||||
|
||||
|
||||
$primitive_types::var_char = "\0";
|
||||
is($primitive_types::var_char, "\0", "char '0' case");
|
||||
|
||||
|
|
@ -220,8 +215,6 @@ primitive_types::pchar_setitem($pc, 3, 'a');
|
|||
primitive_types::pchar_setitem($pc, 4, 0);
|
||||
|
||||
|
||||
is($t->strlen($pc), 4, "string typemap");
|
||||
|
||||
$primitive_types::var_pchar = $pc;
|
||||
is($primitive_types::var_pchar, "hola", "pointer case");
|
||||
|
||||
|
|
|
|||
|
|
@ -355,8 +355,6 @@ macro(size_t, pfx, sizet)
|
|||
%enddef
|
||||
|
||||
|
||||
%apply (char *STRING, int LENGTH) { (const char *str, size_t len) }
|
||||
|
||||
%inline {
|
||||
struct Foo
|
||||
{
|
||||
|
|
@ -464,15 +462,8 @@ macro(size_t, pfx, sizet)
|
|||
|
||||
%test_prim_types_ovr(ovr_decl, ovr)
|
||||
|
||||
size_t strlen(const char *str, size_t len)
|
||||
{
|
||||
return len;
|
||||
}
|
||||
|
||||
static const double stc_double;
|
||||
static const double stc_float;
|
||||
|
||||
|
||||
};
|
||||
|
||||
struct TestDirector
|
||||
|
|
|
|||
36
Examples/test-suite/python/char_binary_runme.py
Normal file
36
Examples/test-suite/python/char_binary_runme.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from char_binary import *
|
||||
|
||||
t = Test()
|
||||
if t.strlen('hile') != 4:
|
||||
print t.strlen('hile')
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
||||
if t.strlen('hil\0') != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
||||
#
|
||||
# creating a raw char*
|
||||
#
|
||||
pc = new_pchar(5)
|
||||
pchar_setitem(pc, 0, 'h')
|
||||
pchar_setitem(pc, 1, 'o')
|
||||
pchar_setitem(pc, 2, 'l')
|
||||
pchar_setitem(pc, 3, 'a')
|
||||
pchar_setitem(pc, 4, 0)
|
||||
|
||||
|
||||
if t.strlen(pc) != 4:
|
||||
raise RuntimeError, "bad multi-arg typemap"
|
||||
|
||||
cvar.var_pchar = pc
|
||||
if cvar.var_pchar != "hola":
|
||||
print cvar.var_pchar
|
||||
raise RuntimeError, "bad pointer case"
|
||||
|
||||
cvar.var_namet = pc
|
||||
#if cvar.var_namet != "hola\0":
|
||||
if cvar.var_namet != "hola":
|
||||
raise RuntimeError, "bad pointer case"
|
||||
|
||||
delete_pchar(pc)
|
||||
|
||||
|
|
@ -188,14 +188,6 @@ if t.var_namet != 'hol':
|
|||
raise RuntimeError
|
||||
|
||||
|
||||
if t.strlen('hile') != 4:
|
||||
print t.strlen('hile')
|
||||
raise RuntimeError, "bad string typemap"
|
||||
|
||||
if t.strlen('hil\0') != 4:
|
||||
raise RuntimeError, "bad string typemap"
|
||||
|
||||
|
||||
cvar.var_char = '\0'
|
||||
if cvar.var_char != '\0':
|
||||
raise RuntimeError, "bad char '0' case"
|
||||
|
|
@ -244,9 +236,6 @@ pchar_setitem(pc, 3, 'a')
|
|||
pchar_setitem(pc, 4, 0)
|
||||
|
||||
|
||||
if t.strlen(pc) != 4:
|
||||
raise RuntimeError, "bad string typemap"
|
||||
|
||||
cvar.var_pchar = pc
|
||||
if cvar.var_pchar != "hola":
|
||||
print cvar.var_pchar
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue