Merge trunk (up to just after swig 2.0.5 release - rev 13009) to gsoc2008-cherylfoil

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@13017 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-04-27 18:55:37 +00:00
commit af1c6ac3c3
113 changed files with 95013 additions and 36002 deletions

View file

@ -9,11 +9,7 @@ else
endif
LANGUAGE = python
ifneq (,$(USE_VALGRIND))
PYTHON = valgrind --leak-check=full --suppressions=pyswig.supp $(PYBIN)
else
PYTHON = $(PYBIN)
endif
PYTHON = $(PYBIN)
#*_runme.py for Python 2.x, *_runme3.py for Python 3.x
PY2SCRIPTSUFFIX = _runme.py
@ -30,51 +26,59 @@ top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
#Use the tricky command because we want to disable the "import" fixer,
#but currently 2to3 has no option to let us do it
PY2TO3 = 2to3 `2to3 -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'`
PY2TO3 = 2to3 -x import
CPP_TEST_CASES += \
abstractbase \
argcargvtest \
autodoc \
callback \
complextest \
director_stl \
director_wstring \
file_test \
iadd \
inout \
input \
inplaceadd \
implicittest \
kwargs \
inout \
inplaceadd \
input \
kwargs_feature \
li_cstring \
li_cwstring \
li_factory \
li_implicit \
li_std_vectora \
li_std_map \
li_std_containers_int \
li_std_map_member \
li_std_multimap \
li_std_pair_extra \
li_std_set \
li_std_stream \
li_std_string_extra \
li_std_vectora \
li_std_vector_extra \
li_std_wstream \
li_std_wstring \
nondynamic \
overload_simple_cast \
primitive_types \
python_abstractbase \
python_append \
python_director \
python_nondynamic \
python_overload_simple_cast \
python_richcompare \
simutry \
std_containers \
swigobject \
template_matrix \
simutry \
vector
template_matrix
# li_std_carray
# director_profile
# python_pybuf
C_TEST_CASES += \
file_test \
li_cstring \
li_cwstring \
nondynamic
python_nondynamic \
python_varargs_typemap
#
# This test only works with modern C compilers
@ -84,10 +88,26 @@ C_TEST_CASES += \
include $(srcdir)/../common.mk
BUILTIN_BROKEN = \
default_constructor.cpptest \
director_exception.cpptest \
exception_order.cpptest \
li_std_string_extra.cpptest \
li_std_wstring.cpptest \
python_abstractbase.cpptest \
threads_exception.cpptest
BUILTIN_NOT_BROKEN = $(filter-out $(BUILTIN_BROKEN),$(NOT_BROKEN_TEST_CASES))
builtin-check : $(BUILTIN_NOT_BROKEN)
# Overridden variables here
LIBS = -L.
VALGRIND_OPT += --suppressions=pythonswig.supp
# Custom tests - tests with additional commandline options
# none!
# Rules for the different types of tests
%.cpptest:
$(setup)
@ -114,33 +134,34 @@ VALGRIND_OPT += --suppressions=pythonswig.supp
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.py (or _runme3.py for Python 3) appended after the testcase name.
run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)
run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)
py2_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX)
py3_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX)
ifeq (,$(PY3))
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
$(run_python);)\
fi;
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(run_python);\
fi
else
py2_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX)
py3_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX)
run_testcase = \
if [ -f $(py2_runme) ]; then ( \
$(MAKE) -f $(srcdir)/Makefile $(py3_runme) && \
$(run_python);) \
elif [ -f $(py3_runme)]; then ( \
$(run_python);) \
fi;
if [ -f $(py2_runme) ]; then \
$(MAKE) -f $(srcdir)/Makefile $(py3_runme) && $(run_python); \
elif [ -f $(py3_runme) ]; then \
$(run_python); \
fi
endif
# Clean: remove the generated .py file
%.clean:
@rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py
@rm -f $*.py;
@#We only remove the _runme3.py if it is generated by 2to3 from a _runme.py.
@if [ -f $(py2_runme) ]; then rm -f $(py3_runme) $(py3_runme).bak; fi
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile python_clean
rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py
cvsignore:
@echo '*wrap* *.pyc *.so *.dll *.exp *.lib'
@ -163,3 +184,4 @@ hugemod:
$(MAKE) hugemod_b.cpptest
sh -c "time $(PYTHON) $(hugemod_runme)"
sh -c "time $(PYTHON) $(hugemod_runme)"

View file

@ -1,18 +0,0 @@
%module abstractbase
%include <pyabc.i>
%include <std_map.i>
%include <std_multimap.i>
%include <std_set.i>
%include <std_multiset.i>
%include <std_list.i>
%include <std_vector.i>
namespace std
{
%template(Mapii) map<int, int>;
%template(Multimapii) multimap<int, int>;
%template(IntSet) set<int>;
%template(IntMultiset) multiset<int>;
%template(IntVector) vector<int>;
%template(IntList) list<int>;
}

View file

@ -1,23 +0,0 @@
%module argcargvtest
%include <argcargv.i>
%apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) }
%inline %{
int mainc(size_t argc, const char **argv)
{
return (int)argc;
}
const char* mainv(size_t argc, const char **argv, int idx)
{
return argv[idx];
}
void initializeApp(size_t argc, const char **argv, bool setPGid = true, bool isMakeline = false)
{
}
%}

View file

@ -2,16 +2,16 @@ from argcargvtest import *
largs=['hi','hola','hello']
if mainc(largs) != 3:
raise RuntimeError, "bad main typemap"
raise RuntimeError("bad main typemap")
targs=('hi','hola')
if mainv(targs,1) != 'hola':
print mainv(targs,1)
raise RuntimeError, "bad main typemap"
print(mainv(targs,1))
raise RuntimeError("bad main typemap")
targs=('hi', 'hola')
if mainv(targs,1) != 'hola':
raise RuntimeError, "bad main typemap"
raise RuntimeError("bad main typemap")
try:
error = 0
@ -20,7 +20,7 @@ try:
except TypeError:
pass
if error:
raise RuntimeError, "bad main typemap"
raise RuntimeError("bad main typemap")

View file

@ -1,95 +0,0 @@
%module(docstring="hello") autodoc
%feature("autodoc");
// especial typemap and its docs
%typemap(in) (int c, int d) "$1 =0; $2 = 0;";
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]";
// testing for different documentation levels
%feature("autodoc","0") A::func0; // names
%feature("autodoc","1") A::func1; // names + types
%feature("autodoc","2") A::func2; // extended
%feature("autodoc","3") A::func3; // extended + types
%feature("autodoc","just a string") A::func; // names
%inline {
enum Hola {
hi, hello
};
struct A
{
A(int a, short b, Hola h)
{
}
int func(int a)
{
return a;
}
int func0(int c, int d)
{
return c;
}
int func1(int c, int d)
{
return c;
}
int func2(A* c, double d = 2)
{
return 2;
}
int func3(A* c, double d = 2)
{
return 2;
}
};
}
// deleting typemaps and docs
%typemap(in) (int c, int d) ;
%typemap(doc) (int c, int d);
// docs for some parameters
%typemap(doc) int a "a: special comment for parameter a";
%typemap(doc) int b "b: another special comment for parameter b";
%callback(1) func_cb;
%inline {
struct B
{
B(int a, int b, Hola h)
{
}
int func(int c, int d)
{
return c;
}
};
int func(int c, int d) {
return c;
}
int funcio(int *INOUT) {
return 1;
}
int func_cb(int c, int d) {
return c;
}
}

View file

@ -0,0 +1,176 @@
from autodoc import *
def check(got, expected):
if expected != got:
raise RuntimeError("\n" + "Expected: [" + str(expected) + "]\n" + "Got : [" + str(got) + "]")
check(A.__doc__, "Proxy of C++ A class")
check(A.funk.__doc__, "just a string")
check(A.func0.__doc__, "func0(self, arg2, hello) -> int")
check(A.func1.__doc__, "func1(A self, short arg2, Tuple hello) -> int")
check(A.func2.__doc__, "\n"
" func2(self, arg2, hello) -> int\n"
"\n"
" Parameters:\n"
" arg2: short\n"
" hello: int tuple[2]\n"
"\n"
" "
)
check(A.func3.__doc__, "\n"
" func3(A self, short arg2, Tuple hello) -> int\n"
"\n"
" Parameters:\n"
" arg2: short\n"
" hello: int tuple[2]\n"
"\n"
" "
)
check(A.func0default.__doc__, "\n"
" func0default(self, e, arg3, hello, f=2) -> int\n"
" func0default(self, e, arg3, hello) -> int\n"
" "
)
check(A.func1default.__doc__, "\n"
" func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
" func1default(A self, A e, short arg3, Tuple hello) -> int\n"
" "
)
check(A.func2default.__doc__, "\n"
" func2default(self, e, arg3, hello, f=2) -> int\n"
"\n"
" Parameters:\n"
" e: A *\n"
" arg3: short\n"
" hello: int tuple[2]\n"
" f: double\n"
"\n"
" func2default(self, e, arg3, hello) -> int\n"
"\n"
" Parameters:\n"
" e: A *\n"
" arg3: short\n"
" hello: int tuple[2]\n"
"\n"
" "
)
check(A.func3default.__doc__, "\n"
" func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
"\n"
" Parameters:\n"
" e: A *\n"
" arg3: short\n"
" hello: int tuple[2]\n"
" f: double\n"
"\n"
" func3default(A self, A e, short arg3, Tuple hello) -> int\n"
"\n"
" Parameters:\n"
" e: A *\n"
" arg3: short\n"
" hello: int tuple[2]\n"
"\n"
" "
)
check(A.func0static.__doc__, "\n"
" func0static(e, arg2, hello, f=2) -> int\n"
" func0static(e, arg2, hello) -> int\n"
" "
)
check(A.func1static.__doc__, "\n"
" func1static(A e, short arg2, Tuple hello, double f=2) -> int\n"
" func1static(A e, short arg2, Tuple hello) -> int\n"
" "
)
check(A.func2static.__doc__, "\n"
" func2static(e, arg2, hello, f=2) -> int\n"
"\n"
" Parameters:\n"
" e: A *\n"
" arg2: short\n"
" hello: int tuple[2]\n"
" f: double\n"
"\n"
" func2static(e, arg2, hello) -> int\n"
"\n"
" Parameters:\n"
" e: A *\n"
" arg2: short\n"
" hello: int tuple[2]\n"
"\n"
" "
)
check(A.func3static.__doc__, "\n"
" func3static(A e, short arg2, Tuple hello, double f=2) -> int\n"
"\n"
" Parameters:\n"
" e: A *\n"
" arg2: short\n"
" hello: int tuple[2]\n"
" f: double\n"
"\n"
" func3static(A e, short arg2, Tuple hello) -> int\n"
"\n"
" Parameters:\n"
" e: A *\n"
" arg2: short\n"
" hello: int tuple[2]\n"
"\n"
" "
)
check(A.variable_a.__doc__, "A_variable_a_get(self) -> int")
check(A.variable_b.__doc__, "A_variable_b_get(A self) -> int")
check(A.variable_c.__doc__, "\n"
"A_variable_c_get(self) -> int\n"
"\n"
"Parameters:\n"
" self: A *\n"
"\n"
)
check(A.variable_d.__doc__, "\n"
"A_variable_d_get(A self) -> int\n"
"\n"
"Parameters:\n"
" self: A *\n"
"\n"
)
check(B.__doc__, "Proxy of C++ B class")
check(C.__init__.__doc__, "__init__(self, a, b, h) -> C")
check(D.__init__.__doc__, "__init__(D self, int a, int b, Hola h) -> D")
check(E.__init__.__doc__, "\n"
" __init__(self, a, b, h) -> E\n"
"\n"
" Parameters:\n"
" a: special comment for parameter a\n"
" b: another special comment for parameter b\n"
" h: enum Hola\n"
"\n"
" "
)
check(F.__init__.__doc__, "\n"
" __init__(F self, int a, int b, Hola h) -> F\n"
"\n"
" Parameters:\n"
" a: special comment for parameter a\n"
" b: another special comment for parameter b\n"
" h: enum Hola\n"
"\n"
" "
)
check(B.funk.__doc__, "funk(B self, int c, int d) -> int")
check(funk.__doc__, "funk(A e, short arg2, int c, int d) -> int")
check(funkdefaults.__doc__, "\n"
" funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n"
" funkdefaults(A e, short arg2, int c, int d) -> int\n"
" "
)
check(func_input.__doc__, "func_input(int * INPUT) -> int")
check(func_output.__doc__, "func_output() -> int")
check(func_inout.__doc__, "func_inout(int * INOUT) -> int")
check(banana.__doc__, "banana(S a, S b, int c, Integer d)")

View file

@ -1,72 +0,0 @@
%module callback
%callback(1) foo;
%callback(1) foof;
%callback(1) A::bar;
%callback(1) A::foom;
%callback("%s_Cb_Ptr") foo_T; // old style, still works.
%inline %{
int foo(int a) {
return a;
}
int foof(int a) {
return 3*a;
}
struct A
{
static int bar(int a) {
return 2*a;
}
int foom(int a)
{
return -a;
}
//friend int foof(int a);
};
extern "C" int foobar(int a, int (*pf)(int a)) {
return pf(a);
}
extern "C" int foobarm(int a, A ap, int (A::*pf)(int a)) {
return (ap.*pf)(a);
}
template <class T>
T foo_T(T a)
{
return a;
}
template <class T>
T foo_T(T a, T b)
{
return a + b;
}
template <class T>
T foobar_T(T a, T (*pf)(T a)) {
return pf(a);
}
template <class T>
const T& ident(const T& x) {
return x;
}
%}
%template(foo_i) foo_T<int>;
%template(foobar_i) foobar_T<int>;
%template(foo_d) foo_T<double>;
%template(foobar_d) foobar_T<double>;
%template(ident_d) ident<double>;

View 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)

View file

@ -1,61 +0,0 @@
%module complextest
%include <complex.i>
#ifdef __cplusplus
%{
#include <algorithm>
#include <functional>
#include <numeric>
%}
%include <std_vector.i>
#if 1
%template(VectorStdCplx) std::vector<std::complex<double> >;
#endif
%inline
{
std::complex<double> Conj(const std::complex<double>& a)
{
return std::conj(a);
}
std::complex<float> Conjf(const std::complex<float>& a)
{
return std::conj(a);
}
#if 1
std::vector<std::complex<double> > Copy_h(const std::vector<std::complex<double> >& a)
{
std::vector<std::complex<double> > b(a.size()/2);
std::copy(a.begin(), a.begin()+a.size()/2, b.begin());
return b;
}
#endif
}
#else
%{
%}
%inline
{
complex Conj(complex a)
{
return conj(a);
}
complex float Conjf(float complex a)
{
return conj(a);
}
}
#endif

View file

@ -0,0 +1,3 @@
from constructor_rename import *
x = RenamedConstructor()

View file

@ -133,3 +133,11 @@ try:
except:
pass
#Namespace
my = contract.myClass(1)
try:
my = contract.myClass(0)
print "Failed! constructor preassertion"
except:
pass

View file

@ -0,0 +1,7 @@
#!/usr/bin/evn python
from cpp_static import *
StaticFunctionTest.static_func()
StaticFunctionTest.static_func_2(1)
StaticFunctionTest.static_func_3(1,2)
StaticMemberTest.static_int = 10
assert StaticMemberTest.static_int == 10

View file

@ -0,0 +1,17 @@
from default_arg_values import *
d = Display()
if d.draw1() != 0:
raise RuntimeError
if d.draw1(12) != 12:
raise RuntimeError
p = createPtr(123);
if d.draw2() != 0:
raise RuntimeError
if d.draw2(p) != 123:
raise RuntimeError

View file

@ -1,3 +1,7 @@
# This test is expected to fail with -builtin option.
# It uses the old static syntax (e.g., dc.new_A() rather than dc.A()),
# which is not provided with the -builtin option.
import _default_constructor
dc = _default_constructor

View file

@ -0,0 +1,5 @@
from director_alternating import *
id = getBar().id()
if id != idFromGetBar():
raise RuntimeError, "Got wrong id: " + str(id)

View file

@ -43,7 +43,7 @@ b = launder(a)
try:
b.pong()
except TypeError, e:
if str(e) == "Swig director type mismatch in output value of type 'std::string'":
if str(e) == "SWIG director type mismatch in output value of type 'std::string'":
ok = 1
else:
print "Unexpected error message: %s" % str(e)
@ -66,11 +66,15 @@ except MyException, e:
if not ok:
raise RuntimeError
# This is expected to fail with -builtin option
# Throwing builtin classes as exceptions not supported
try:
raise Exception2()
except Exception2:
pass
# This is expected to fail with -builtin option
# Throwing builtin classes as exceptions not supported
try:
raise Exception1()
except Exception1:

View file

@ -1,64 +0,0 @@
%module(directors="1") director_profile
%include std_string.i
%feature("director") B;
%inline %{
class A {
public:
A() {}
};
class B
{
A aa;
public:
B() {}
virtual A fn(const A* a) {
return *a;
}
virtual int vfi(int a) {
return a + 1;
}
int fi(int a) {
return vfi(a);
}
int fj(const A* a) {
return 10;
}
B* fk(int i) {
return this;
}
const char* fl(int i) {
return "hello";
}
virtual ~B()
{
}
static B* get_self(B *b)
{
return b;
}
virtual std::string vfs(const std::string& a) {
return a;
}
std::string fs(const std::string& a) {
return vfs(a);
}
};
%}

View file

@ -12,11 +12,16 @@ class FooBar2(Bar):
def pang(self):
return "FooBar2::pang();"
class FooBar3(Bar):
def cheer(self):
return "FooBar3::cheer();"
b = Bar()
f = b.create()
fb = FooBar()
fb2 = FooBar2()
fb3 = FooBar3()
try:
@ -66,7 +71,7 @@ try:
except:
pass
if not protected:
raise RuntimeError,"Boo::ping is protected"
raise RuntimeError,"Foo::ping is protected"
protected=1
try:
@ -86,3 +91,39 @@ except:
pass
if not protected:
raise RuntimeError,"FooBar::pang is protected"
protected=1
try:
b.cheer()
protected=0
except:
pass
if not protected:
raise RuntimeError,"Bar::cheer is protected"
protected=1
try:
f.cheer()
protected=0
except:
pass
if not protected:
raise RuntimeError,"Foo::cheer is protected"
if fb3.cheer() != "FooBar3::cheer();":
raise RuntimeError, "bad fb3::cheer"
if fb2.callping() != "FooBar2::ping();":
raise RuntimeError, "bad fb2.callping"
if fb2.callcheer() != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();":
raise RuntimeError, "bad fb2.callcheer"
if fb3.callping() != "Bar::ping();":
raise RuntimeError, "bad fb3.callping"
if fb3.callcheer() != "FooBar3::cheer();":
raise RuntimeError, "bad fb3.callcheer"

View file

@ -1,76 +0,0 @@
%module(directors="1") director_stl
#pragma SWIG nowarn=SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR
%include "std_string.i"
%include "std_pair.i"
%include "std_vector.i"
#ifndef SWIG_STD_DEFAULT_INSTANTIATION
%template() std::vector<double>;
%template() std::vector<int>;
%template() std::vector<std::string>;
%template() std::pair<std::string, int>;
%template() std::pair<int,double>;
%template() std::pair<double,int>;
#endif
%feature("director") Foo;
%feature("director:except") {
if ($error != NULL) {
throw Swig::DirectorMethodException();
}
}
%exception {
try { $action }
catch (...) { SWIG_fail; }
}
%inline
{
class Foo {
public:
virtual ~Foo() {}
virtual std::string& bar(std::string& s)
{
return s;
}
virtual std::string ping(std::string s) = 0;
virtual std::string pong(const std::string& s)
{ return std::string("Foo::pong:") + s + ":" + ping(s); }
std::string tping(std::string s) { return ping(s); }
std::string tpong(const std::string& s) { return pong(s); }
virtual std::pair<double, int>
pident(const std::pair<double, int>& p) { return p; }
virtual std::vector<int>
vident(const std::vector<int>& p) { return p; }
virtual std::vector<int>
vsecond(const std::vector<int>& p, const std::vector<int>& s) { return s; }
std::pair<double, int>
tpident(const std::pair<double, int>& p) { return pident(p); }
std::vector<int>
tvident(const std::vector<int>& p) { return vident(p); }
virtual std::vector<int>
tvsecond(const std::vector<int>& p, const std::vector<int>& s) { return vsecond(p,s); }
virtual std::vector<std::string>
vidents(const std::vector<std::string>& p) { return p; }
std::vector<std::string>
tvidents(const std::vector<std::string>& p) { return vidents(p); }
};
}

View file

@ -14,3 +14,5 @@ d.run()
if d.val >= 0:
print d.val
raise RuntimeError
d.stop()

Some files were not shown because too many files have changed in this diff Show more