massive typemap unification

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7676 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-18 13:24:15 +00:00
commit 7e5e4fd1f9
144 changed files with 6378 additions and 7248 deletions

View file

@ -1,5 +1,5 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i

View file

@ -1,5 +1,5 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
SRCS =
TARGET = example
INTERFACE = example.i

View file

@ -1,5 +1,5 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i

View file

@ -1,5 +1,5 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = my_tclsh
DLTARGET = example

View file

@ -16,16 +16,16 @@ public:
}
};
class quat;
class Quat;
class matrix4;
class tacka3;
class quat {
class Quat {
public:
quat::quat(void){}
quat::quat(float in_w, float x, float y, float z){}
quat::quat(const tacka3& axis, float angle){}
quat::quat(const matrix4& m){}
Quat::Quat(void){}
Quat::Quat(float in_w, float x, float y, float z){}
Quat::Quat(const tacka3& axis, float angle){}
Quat::Quat(const matrix4& m){}
};
%}

View file

@ -346,6 +346,7 @@ C_TEST_CASES += \
sizeof_pointer \
sneaky1 \
struct_rename \
typedef_struct \
typemap_subst \
unions

View file

@ -0,0 +1,49 @@
%module(directors="1") director_wstring;
%include stl.i
%include std_vector.i
%include std_wstring.i
// Using thread unsafe wrapping
%warnfilter(470) A;
%{
#include <vector>
#include <string>
%}
%feature("director") A;
%inline %{
struct A
{
A(const std::wstring& first)
: m_strings(1, first)
{}
virtual ~A() {}
virtual const std::wstring& get_first() const
{ return get(0); }
virtual const std::wstring& get(int n) const
{ return m_strings[n]; }
virtual const std::wstring& call_get_first() const
{ return get_first(); }
virtual const std::wstring& call_get(int n) const
{ return get(n); }
std::vector<std::wstring> m_strings;
virtual void process_text(const char *text)
{
}
void call_process_func() { process_text("hello"); }
};
%}
%template(StringVector) std::vector<std::wstring>;

View file

@ -63,6 +63,7 @@ struct SpeedClass {
enum speed { slow=10, medium=20, fast=30, lightning };
typedef enum speed speedtd1;
int speedTest0(int s) { return s; }
speed speedTest1(speed s) { return s; }
enum speed speedTest2(enum speed s) { return s; }
const speed speedTest3(const speed s) { return s; }
@ -77,6 +78,7 @@ struct SpeedClass {
SpeedClass() : myColour2(red), mySpeedtd1(slow) { }
};
int speedTest0(int s) { return s; }
SpeedClass::speed speedTest1(SpeedClass::speed s) { return s; }
enum SpeedClass::speed speedTest2(enum SpeedClass::speed s) { return s; }
const SpeedClass::speed speedTest3(const SpeedClass::speed s) { return s; }

View file

@ -19,8 +19,10 @@ SWIGEXPORT extern int externexport(int);
extern int SWIGSTDCALL externstdcall(int);
%{
// externimport ought to be using MYDLLIMPORT and compiled into another dll, but that is
// a bit tricky to do in the test framework
/*
externimport ought to be using MYDLLIMPORT and compiled into another dll, but that is
a bit tricky to do in the test framework
*/
SWIGEXPORT extern int externimport(int i) { return i; }
SWIGEXPORT extern int externexport(int i) { return i; }
extern int SWIGSTDCALL externstdcall(int i) { return i; }

View file

@ -1,4 +1,4 @@
%module implicittest
%module li_implicit
%include implicit.i
%inline

View file

@ -1,6 +1,9 @@
// Massive primitive datatype test.
%module(directors="1") primitive_types
// Ruby constant names
#pragma SWIG nowarn=801
// Using thread unsafe wrapping
#pragma SWIG nowarn=470
/*
@ -217,8 +220,8 @@ macro(long, pfx, long)
macro(unsigned long, pfx, ulong)
macro(long long, pfx, llong)
macro(unsigned long long, pfx, ullong)
//macro(float, pfx, float)
//macro(double, pfx, double)
macro(float, pfx, float)
macro(double, pfx, double)
macro(char, pfx, char)
%enddef
@ -345,9 +348,7 @@ macro(size_t, pfx, sizet)
%enddef
#ifdef SWIGPYTHON
%apply (char *STRING, int LENGTH) { (const char *str, size_t len) }
#endif
%inline {
struct Foo

View file

@ -18,14 +18,15 @@ CPP_TEST_CASES += \
complextest \
director_stl \
director_thread \
director_wstring \
file_test \
implicittest \
inout \
input \
inplaceadd \
kwargs \
li_cstring \
li_cwstring \
li_implicit \
li_std_except \
li_std_vectora \
li_std_map \

View file

@ -6,6 +6,7 @@ if mainc(largs) != 3:
targs=('hi','hola')
if mainv(targs,1) != 'hola':
print mainv(targs,1)
raise RuntimeError, "bad main typemap"
targs=('hi', 'hola')

View file

@ -0,0 +1 @@
import empty

View file

@ -32,6 +32,10 @@
p->second += 1;
}
inline void AddOne1r(double& a) {
a += 1;
}
%}
%template() std::pair<double, double>;
@ -41,3 +45,4 @@ void AddOne3(double* INOUT, double* INOUT, double* INOUT);
void AddOne1p(std::pair<double, double>* INOUT);
void AddOne2p(std::pair<double, double>* INOUT, double* INOUT);
void AddOne3p(double* INOUT, std::pair<double, double>* INOUT, double* INOUT);
void AddOne1r(double& INOUT);

View file

@ -11,9 +11,11 @@ if test2() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
raise RuntimeError
if test3("hello") != "hello-suffix":
print test3("hello")
raise RuntimeError
if test4("hello") != "hello-suffix":
print test4("hello")
raise RuntimeError
if test5(4) != 'xxxx':

View file

@ -1,4 +1,4 @@
from implicittest import *
from li_implicit import *
b = B()
ai = A(1)
ad = A(2.0)

View file

@ -11,6 +11,7 @@ if li_std_string.test_cvalue(x) != x:
raise RuntimeError, "bad string mapping"
if li_std_string.test_value(x) != x:
print x, li_std_string.test_value(x)
raise RuntimeError, "bad string mapping"
if li_std_string.test_const_reference(x) != x:

View file

@ -3,6 +3,7 @@ import li_std_wstring
x=u"h"
if li_std_wstring.test_wcvalue(x) != x:
print li_std_wstring.test_wcvalue(x)
raise RuntimeError, "bad string mapping"
x=u"hello"

View file

@ -14,8 +14,8 @@ cvar.var_long = sct_long
cvar.var_ulong = sct_ulong
cvar.var_llong = sct_llong
cvar.var_ullong = sct_ullong
#cvar.var_float = sct_float
#cvar.var_double = sct_double
cvar.var_float = sct_float
cvar.var_double = sct_double
cvar.var_char = sct_char
cvar.var_pchar = sct_pchar
cvar.var_pcharc = sct_pcharc
@ -46,8 +46,8 @@ if cvar.var_long != cct_long: pyerror("long", cvar.var_long, cct_long)
if cvar.var_ulong != cct_ulong: pyerror("ulong", cvar.var_ulong, cct_ulong)
if cvar.var_llong != cct_llong: pyerror("llong", cvar.var_llong, cct_llong)
if cvar.var_ullong != cct_ullong: pyerror("ullong", cvar.var_ullong, cct_ullong)
#if cvar.var_float != cct_float: pyerror("float", cvar.var_float, cct_float)
#if cvar.var_double != cct_double: pyerror("double", cvar.var_double, cct_double)
if cvar.var_float != cct_float: pyerror("float", cvar.var_float, cct_float)
if cvar.var_double != cct_double: pyerror("double", cvar.var_double, cct_double)
if cvar.var_char != cct_char: pyerror("char", cvar.var_char, cct_char)
if cvar.var_pchar != cct_pchar: pyerror("pchar", cvar.var_pchar, cct_pchar)
if cvar.var_pcharc != cct_pcharc: pyerror("pchar", cvar.var_pcharc, cct_pcharc)
@ -128,8 +128,8 @@ p.var_long = p.stc_long
p.var_ulong = p.stc_ulong
p.var_llong = p.stc_llong
p.var_ullong = p.stc_ullong
#p.var_float = p.stc_float
#p.var_double = p.stc_double
p.var_float = p.stc_float
p.var_double = p.stc_double
p.var_char = p.stc_char
p.var_pchar = sct_pchar
p.var_pcharc = sct_pcharc
@ -156,8 +156,8 @@ t.var_long = t.stc_long
t.var_ulong = t.stc_ulong
t.var_llong = t.stc_llong
t.var_ullong = t.stc_ullong
#t.var_float = t.stc_float
#t.var_double = t.stc_double
t.var_float = t.stc_float
t.var_double = t.stc_double
t.var_char = t.stc_char
t.var_pchar = sct_pchar
t.var_pcharc = sct_pcharc
@ -215,6 +215,7 @@ if cvar.var_char != '\0':
cvar.var_namet = '\0'
#if cvar.var_namet != '\0\0\0\0\0':
if cvar.var_namet != '':
print 'hola', '', cvar.var_namet
raise RuntimeError, "bad char '\0' case"
cvar.var_namet = ''
@ -301,7 +302,7 @@ try:
a = t.var_uint
t.var_uint = -1
error = 1
except TypeError:
except OverflowError:
if a != t.var_uint:
error = 1
pass

View file

@ -33,7 +33,7 @@ if (Bools.value(Bools.const_pbool) != Bools.bool1)
exit 1
end
if (Bools.value(Bools.const_rbool) != Bools.bool2)
if (Bools.const_rbool != Bools.bool2)
print "Runtime test 7 failed\n"
exit 1
end
@ -59,7 +59,7 @@ if (Bools.value(Bools.pbo(Bools.pbool)) != Bools.value(Bools.pbool))
exit 1
end
if (Bools.const_rbo(Bools.value(Bools.const_rbool)) != Bools.value(Bools.const_rbool))
if (Bools.const_rbo(Bools.const_rbool) != Bools.const_rbool)
print "Runtime test 12 failed\n"
exit 1
end

View file

@ -14,6 +14,12 @@ class MyFoo2 < Foo
end
end
class MyFoo3 < Foo
def ping
5 # error: should return a string
end
end
ok = false
a = MyFoo.new
@ -38,5 +44,16 @@ rescue TypeError
ok = true
end
a = MyFoo3.new
b = launder(a)
begin
b.pong
rescue TypeError
ok = true
end
raise RuntimeError unless ok

View file

@ -0,0 +1,43 @@
require 'primitive_types'
include Primitive_types
raise RuntimeError if val_uchar(255) != 255
raise RuntimeError if val_double(255.5) != 255.5
fail = 0
begin
val_uchar(-1)
rescue RangeError
fail = 1
end
fail = 0
begin
val_uchar(256)
rescue RangeError
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_uchar(256.0)
rescue TypeError
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_uchar("caca")
rescue TypeError
fail = 1
end
raise RuntimeError if fail != 1

View file

@ -9,6 +9,9 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
CPP_TEST_CASES += \
primitive_types \
include $(srcdir)/../common.mk
# Overridden variables here
@ -39,6 +42,6 @@ run_testcase = \
# Clean
%.clean:
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile tcl_clean

View file

@ -35,7 +35,7 @@ if { [ value $const_pbool ] != $bool1} {
exit 1
}
if { [ value $const_rbool ] != $bool2} {
if { $const_rbool != $bool2} {
puts stderr "Runtime test 7 failed"
exit 1
}
@ -61,7 +61,7 @@ if { [ value [ pbo $pbool ] ] != [ value $pbool ]} {
exit 1
}
if { [ const_rbo [ value $const_rbool ] ] != [ value $const_rbool ]} {
if { [ const_rbo $const_rbool ] != $const_rbool } {
puts stderr "Runtime test 12 failed"
exit 1
}

View file

@ -3,6 +3,7 @@ if [ catch { load ./enum_thorough[info sharedlibextension] enum_thorough} err_ms
puts stderr "Could not load shared object:\n$err_msg"
}
if { [speedTest0 $SpeedClass_slow] != $SpeedClass_slow } { puts stderr "speedTest0 failed" }
if { [speedTest4 $SpeedClass_slow] != $SpeedClass_slow } { puts stderr "speedTest4 failed" }
if { [speedTest5 $SpeedClass_slow] != $SpeedClass_slow } { puts stderr "speedTest5 failed" }

View file

@ -9,7 +9,7 @@ set v [malloc_void 32]
set x [foo 3]
if {$x != "foo:int"} {
puts stderr "foo(int) test failed"
puts stderr "foo(int) test failed $x"
exit 1
}

View file

@ -0,0 +1,21 @@
if [ catch { load ./primitive_types[info sharedlibextension] primitive_types} err_msg ] {
puts stderr "Could not load shared object:\n$err_msg"
}
if {[val_int 10] != 10 } { error "bad int map" }
if {[val_schar 10] != 10 } { error "bad char map" }
if {[val_short 10] != 10 } { error "bad schar map" }
if [catch { val_schar 10000 } ] {} else { error "bad schar map" }
if [catch { val_uint -100 } ] {} else { error "bad uint map" }
if [catch { val_uchar -100 } ] {} else { error "bad uchar map" }
if {[val_uint 10] != 10 } { error "bad uint map" }
if {[val_uchar 10] != 10 } { error "bad uchar map" }
if {[val_ushort 10] != 10 } { error "bad ushort map" }