diff options
author | Marcelo Matus <mmatus@acms.arizona.edu> | 2005-10-18 13:24:15 +0000 |
---|---|---|
committer | Marcelo Matus <mmatus@acms.arizona.edu> | 2005-10-18 13:24:15 +0000 |
commit | 7e5e4fd1f9c8adfcd0eb1328e35143e110e115ff (patch) | |
tree | c9290832aaa1a42f5bcb6dd14ffaf82ed584ddca /Examples | |
parent | 5bbd841acc554b9e3d1ec33d604e825197ae6e0c (diff) | |
download | swig-7e5e4fd1f9c8adfcd0eb1328e35143e110e115ff.tar.gz |
massive typemap unification
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7676 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples')
28 files changed, 187 insertions, 34 deletions
diff --git a/Examples/python/multimap/Makefile b/Examples/python/multimap/Makefile index 754c4a029..4a1e1bb71 100644 --- a/Examples/python/multimap/Makefile +++ b/Examples/python/multimap/Makefile @@ -1,5 +1,5 @@ TOP = ../.. -SWIG = $(TOP)/../swig +SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i diff --git a/Examples/python/varargs/Makefile b/Examples/python/varargs/Makefile index 5b726c2b1..01d0f943a 100644 --- a/Examples/python/varargs/Makefile +++ b/Examples/python/varargs/Makefile @@ -1,5 +1,5 @@ TOP = ../.. -SWIG = $(TOP)/../swig +SWIG = $(TOP)/../preinst-swig SRCS = TARGET = example INTERFACE = example.i diff --git a/Examples/ruby/mpointer/Makefile b/Examples/ruby/mpointer/Makefile index 27cb6d6bd..2a8eb7b56 100644 --- a/Examples/ruby/mpointer/Makefile +++ b/Examples/ruby/mpointer/Makefile @@ -1,5 +1,5 @@ TOP = ../.. -SWIG = $(TOP)/../swig +SWIG = $(TOP)/../preinst-swig CXXSRCS = example.cxx TARGET = example INTERFACE = example.i diff --git a/Examples/tcl/multimap/Makefile b/Examples/tcl/multimap/Makefile index 6efb6fb84..bed049a36 100644 --- a/Examples/tcl/multimap/Makefile +++ b/Examples/tcl/multimap/Makefile @@ -1,5 +1,5 @@ TOP = ../.. -SWIG = $(TOP)/../swig +SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = my_tclsh DLTARGET = example diff --git a/Examples/test-suite/class_scope_weird.i b/Examples/test-suite/class_scope_weird.i index 74155478c..a0a544d28 100644 --- a/Examples/test-suite/class_scope_weird.i +++ b/Examples/test-suite/class_scope_weird.i @@ -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){} }; %} diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 6f45b8811..6448d572a 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -346,6 +346,7 @@ C_TEST_CASES += \ sizeof_pointer \ sneaky1 \ struct_rename \ + typedef_struct \ typemap_subst \ unions diff --git a/Examples/test-suite/director_wstring.i b/Examples/test-suite/director_wstring.i new file mode 100644 index 000000000..f386b20ec --- /dev/null +++ b/Examples/test-suite/director_wstring.i @@ -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>; diff --git a/Examples/test-suite/enum_thorough.i b/Examples/test-suite/enum_thorough.i index 0a31b7d1c..3fe737d89 100644 --- a/Examples/test-suite/enum_thorough.i +++ b/Examples/test-suite/enum_thorough.i @@ -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; } diff --git a/Examples/test-suite/extern_declaration.i b/Examples/test-suite/extern_declaration.i index 24e214a2e..eca97b5b4 100644 --- a/Examples/test-suite/extern_declaration.i +++ b/Examples/test-suite/extern_declaration.i @@ -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; } diff --git a/Examples/test-suite/python/implicittest.i b/Examples/test-suite/li_implicit.i index 617fa0a27..ce457be8b 100644 --- a/Examples/test-suite/python/implicittest.i +++ b/Examples/test-suite/li_implicit.i @@ -1,4 +1,4 @@ -%module implicittest +%module li_implicit %include implicit.i %inline diff --git a/Examples/test-suite/primitive_types.i b/Examples/test-suite/primitive_types.i index 964d82f65..01813ad8f 100644 --- a/Examples/test-suite/primitive_types.i +++ b/Examples/test-suite/primitive_types.i @@ -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 diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index e6faa2bbc..32122943a 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -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 \ diff --git a/Examples/test-suite/python/argcargvtest_runme.py b/Examples/test-suite/python/argcargvtest_runme.py index c1ca9386d..5ddb3df42 100644 --- a/Examples/test-suite/python/argcargvtest_runme.py +++ b/Examples/test-suite/python/argcargvtest_runme.py @@ -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') diff --git a/Examples/test-suite/python/empty_runme.py b/Examples/test-suite/python/empty_runme.py new file mode 100644 index 000000000..7de5d15e5 --- /dev/null +++ b/Examples/test-suite/python/empty_runme.py @@ -0,0 +1 @@ +import empty diff --git a/Examples/test-suite/python/inout.i b/Examples/test-suite/python/inout.i index f557b5c46..dc6db0ecb 100644 --- a/Examples/test-suite/python/inout.i +++ b/Examples/test-suite/python/inout.i @@ -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); diff --git a/Examples/test-suite/python/li_cstring_runme.py b/Examples/test-suite/python/li_cstring_runme.py index 5ac4d7e71..6503744bd 100644 --- a/Examples/test-suite/python/li_cstring_runme.py +++ b/Examples/test-suite/python/li_cstring_runme.py @@ -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': diff --git a/Examples/test-suite/python/implicittest_runme.py b/Examples/test-suite/python/li_implicit_runme.py index 5de43844f..a0672e016 100644 --- a/Examples/test-suite/python/implicittest_runme.py +++ b/Examples/test-suite/python/li_implicit_runme.py @@ -1,4 +1,4 @@ -from implicittest import * +from li_implicit import * b = B() ai = A(1) ad = A(2.0) diff --git a/Examples/test-suite/python/li_std_string_runme.py b/Examples/test-suite/python/li_std_string_runme.py index a30795ae6..7a04a3e6f 100644 --- a/Examples/test-suite/python/li_std_string_runme.py +++ b/Examples/test-suite/python/li_std_string_runme.py @@ -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: diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py index 3e49033fd..1b2252ddb 100644 --- a/Examples/test-suite/python/li_std_wstring_runme.py +++ b/Examples/test-suite/python/li_std_wstring_runme.py @@ -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" diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py index bd357b528..29d596ee8 100644 --- a/Examples/test-suite/python/primitive_types_runme.py +++ b/Examples/test-suite/python/primitive_types_runme.py @@ -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 diff --git a/Examples/test-suite/ruby/bools_runme.rb b/Examples/test-suite/ruby/bools_runme.rb index 2f6a49b19..ef118b269 100644 --- a/Examples/test-suite/ruby/bools_runme.rb +++ b/Examples/test-suite/ruby/bools_runme.rb @@ -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 diff --git a/Examples/test-suite/ruby/director_exception_runme.rb b/Examples/test-suite/ruby/director_exception_runme.rb index 0d91a4f2e..ec6559b2a 100644 --- a/Examples/test-suite/ruby/director_exception_runme.rb +++ b/Examples/test-suite/ruby/director_exception_runme.rb @@ -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 diff --git a/Examples/test-suite/ruby/primitive_types_runme.rb b/Examples/test-suite/ruby/primitive_types_runme.rb new file mode 100644 index 000000000..35c380826 --- /dev/null +++ b/Examples/test-suite/ruby/primitive_types_runme.rb @@ -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 diff --git a/Examples/test-suite/tcl/Makefile.in b/Examples/test-suite/tcl/Makefile.in index c94f98195..37f65f164 100644 --- a/Examples/test-suite/tcl/Makefile.in +++ b/Examples/test-suite/tcl/Makefile.in @@ -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 diff --git a/Examples/test-suite/tcl/bools_runme.tcl b/Examples/test-suite/tcl/bools_runme.tcl index 92aeb99ec..582b8121f 100644 --- a/Examples/test-suite/tcl/bools_runme.tcl +++ b/Examples/test-suite/tcl/bools_runme.tcl @@ -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 } diff --git a/Examples/test-suite/tcl/enum_thorough_runme.tcl b/Examples/test-suite/tcl/enum_thorough_runme.tcl index 3457bfe4b..d4cc1995a 100644 --- a/Examples/test-suite/tcl/enum_thorough_runme.tcl +++ b/Examples/test-suite/tcl/enum_thorough_runme.tcl @@ -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" } diff --git a/Examples/test-suite/tcl/overload_simple_runme.tcl b/Examples/test-suite/tcl/overload_simple_runme.tcl index e5e7b6f2d..38e6dd1dc 100644 --- a/Examples/test-suite/tcl/overload_simple_runme.tcl +++ b/Examples/test-suite/tcl/overload_simple_runme.tcl @@ -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 } diff --git a/Examples/test-suite/tcl/primitive_types_runme.tcl b/Examples/test-suite/tcl/primitive_types_runme.tcl new file mode 100644 index 000000000..f10e1b0cb --- /dev/null +++ b/Examples/test-suite/tcl/primitive_types_runme.tcl @@ -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" } + + + |