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:
commit
af1c6ac3c3
1811 changed files with 94580 additions and 35569 deletions
|
|
@ -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)"
|
||||
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
}
|
||||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
%}
|
||||
|
|
@ -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")
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
176
Examples/test-suite/python/autodoc_runme.py
Normal file
176
Examples/test-suite/python/autodoc_runme.py
Normal 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)")
|
||||
|
|
@ -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>;
|
||||
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)
|
||||
|
||||
|
|
@ -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
|
||||
3
Examples/test-suite/python/constructor_rename_runme.py
Normal file
3
Examples/test-suite/python/constructor_rename_runme.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from constructor_rename import *
|
||||
|
||||
x = RenamedConstructor()
|
||||
|
|
@ -133,3 +133,11 @@ try:
|
|||
except:
|
||||
pass
|
||||
|
||||
#Namespace
|
||||
my = contract.myClass(1)
|
||||
try:
|
||||
my = contract.myClass(0)
|
||||
print "Failed! constructor preassertion"
|
||||
except:
|
||||
pass
|
||||
|
||||
|
|
|
|||
7
Examples/test-suite/python/cpp_static_runme.py
Normal file
7
Examples/test-suite/python/cpp_static_runme.py
Normal 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
|
||||
17
Examples/test-suite/python/default_arg_values_runme.py
Normal file
17
Examples/test-suite/python/default_arg_values_runme.py
Normal 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
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
5
Examples/test-suite/python/director_alternating_runme.py
Normal file
5
Examples/test-suite/python/director_alternating_runme.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from director_alternating import *
|
||||
|
||||
id = getBar().id()
|
||||
if id != idFromGetBar():
|
||||
raise RuntimeError, "Got wrong id: " + str(id)
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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); }
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -14,3 +14,5 @@ d.run()
|
|||
if d.val >= 0:
|
||||
print d.val
|
||||
raise RuntimeError
|
||||
|
||||
d.stop()
|
||||
|
|
|
|||
|
|
@ -5,3 +5,15 @@ _enums.bar2(1)
|
|||
_enums.bar3(1)
|
||||
_enums.bar1(1)
|
||||
|
||||
if _enums.cvar.enumInstance != 2:
|
||||
raise RuntimeError
|
||||
|
||||
if _enums.cvar.Slap != 10:
|
||||
raise RuntimeError
|
||||
|
||||
if _enums.cvar.Mine != 11:
|
||||
raise RuntimeError
|
||||
|
||||
if _enums.cvar.Thigh != 12:
|
||||
raise RuntimeError
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from exception_order import *
|
||||
|
||||
# This test is expected to fail with -builtin option.
|
||||
# Throwing builtin classes as exceptions not supported
|
||||
|
||||
a = A()
|
||||
|
||||
|
|
|
|||
4
Examples/test-suite/python/extern_c_runme.py
Normal file
4
Examples/test-suite/python/extern_c_runme.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import extern_c
|
||||
|
||||
extern_c.RealFunction(2)
|
||||
|
||||
9
Examples/test-suite/python/funcptr_cpp_runme.py
Normal file
9
Examples/test-suite/python/funcptr_cpp_runme.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from funcptr_cpp import *
|
||||
|
||||
if call1(ADD_BY_VALUE, 10, 11) != 21:
|
||||
raise RuntimeError
|
||||
if call2(ADD_BY_POINTER, 12, 13) != 25:
|
||||
raise RuntimeError
|
||||
if call3(ADD_BY_REFERENCE, 14, 15) != 29:
|
||||
raise RuntimeError
|
||||
|
||||
40
Examples/test-suite/python/global_namespace_runme.py
Normal file
40
Examples/test-suite/python/global_namespace_runme.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from global_namespace import *
|
||||
|
||||
k1 = Klass1()
|
||||
k2 = Klass2()
|
||||
k3 = Klass3()
|
||||
k4 = Klass4()
|
||||
k5 = Klass5()
|
||||
k6 = Klass6()
|
||||
k7 = Klass7()
|
||||
|
||||
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
|
||||
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
|
||||
|
||||
k1 = getKlass1A()
|
||||
k2 = getKlass2A()
|
||||
k3 = getKlass3A()
|
||||
k4 = getKlass4A()
|
||||
k5 = getKlass5A()
|
||||
k6 = getKlass6A()
|
||||
k7 = getKlass7A()
|
||||
|
||||
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
|
||||
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
|
||||
|
||||
k1 = getKlass1B()
|
||||
k2 = getKlass2B()
|
||||
k3 = getKlass3B()
|
||||
k4 = getKlass4B()
|
||||
k5 = getKlass5B()
|
||||
k6 = getKlass6B()
|
||||
k7 = getKlass7B()
|
||||
|
||||
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
|
||||
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
|
||||
|
||||
XYZMethods.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
|
||||
XYZMethods.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
|
||||
|
||||
TheEnumMethods.methodA(theenum1, theenum2, theenum3)
|
||||
TheEnumMethods.methodA(theenum1, theenum2, theenum3)
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
from global_ns_arg import *
|
||||
|
||||
a = foo(1)
|
||||
b = bar()
|
||||
b = bar_fn()
|
||||
|
||||
|
|
|
|||
|
|
@ -11,3 +11,4 @@ if x != -37:
|
|||
raise RuntimeError
|
||||
|
||||
grouping.cvar.test3 = 42
|
||||
grouping.test3 = 42
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
struct B {
|
||||
int x;
|
||||
B(const int x) : x(x) {}
|
||||
|
||||
B& get_me()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
B& operator+=(const B& a) {
|
||||
x += a.x;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace test {
|
||||
|
||||
struct A {
|
||||
int x;
|
||||
A(const int x) : x(x) {}
|
||||
|
||||
A& get_me()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
A operator+=(const A& a) {
|
||||
x += a.x;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
Foo(): _a(new A(5)), _n(new long) {}
|
||||
~Foo() { delete _a; delete _n; _a = NULL; _n = NULL; }
|
||||
|
||||
A & AsA() const { return *_a; }
|
||||
long& AsLong() const { return *_n; }
|
||||
private:
|
||||
A *_a;
|
||||
long *_n;
|
||||
};
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
%module iadd
|
||||
|
||||
%include attribute.i
|
||||
%{
|
||||
#include "iadd.h"
|
||||
%}
|
||||
class Foo;
|
||||
%attribute_ref(test::Foo, test::A& , AsA);
|
||||
%attribute_ref(test::Foo, long, AsLong);
|
||||
|
||||
|
||||
%include "iadd.h"
|
||||
0
Examples/test-suite/python/iadd_runme.py
Executable file → Normal file
0
Examples/test-suite/python/iadd_runme.py
Executable file → Normal file
|
|
@ -1,68 +0,0 @@
|
|||
%module(naturalvar="1") implicittest
|
||||
|
||||
%implicitconv;
|
||||
|
||||
%inline
|
||||
{
|
||||
struct B { };
|
||||
}
|
||||
|
||||
%inline
|
||||
{
|
||||
struct A
|
||||
{
|
||||
int ii;
|
||||
A(int i) { ii = 1; }
|
||||
A(double d) { ii = 2; }
|
||||
A(const B& b) { ii = 3; }
|
||||
explicit A(char *s) { ii = 4; }
|
||||
|
||||
int get() const { return ii; }
|
||||
|
||||
};
|
||||
|
||||
int get(const A& a) { return a.ii; }
|
||||
|
||||
template <class T>
|
||||
struct A_T
|
||||
{
|
||||
int ii;
|
||||
A_T(int i) { ii = 1; }
|
||||
A_T(double d) { ii = 2; }
|
||||
A_T(const B& b) { ii = 3; }
|
||||
explicit A_T(char *s) { ii = 4; }
|
||||
|
||||
int get() const { return ii; }
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
%inline
|
||||
{
|
||||
struct Foo
|
||||
{
|
||||
int ii;
|
||||
Foo(){ ii = 0;}
|
||||
Foo(int){ ii = 1;}
|
||||
Foo(double){ ii = 2;}
|
||||
explicit Foo(char *s){ii = 3;}
|
||||
Foo(const Foo& f){ ii = f.ii;}
|
||||
|
||||
};
|
||||
|
||||
struct Bar
|
||||
{
|
||||
int ii;
|
||||
Foo f;
|
||||
Bar() {ii = -1;}
|
||||
Bar(const Foo& ff){ ii = ff.ii;}
|
||||
};
|
||||
|
||||
|
||||
int get_b(const Bar&b) { return b.ii; }
|
||||
|
||||
Foo foo;
|
||||
|
||||
}
|
||||
|
||||
%template(A_int) A_T<int>;
|
||||
7
Examples/test-suite/python/import_stl_runme.py
Normal file
7
Examples/test-suite/python/import_stl_runme.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import import_stl_b
|
||||
import import_stl_a
|
||||
|
||||
v_new = import_stl_b.process_vector([1,2,3])
|
||||
if v_new != (1,2,3,4):
|
||||
raise RuntimeError, v_new
|
||||
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
%module inout
|
||||
|
||||
%include "typemaps.i"
|
||||
%include "std_pair.i"
|
||||
|
||||
%{
|
||||
inline void AddOne3(double* a, double* b, double* c) {
|
||||
*a += 1;
|
||||
*b += 1;
|
||||
*c += 1;
|
||||
}
|
||||
|
||||
inline void AddOne1(double* a) {
|
||||
*a += 1;
|
||||
}
|
||||
|
||||
inline void AddOne1p(std::pair<double, double>* p) {
|
||||
p->first += 1;
|
||||
p->second += 1;
|
||||
}
|
||||
|
||||
inline void AddOne2p(std::pair<double, double>* p,double* a) {
|
||||
*a += 1;
|
||||
p->first += 1;
|
||||
p->second += 1;
|
||||
}
|
||||
|
||||
inline void AddOne3p(double* a, std::pair<double, double>* p,double* b) {
|
||||
*a += 1;
|
||||
*b += 1;
|
||||
p->first += 1;
|
||||
p->second += 1;
|
||||
}
|
||||
|
||||
inline void AddOne1r(double& a) {
|
||||
a += 1;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%template() std::pair<double, double>;
|
||||
|
||||
void AddOne1(double* INOUT);
|
||||
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);
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
%module inplaceadd
|
||||
%{
|
||||
#include <iostream>
|
||||
%}
|
||||
|
||||
|
||||
%inline %{
|
||||
struct A
|
||||
{
|
||||
int val;
|
||||
|
||||
A(int v): val(v)
|
||||
{
|
||||
}
|
||||
|
||||
A& operator+=(int v)
|
||||
{
|
||||
val += v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A& operator+=(const A& a)
|
||||
{
|
||||
val += a.val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A& operator-=(int v)
|
||||
{
|
||||
val -= v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A& operator*=(int v)
|
||||
{
|
||||
val *= v;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
%module input
|
||||
|
||||
%apply int *INPUT {int *bar};
|
||||
|
||||
%typemap(out, fragment=SWIG_From_frag(int)) int *foo {
|
||||
if ($1) {
|
||||
$result = SWIG_From(int)(*$1);
|
||||
} else {
|
||||
$result = SWIG_Py_Void();
|
||||
}
|
||||
}
|
||||
|
||||
%inline
|
||||
{
|
||||
struct Foo {
|
||||
int *foo(int *bar = 0) {
|
||||
if (bar) {
|
||||
*bar *= 2;
|
||||
}
|
||||
return (bar) ? bar : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
%include std_string.i
|
||||
%apply std::string *INPUT {std::string *bar};
|
||||
|
||||
%typemap(out, fragment=SWIG_From_frag(std::string)) std::string *sfoo {
|
||||
if ($1) {
|
||||
$result = SWIG_From(std::string)(*$1);
|
||||
} else {
|
||||
$result = SWIG_Py_Void();
|
||||
}
|
||||
}
|
||||
|
||||
%inline %{
|
||||
std::string *sfoo(std::string *bar = 0) {
|
||||
if (bar) *bar += " world";
|
||||
return (bar) ? bar : 0;
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
%module kwargs
|
||||
|
||||
%nocopyctor;
|
||||
%kwargs;
|
||||
|
||||
%rename(myDel) del;
|
||||
%inline
|
||||
{
|
||||
struct s { int del; };
|
||||
}
|
||||
|
||||
|
||||
// Simple class
|
||||
%extend Foo
|
||||
{
|
||||
int efoo(int a = 1, int b = 0) {return a + b; }
|
||||
static int sfoo(int a = 1, int b = 0) { return a + b; }
|
||||
}
|
||||
|
||||
%newobject Foo::create;
|
||||
|
||||
%inline %{
|
||||
|
||||
struct Foo
|
||||
{
|
||||
Foo(int a, int b = 0) {}
|
||||
|
||||
virtual int foo(int a = 1, int b = 0) {return a + b; }
|
||||
static int statfoo(int a = 1, int b = 0) {return a + b; }
|
||||
|
||||
static Foo *create(int a = 1, int b = 0)
|
||||
{
|
||||
return new Foo(a, b);
|
||||
}
|
||||
|
||||
virtual ~Foo() {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
|
||||
// Templated class
|
||||
%extend Bar
|
||||
{
|
||||
T ebar(T a = 1, T b = 0) {return a + b; }
|
||||
static T sbar(T a = 1, T b = 0) { return a + b; }
|
||||
}
|
||||
|
||||
%inline %{
|
||||
template <typename T> struct Bar
|
||||
{
|
||||
Bar(T a, T b = 0){}
|
||||
|
||||
T bar(T a = 1, T b = 0) {return a + b; }
|
||||
static T statbar(T a = 1, T b = 0) {return a + b; }
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
%template(BarInt) Bar<int>;
|
||||
|
||||
|
||||
// Functions
|
||||
%inline %{
|
||||
int foo(int a = 1, int b = 0) {return a + b; }
|
||||
|
||||
|
||||
template<typename T> T templatedfunction(T a = 1, T b = 0) { return a + b; }
|
||||
%}
|
||||
|
||||
%template(templatedfunction) templatedfunction<int>;
|
||||
|
||||
|
||||
// Deafult args with references
|
||||
%inline
|
||||
%{
|
||||
|
||||
typedef int size_type;
|
||||
|
||||
struct Hello
|
||||
{
|
||||
static const size_type hello = 3;
|
||||
};
|
||||
|
||||
|
||||
|
||||
int rfoo( const size_type& x = Hello::hello, const Hello& y = Hello() )
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
%}
|
||||
%{
|
||||
const int Hello::hello;
|
||||
%}
|
||||
|
||||
|
||||
// Functions with keywords
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD);
|
||||
%inline %{
|
||||
/* silently rename the parameter names in python */
|
||||
|
||||
int foo_kw(int from = 1, int except = 2) {return from + except; }
|
||||
|
||||
|
||||
int foo_nu(int from = 1, int = 0) {return from; }
|
||||
|
||||
int foo_mm(int min = 1, int max = 2) {return min + max; }
|
||||
|
||||
%}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from kwargs import *
|
||||
from kwargs_feature import *
|
||||
|
||||
class MyFoo(Foo):
|
||||
def __init__(self, a , b = 0):
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
# Ported to C# li_attribute_runme.cs
|
||||
|
||||
import li_attribute
|
||||
|
||||
aa = li_attribute.A(1,2,3)
|
||||
|
|
@ -9,7 +11,6 @@ if aa.a != 3:
|
|||
print aa.a
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
if aa.b != 2:
|
||||
print aa.b
|
||||
raise RuntimeError
|
||||
|
|
@ -17,8 +18,6 @@ aa.b = 5
|
|||
if aa.b != 5:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
|
||||
if aa.d != aa.b:
|
||||
raise RuntimeError
|
||||
|
||||
|
|
@ -36,17 +35,40 @@ pi.value=3
|
|||
if pi.value != 3:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
b = li_attribute.B(aa)
|
||||
|
||||
if b.a.c != 3:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
myFoo = li_attribute.MyFoo
|
||||
# class/struct attribute with get/set methods using return/pass by reference
|
||||
myFoo = li_attribute.MyFoo()
|
||||
myFoo.x = 8
|
||||
myClass = li_attribute.MyClass
|
||||
myClass = li_attribute.MyClass()
|
||||
myClass.Foo = myFoo
|
||||
if myClass.Foo.x != 8:
|
||||
raise RuntimeError
|
||||
|
||||
# class/struct attribute with get/set methods using return/pass by value
|
||||
myClassVal = li_attribute.MyClassVal()
|
||||
if myClassVal.ReadWriteFoo.x != -1:
|
||||
raise RuntimeError
|
||||
if myClassVal.ReadOnlyFoo.x != -1:
|
||||
raise RuntimeError
|
||||
myClassVal.ReadWriteFoo = myFoo
|
||||
if myClassVal.ReadWriteFoo.x != 8:
|
||||
raise RuntimeError
|
||||
if myClassVal.ReadOnlyFoo.x != 8:
|
||||
raise RuntimeError
|
||||
|
||||
# string attribute with get/set methods using return/pass by value
|
||||
myStringyClass = li_attribute.MyStringyClass("initial string")
|
||||
if myStringyClass.ReadWriteString != "initial string":
|
||||
raise RuntimeError
|
||||
if myStringyClass.ReadOnlyString != "initial string":
|
||||
raise RuntimeError
|
||||
myStringyClass.ReadWriteString = "changed string"
|
||||
if myStringyClass.ReadWriteString != "changed string":
|
||||
raise RuntimeError
|
||||
if myStringyClass.ReadOnlyString != "changed string":
|
||||
raise RuntimeError
|
||||
|
||||
|
|
|
|||
|
|
@ -18,3 +18,17 @@ check(nd)
|
|||
b = boing(nd)
|
||||
check(b)
|
||||
|
||||
################################
|
||||
|
||||
v = VectorIntHolder()
|
||||
v.push_back(IntHolder(11))
|
||||
v.push_back(IntHolder(22))
|
||||
v.push_back(IntHolder(33))
|
||||
|
||||
sum = sum(v)
|
||||
if sum != 66:
|
||||
raise "sum is wrong"
|
||||
|
||||
################################
|
||||
p = HiddenDestructor.create()
|
||||
|
||||
|
|
|
|||
|
|
@ -304,6 +304,15 @@ class li_boost_shared_ptr_runme:
|
|||
self.verifyValue(li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr")
|
||||
self.verifyValue(li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref")
|
||||
|
||||
# 3rd derived class
|
||||
k = li_boost_shared_ptr.Klass3rdDerived("me oh my")
|
||||
val = k.getValue()
|
||||
self.verifyValue("me oh my-3rdDerived", val)
|
||||
self.verifyCount(1, k)
|
||||
val = li_boost_shared_ptr.test3rdupcast(k)
|
||||
self.verifyValue("me oh my-3rdDerived", val)
|
||||
self.verifyCount(1, k)
|
||||
|
||||
# //////////////////////////////// Member variables ////////////////////////////////////////
|
||||
# smart pointer by value
|
||||
m = li_boost_shared_ptr.MemberVariables()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
from li_boost_shared_ptr_template import *
|
||||
|
||||
b = BaseINTEGER()
|
||||
d = DerivedINTEGER()
|
||||
if b.bar() != 1:
|
||||
raise RuntimeError
|
||||
if d.bar() != 2:
|
||||
raise RuntimeError
|
||||
if bar_getter(b) != 1:
|
||||
raise RuntimeError
|
||||
# Fix reverted in rev 12953
|
||||
#if bar_getter(d) != 2:
|
||||
# raise RuntimeError
|
||||
|
||||
b = BaseDefaultInt()
|
||||
d = DerivedDefaultInt()
|
||||
d2 = DerivedDefaultInt2()
|
||||
if b.bar2() != 3:
|
||||
raise RuntimeError
|
||||
if d.bar2() != 4:
|
||||
raise RuntimeError
|
||||
if d2.bar2() != 4:
|
||||
raise RuntimeError
|
||||
if bar2_getter(b) != 3:
|
||||
raise RuntimeError
|
||||
# Fix reverted in rev 12953
|
||||
#if bar2_getter(d) != 4:
|
||||
# raise RuntimeError
|
||||
#if bar2_getter(d2) != 4:
|
||||
# raise RuntimeError
|
||||
10
Examples/test-suite/python/li_cdata_runme.py
Normal file
10
Examples/test-suite/python/li_cdata_runme.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
from li_cdata import *
|
||||
|
||||
s = "ABC abc"
|
||||
m = malloc(256)
|
||||
memmove(m, s)
|
||||
ss = cdata(m, 7)
|
||||
if ss != "ABC abc":
|
||||
raise "failed"
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
%module li_std_carray
|
||||
|
||||
%include <std_carray.i>
|
||||
|
||||
%template(Vector3) std::carray<double, 3>;
|
||||
|
||||
%template(Matrix3) std::carray<std::carray<double, 3>, 3>;
|
||||
|
||||
265
Examples/test-suite/python/li_std_containers_int_runme.py
Normal file
265
Examples/test-suite/python/li_std_containers_int_runme.py
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
# Check std::vector and std::list behaves the same as Python iterable types (list)
|
||||
|
||||
from li_std_containers_int import *
|
||||
|
||||
def failed(a, b, msg):
|
||||
raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b))
|
||||
|
||||
def compare_sequences(a, b):
|
||||
if len(a) != len(b):
|
||||
failed(a, b, "different sizes")
|
||||
for i in range(len(a)):
|
||||
if a[i] != b[i]:
|
||||
failed(a, b, "elements are different")
|
||||
|
||||
def compare_containers(pythonlist, swigvector, swiglist):
|
||||
compare_sequences(pythonlist, swigvector)
|
||||
compare_sequences(pythonlist, swiglist)
|
||||
|
||||
# Check std::vector and std::list assignment behaves same as Python list assignment including exceptions
|
||||
def container_insert_step(i, j, step, newval):
|
||||
ps = range(6)
|
||||
iv = vector_int(ps)
|
||||
il = list_int(ps)
|
||||
|
||||
# Python slice
|
||||
try:
|
||||
if step == None:
|
||||
if j == None:
|
||||
ps[i] = newval
|
||||
else:
|
||||
ps[i:j] = newval
|
||||
else:
|
||||
if j == None:
|
||||
ps[i::step] = newval
|
||||
else:
|
||||
ps[i:j:step] = newval
|
||||
ps_error = None
|
||||
except ValueError, e:
|
||||
ps_error = e
|
||||
except IndexError, e:
|
||||
ps_error = e
|
||||
|
||||
# std::vector<int>
|
||||
try:
|
||||
if step == None:
|
||||
if j == None:
|
||||
iv[i] = newval
|
||||
else:
|
||||
iv[i:j] = newval
|
||||
else:
|
||||
if j == None:
|
||||
iv[i::step] = newval
|
||||
else:
|
||||
iv[i:j:step] = newval
|
||||
iv_error = None
|
||||
except ValueError, e:
|
||||
iv_error = e
|
||||
except IndexError, e:
|
||||
iv_error = e
|
||||
|
||||
# std::list<int>
|
||||
try:
|
||||
if step == None:
|
||||
if j == None:
|
||||
il[i] = newval
|
||||
else:
|
||||
il[i:j] = newval
|
||||
else:
|
||||
if j == None:
|
||||
il[i::step] = newval
|
||||
else:
|
||||
il[i:j:step] = newval
|
||||
il_error = None
|
||||
except ValueError, e:
|
||||
il_error = e
|
||||
except IndexError, e:
|
||||
il_error = e
|
||||
|
||||
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
|
||||
raise RuntimeError, "ValueError exception not consistently thrown: " + str(ps_error) + " " + str(iv_error) + " " + str(il_error)
|
||||
|
||||
compare_containers(ps, iv, il)
|
||||
|
||||
|
||||
# Check std::vector and std::list delete behaves same as Python list delete including exceptions
|
||||
def container_delete_step(i, j, step):
|
||||
ps = range(6)
|
||||
iv = vector_int(ps)
|
||||
il = list_int(ps)
|
||||
|
||||
# Python slice
|
||||
try:
|
||||
if step == None:
|
||||
if j == None:
|
||||
del ps[i]
|
||||
else:
|
||||
del ps[i:j]
|
||||
else:
|
||||
if j == None:
|
||||
del ps[i::step]
|
||||
else:
|
||||
del ps[i:j:step]
|
||||
ps_error = None
|
||||
except ValueError, e:
|
||||
ps_error = e
|
||||
except IndexError, e:
|
||||
ps_error = e
|
||||
|
||||
# std::vector<int>
|
||||
try:
|
||||
if step == None:
|
||||
if j == None:
|
||||
del iv[i]
|
||||
else:
|
||||
del iv[i:j]
|
||||
else:
|
||||
if j == None:
|
||||
del iv[i::step]
|
||||
else:
|
||||
del iv[i:j:step]
|
||||
iv_error = None
|
||||
except ValueError, e:
|
||||
iv_error = e
|
||||
except IndexError, e:
|
||||
iv_error = e
|
||||
|
||||
# std::list<int>
|
||||
try:
|
||||
if step == None:
|
||||
if j == None:
|
||||
del il[i]
|
||||
else:
|
||||
del il[i:j]
|
||||
else:
|
||||
if j == None:
|
||||
del il[i::step]
|
||||
else:
|
||||
del il[i:j:step]
|
||||
il_error = None
|
||||
except ValueError, e:
|
||||
il_error = e
|
||||
except IndexError, e:
|
||||
il_error = e
|
||||
|
||||
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
|
||||
raise RuntimeError, "ValueError exception not consistently thrown: " + str(ps_error) + " " + str(iv_error) + " " + str(il_error)
|
||||
|
||||
compare_containers(ps, iv, il)
|
||||
|
||||
|
||||
ps = [0,1,2,3,4,5]
|
||||
|
||||
iv = vector_int(ps)
|
||||
il = list_int(ps)
|
||||
|
||||
# slices
|
||||
compare_containers(ps[0:0], iv[0:0], il[0:0])
|
||||
compare_containers(ps[1:1], iv[1:1], il[1:1])
|
||||
compare_containers(ps[1:3], iv[1:3], il[1:3])
|
||||
compare_containers(ps[2:4], iv[2:4], il[2:4])
|
||||
compare_containers(ps[0:3], iv[0:3], il[0:3])
|
||||
compare_containers(ps[3:6], iv[3:6], il[3:6])
|
||||
compare_containers(ps[3:10], iv[3:10], il[3:10]) # beyond end of range
|
||||
|
||||
# before beginning of range (negative indexing)
|
||||
compare_containers(ps[-1:7], iv[-1:7], il[-1:7])
|
||||
compare_containers(ps[-2:7], iv[-2:7], il[-2:7])
|
||||
compare_containers(ps[-5:7], iv[-5:7], il[-5:7])
|
||||
compare_containers(ps[-6:7], iv[-6:7], il[-6:7])
|
||||
|
||||
# before beginning of range (negative indexing, negative index is > container size)
|
||||
compare_containers(ps[-7:7], iv[-7:7], il[-7:7])
|
||||
compare_containers(ps[-100:7], iv[-100:7], il[-100:7])
|
||||
|
||||
compare_containers(ps[3:], iv[3:], il[3:])
|
||||
compare_containers(ps[:3], iv[:3], il[:3])
|
||||
compare_containers(ps[:], iv[:], il[:])
|
||||
compare_containers(ps[-3:], iv[-3:], il[-3:])
|
||||
compare_containers(ps[-7:], iv[-7:], il[-7:])
|
||||
compare_containers(ps[:-1], iv[:-1], il[:-1])
|
||||
compare_containers(ps[:-7], iv[:-7], il[:-7])
|
||||
|
||||
# step slicing
|
||||
compare_containers(ps[1:5:1], iv[1:5:1], il[1:5:1])
|
||||
compare_containers(ps[1:5:2], iv[1:5:2], il[1:5:2])
|
||||
compare_containers(ps[1:5:3], iv[1:5:3], il[1:5:3])
|
||||
compare_containers(ps[1:5:4], iv[1:5:4], il[1:5:4])
|
||||
compare_containers(ps[1:6:5], iv[1:6:5], il[1:6:5])
|
||||
compare_containers(ps[1:7:5], iv[1:7:5], il[1:7:5])
|
||||
compare_containers(ps[-1:7:1], iv[-1:7:1], il[-1:7:1])
|
||||
compare_containers(ps[-1:7:2], iv[-1:7:2], il[-1:7:2])
|
||||
compare_containers(ps[-6:7:2], iv[-6:7:2], il[-6:7:2])
|
||||
compare_containers(ps[-100:7:2], iv[-100:7:2], il[-100:7:2])
|
||||
compare_containers(ps[::1], iv[::1], il[::1])
|
||||
compare_containers(ps[::2], iv[::2], il[::2])
|
||||
|
||||
compare_containers(ps[::-1], iv[::-1], il[::-1])
|
||||
compare_containers(ps[6::-1], iv[6::-1], il[6::-1])
|
||||
compare_containers(ps[:-3:-1], iv[:-3:-1], il[:-3:-1])
|
||||
compare_containers(ps[:-6:-1], iv[:-6:-1], il[:-6:-1])
|
||||
compare_containers(ps[:-7:-1], iv[:-7:-1], il[:-7:-1])
|
||||
compare_containers(ps[:-8:-1], iv[:-8:-1], il[:-8:-1])
|
||||
compare_containers(ps[:-100:-1], iv[:-100:-1], il[:-100:-1])
|
||||
compare_containers(ps[4:6:-1], iv[4:6:-1], il[4:6:-1])
|
||||
compare_containers(ps[4:5:-1], iv[4:5:-1], il[4:5:-1])
|
||||
compare_containers(ps[4:4:-1], iv[4:4:-1], il[4:4:-1])
|
||||
compare_containers(ps[4:3:-1], iv[4:3:-1], il[4:3:-1])
|
||||
compare_containers(ps[4:2:-1], iv[4:2:-1], il[4:2:-1])
|
||||
compare_containers(ps[100:104:-1], iv[100:104:-1], il[100:104:-1])
|
||||
compare_containers(ps[104:100:-1], iv[104:100:-1], il[104:100:-1])
|
||||
compare_containers(ps[-100:-104:-1], iv[-100:-104:-1], il[-100:-104:-1])
|
||||
compare_containers(ps[-104:-100:-1], iv[-104:-100:-1], il[-104:-100:-1])
|
||||
compare_containers(ps[::-2], iv[::-2], il[::-2])
|
||||
compare_containers(ps[::-3], iv[::-3], il[::-3])
|
||||
compare_containers(ps[::-4], iv[::-4], il[::-4])
|
||||
compare_containers(ps[::-5], iv[::-5], il[::-5])
|
||||
|
||||
|
||||
# insert sequences (growing, shrinking and staying same size)
|
||||
for start in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
|
||||
# single element set/replace
|
||||
container_insert_step(start, None, None, 111)
|
||||
for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
|
||||
container_insert_step(start, end, None, [111, 222, 333, 444, 555, 666, 777])
|
||||
container_insert_step(start, end, None, [111, 222, 333, 444, 555, 666])
|
||||
container_insert_step(start, end, None, [111, 222, 333, 444, 555])
|
||||
container_insert_step(start, end, None, [111, 222, 333, 444])
|
||||
container_insert_step(start, end, None, [111, 222, 333])
|
||||
container_insert_step(start, end, None, [111, 222])
|
||||
container_insert_step(start, end, None, [111])
|
||||
container_insert_step(start, end, None, [])
|
||||
|
||||
# delete sequences (growing, shrinking and staying same size)
|
||||
for start in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
|
||||
# single element delete
|
||||
container_delete_step(start, None, None)
|
||||
for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
|
||||
container_delete_step(start, end, None)
|
||||
for step in range(-7,7):
|
||||
container_delete_step(start, end, step)
|
||||
|
||||
ps = range(6)
|
||||
iv = vector_int(ps)
|
||||
il = list_int(ps)
|
||||
del ps[:]; del iv[:]; del il[:]
|
||||
compare_containers(ps, iv, il)
|
||||
|
||||
for end in range(7):
|
||||
for step in range(-7,7):
|
||||
for start in range(7):
|
||||
container_insert_step(start, end, step, [111, 222, 333, 444, 555, 666, 777])
|
||||
container_insert_step(start, end, step, [111, 222, 333, 444, 555, 666])
|
||||
container_insert_step(start, end, step, [111, 222, 333, 444, 555])
|
||||
container_insert_step(start, end, step, [111, 222, 333, 444])
|
||||
container_insert_step(start, end, step, [111, 222, 333])
|
||||
container_insert_step(start, end, step, [111, 222])
|
||||
container_insert_step(start, end, step, [111])
|
||||
container_insert_step(start, end, step, [])
|
||||
|
||||
try:
|
||||
x = iv[::0]
|
||||
raise RuntimeError("Zero step not caught")
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
%module("templatereduce") li_std_map
|
||||
|
||||
%include std_pair.i
|
||||
%include std_map.i
|
||||
%include std_multimap.i
|
||||
|
||||
%inline %{
|
||||
struct A{
|
||||
int val;
|
||||
|
||||
A(int v = 0): val(v)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
%}
|
||||
|
||||
namespace std
|
||||
{
|
||||
%template(pairii) pair<int, int>;
|
||||
%template(pairAA) pair<int, A>;
|
||||
%template(pairA) pair<int, A*>;
|
||||
%template(mapA) map<int, A*>;
|
||||
%template(mmapA) multimap<int, A*>;
|
||||
|
||||
%template(paircA1) pair<const int, A*>;
|
||||
%template(paircA2) pair<const int, const A*>;
|
||||
%template(pairiiA) pair<int,pair<int, A*> >;
|
||||
%template(pairiiAc) pair<int,const pair<int, A*> >;
|
||||
|
||||
|
||||
%template() pair<swig::PyObject_ptr, swig::PyObject_ptr>;
|
||||
%template(pymap) map<swig::PyObject_ptr, swig::PyObject_ptr>;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
%inline
|
||||
{
|
||||
std::pair<int, A*>
|
||||
p_identa(std::pair<int, A*> p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
std::map<int,A*> m_identa(const std::map<int,A*>& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
%template(mapii) map<int,int>;
|
||||
}
|
||||
11
Examples/test-suite/python/li_std_map_member_runme.py
Normal file
11
Examples/test-suite/python/li_std_map_member_runme.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import li_std_map_member
|
||||
|
||||
a = li_std_map_member.mapita()
|
||||
a[1] = li_std_map_member.TestA()
|
||||
|
||||
if (a[1].i != 1) :
|
||||
raise RuntimeError("a[1] != 1")
|
||||
|
||||
a[1].i = 2
|
||||
if (a[1].i != 2) :
|
||||
raise RuntimeError("a[1] != 2")
|
||||
|
|
@ -48,7 +48,7 @@ for k in pm:
|
|||
|
||||
|
||||
|
||||
mii = li_std_map.mapii()
|
||||
mii = li_std_map.IntIntMap()
|
||||
|
||||
mii[1] = 1
|
||||
mii[1] = 2
|
||||
|
|
|
|||
|
|
@ -1,210 +0,0 @@
|
|||
%module li_std_pair
|
||||
|
||||
//
|
||||
// activate the automatic comparison methods generation (==,!=,...)
|
||||
//
|
||||
|
||||
%{
|
||||
#include <algorithm> // for std::swap
|
||||
%}
|
||||
|
||||
|
||||
%include std_pair.i
|
||||
%include std_string.i
|
||||
%include std_complex.i
|
||||
|
||||
%inline
|
||||
%{
|
||||
struct A
|
||||
{
|
||||
int val;
|
||||
|
||||
A(int v = 0): val(v)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
struct B
|
||||
{
|
||||
};
|
||||
%}
|
||||
|
||||
%std_comp_methods(std::pair<std::string, int>);
|
||||
|
||||
namespace std {
|
||||
%template(CIntPair) pair<const int, const int>;
|
||||
%template() pair<double, double>;
|
||||
%template(ShortPair) pair<short, short>;
|
||||
|
||||
%template(IntPair) pair<int, int>;
|
||||
%extend pair<int, int>
|
||||
{
|
||||
%template(pair) pair<short,short>;
|
||||
}
|
||||
|
||||
|
||||
|
||||
%template(SIPair) pair<std::string, int>;
|
||||
%template(CIPair) pair<std::complex<double>, int>;
|
||||
%template(SIIPair) pair<std::pair<std::string, int>, int>;
|
||||
%template(AIntPair) pair<A, int>;
|
||||
|
||||
%template(CCIntPair) pair<const A, const pair<int, int> >;
|
||||
|
||||
%template(ABPair) pair<A, B>;
|
||||
%template(IntAPair) pair<int, A>;
|
||||
|
||||
%template(pairP1) pair<int, A*>;
|
||||
%template(pairP2) pair<A*, int>;
|
||||
%template(pairP3) pair<A*, A*>;
|
||||
%template(pairP4) pair<int, int*>;
|
||||
%template(pairP5) pair<int*, int>;
|
||||
%template(pairP6) pair<int*, int*>;
|
||||
|
||||
}
|
||||
%std_comp_methods(std::pair<std::pair<std::string, int>, int>);
|
||||
|
||||
%apply std::pair<int,int> *INOUT {std::pair<int,int> *INOUT2};
|
||||
|
||||
%inline %{
|
||||
|
||||
/* Test the "out" typemap for pair<T, U> */
|
||||
std::pair<int, int> makeIntPair(int a, int b) {
|
||||
return std::make_pair(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no "out" typemap for a pointer to a pair, so
|
||||
* this should return a wrapped instance of a std::pair
|
||||
* instead of the native "array" type for the target language.
|
||||
*/
|
||||
std::pair<int, int> * makeIntPairPtr(int a, int b) {
|
||||
static std::pair<int, int> p = std::make_pair(a, b);
|
||||
return &p;
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no "out" typemap for a non-const reference to a pair, so
|
||||
* this should return a wrapped instance of a std::pair instead of
|
||||
* the native "array" type for the target language.
|
||||
*/
|
||||
std::pair<int, int>& makeIntPairRef(int a, int b) {
|
||||
static std::pair<int, int> p = std::make_pair(a, b);
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no "out" typemap for a const reference to a pair, so
|
||||
* this should return a wrapped instance of a std::pair
|
||||
* instead of the native "array" type for the target language.
|
||||
*/
|
||||
const std::pair<int, int> & makeIntPairConstRef(int a, int b) {
|
||||
static std::pair<int, int> p = std::make_pair(a, b);
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Test the "in" typemap for pair<T, U> */
|
||||
int product1(std::pair<int, int> p) {
|
||||
return p.first*p.second;
|
||||
}
|
||||
|
||||
/* Test the "in" typemap for const pair<T, U>& */
|
||||
int product2(const std::pair<int, int>& p) {
|
||||
return p.first*p.second;
|
||||
}
|
||||
|
||||
std::pair<int, int>
|
||||
p_ident(std::pair<int, int> p, const std::pair<int, int>& q) {
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, A*>
|
||||
p_identa(const std::pair<int, A*>& p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
d_inout(double *INOUT) {
|
||||
*INOUT += *INOUT;
|
||||
}
|
||||
|
||||
void
|
||||
d_inout(int *INOUT) {
|
||||
*INOUT += *INOUT;
|
||||
}
|
||||
|
||||
int
|
||||
d_inout2(double *INOUT) {
|
||||
*INOUT += *INOUT;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
p_inout(std::pair<int, int> *INOUT) {
|
||||
std::swap(INOUT->first, INOUT->second);
|
||||
}
|
||||
|
||||
int
|
||||
p_inout2(std::pair<int, int> *INOUT) {
|
||||
std::swap(INOUT->first, INOUT->second);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
p_inout3(std::pair<int,int> *INOUT, std::pair<int,int> *INOUT2) {
|
||||
std::swap(*INOUT, *INOUT2);
|
||||
}
|
||||
|
||||
void
|
||||
p_inoutd(std::pair<double, double> *INOUT) {
|
||||
std::swap(INOUT->first, INOUT->second);
|
||||
}
|
||||
|
||||
std::string
|
||||
s_ident(const std::string& s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
#if 0
|
||||
std::pair<char, char>
|
||||
p_ident(std::pair<char, char> p, const std::pair<char, char>& q) {
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Test the "in" typemap for const pair<T, U>* */
|
||||
std::pair<A, B>
|
||||
p_ident(std::pair<A, B> p, const std::pair<A, B>& q) {
|
||||
return q;
|
||||
}
|
||||
|
||||
/* Test the "in" typemap for const pair<T, U>* */
|
||||
std::pair<int, A>
|
||||
p_ident(std::pair<int, A> p, const std::pair<int, A>& q) {
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, int>
|
||||
p_ident(std::pair<int, int> p, const std::pair<A, int>& q) {
|
||||
return p;
|
||||
}
|
||||
|
||||
std::pair<int, int>
|
||||
p_ident(std::pair<int, int> p, const std::pair<A, B>& q) {
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
%template(paircA1) pair<const int, A*>;
|
||||
%template(paircA2) pair<const int, const A*>;
|
||||
%template(pairiiA) pair<int,pair<int, A*> >;
|
||||
}
|
||||
|
||||
59
Examples/test-suite/python/li_std_pair_extra_runme.py
Normal file
59
Examples/test-suite/python/li_std_pair_extra_runme.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import li_std_pair_extra
|
||||
|
||||
p = (1,2)
|
||||
p1 = li_std_pair_extra.p_inout(p)
|
||||
p2 = li_std_pair_extra.p_inoutd(p1)
|
||||
|
||||
d1 = li_std_pair_extra.d_inout(2)
|
||||
|
||||
i,d2 = li_std_pair_extra.d_inout2(2)
|
||||
|
||||
i,p = li_std_pair_extra.p_inout2(p)
|
||||
p3,p4 = li_std_pair_extra.p_inout3(p1,p1)
|
||||
|
||||
psi = li_std_pair_extra.SIPair("hello",1)
|
||||
pci = li_std_pair_extra.CIPair(1,1)
|
||||
|
||||
|
||||
#psi.first = "hi"
|
||||
|
||||
|
||||
psi = li_std_pair_extra.SIPair("hi",1)
|
||||
if psi != ("hi",1):
|
||||
raise RuntimeError
|
||||
|
||||
psii = li_std_pair_extra.SIIPair(psi,1)
|
||||
|
||||
a = li_std_pair_extra.A()
|
||||
b = li_std_pair_extra.B()
|
||||
|
||||
pab = li_std_pair_extra.ABPair(a,b);
|
||||
|
||||
pab.first = a
|
||||
pab.first.val = 2
|
||||
|
||||
if pab.first.val != 2:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
pci = li_std_pair_extra.CIntPair(1,0)
|
||||
|
||||
a = li_std_pair_extra.A(5)
|
||||
p1 = li_std_pair_extra.pairP1(1,a.this)
|
||||
p2 = li_std_pair_extra.pairP2(a,1)
|
||||
p3 = li_std_pair_extra.pairP3(a,a)
|
||||
|
||||
|
||||
if a.val != li_std_pair_extra.p_identa(p1.this)[1].val:
|
||||
raise RuntimeError
|
||||
|
||||
p = li_std_pair_extra.IntPair(1,10)
|
||||
p.first = 1
|
||||
|
||||
p = li_std_pair_extra.paircA1(1,a)
|
||||
p.first
|
||||
p.second
|
||||
|
||||
p = li_std_pair_extra.paircA2(1,a)
|
||||
pp = li_std_pair_extra.pairiiA(1,p)
|
||||
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
import li_std_pair
|
||||
|
||||
p = (1,2)
|
||||
p1 = li_std_pair.p_inout(p)
|
||||
p2 = li_std_pair.p_inoutd(p1)
|
||||
|
||||
d1 = li_std_pair.d_inout(2)
|
||||
|
||||
i,d2 = li_std_pair.d_inout2(2)
|
||||
|
||||
i,p = li_std_pair.p_inout2(p)
|
||||
p3,p4 = li_std_pair.p_inout3(p1,p1)
|
||||
|
||||
psi = li_std_pair.SIPair("hello",1)
|
||||
pci = li_std_pair.CIPair(1,1)
|
||||
|
||||
|
||||
#psi.first = "hi"
|
||||
|
||||
|
||||
psi = li_std_pair.SIPair("hi",1)
|
||||
if psi != ("hi",1):
|
||||
raise RuntimeError
|
||||
|
||||
psii = li_std_pair.SIIPair(psi,1)
|
||||
|
||||
a = li_std_pair.A()
|
||||
b = li_std_pair.B()
|
||||
|
||||
pab = li_std_pair.ABPair(a,b);
|
||||
|
||||
pab.first = a
|
||||
pab.first.val = 2
|
||||
|
||||
if pab.first.val != 2:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
pci = li_std_pair.CIntPair(1,0)
|
||||
|
||||
a = li_std_pair.A(5)
|
||||
p1 = li_std_pair.pairP1(1,a.this)
|
||||
p2 = li_std_pair.pairP2(a,1)
|
||||
p3 = li_std_pair.pairP3(a,a)
|
||||
|
||||
|
||||
if a.val != li_std_pair.p_identa(p1.this)[1].val:
|
||||
raise RuntimeError
|
||||
|
||||
p = li_std_pair.IntPair(1,10)
|
||||
p.first = 1
|
||||
|
||||
p = li_std_pair.paircA1(1,a)
|
||||
p.first
|
||||
p.second
|
||||
|
||||
p = li_std_pair.paircA2(1,a)
|
||||
pp = li_std_pair.pairiiA(1,p)
|
||||
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
%module li_std_set
|
||||
|
||||
%include <std_string.i>
|
||||
%include <std_set.i>
|
||||
%include <std_multiset.i>
|
||||
%include <std_vector.i>
|
||||
|
||||
%template(set_string) std::set<std::string>;
|
||||
%template(set_int) std::multiset<int>;
|
||||
|
||||
|
||||
%template(v_int) std::vector<int>;
|
||||
|
||||
|
||||
|
||||
|
||||
%template(pyset) std::set<swig::PyObject_ptr>;
|
||||
|
|
@ -92,5 +92,5 @@ sum = ()
|
|||
for i in s:
|
||||
sum = sum + (i,)
|
||||
|
||||
if sum != (1, 'hello', (1, 2)):
|
||||
if (len(sum) != 3 or (not 1 in sum) or (not 'hello' in sum) or (not (1, 2) in sum)) :
|
||||
raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
%module li_std_stream
|
||||
|
||||
%inline %{
|
||||
struct A;
|
||||
%}
|
||||
|
||||
%include <std_iostream.i>
|
||||
%include <std_sstream.i>
|
||||
|
||||
|
||||
|
||||
%callback(1) A::bar;
|
||||
|
||||
%inline %{
|
||||
|
||||
struct B {
|
||||
virtual ~B()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct A : B
|
||||
{
|
||||
void __add__(int a)
|
||||
{
|
||||
}
|
||||
|
||||
void __add__(double a)
|
||||
{
|
||||
}
|
||||
|
||||
static int bar(int a){
|
||||
return a;
|
||||
}
|
||||
|
||||
static int foo(int a, int (*pf)(int a))
|
||||
{
|
||||
return pf(a);
|
||||
}
|
||||
|
||||
|
||||
std::ostream& __rlshift__(std::ostream& out)
|
||||
{
|
||||
out << "A class";
|
||||
return out;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%extend std::basic_ostream<char>{
|
||||
std::basic_ostream<char>&
|
||||
operator<<(const A& a)
|
||||
{
|
||||
*self << "A class";
|
||||
return *self;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
%module li_std_string
|
||||
|
||||
%naturalvar A;
|
||||
|
||||
|
||||
%include <std_basic_string.i>
|
||||
%include <std_string.i>
|
||||
|
||||
|
||||
%inline %{
|
||||
|
||||
struct A : std::string
|
||||
{
|
||||
A(const std::string& s) : std::string(s)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct B
|
||||
{
|
||||
B(const std::string& s) : cname(0), name(s), a(s)
|
||||
{
|
||||
}
|
||||
|
||||
char *cname;
|
||||
std::string name;
|
||||
A a;
|
||||
|
||||
};
|
||||
|
||||
|
||||
const char* test_ccvalue(const char* x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
char* test_cvalue(char* x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
std::basic_string<char> test_value_basic1(std::basic_string<char> x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
std::basic_string<char,std::char_traits<char> > test_value_basic2(std::basic_string<char,std::char_traits<char> > x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
std::basic_string<char,std::char_traits<char>,std::allocator<char> > test_value_basic3(std::basic_string<char,std::char_traits<char>,std::allocator<char> > x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%include ../li_std_string.i
|
||||
|
||||
|
|
@ -1,24 +1,24 @@
|
|||
import li_std_string
|
||||
import li_std_string_extra
|
||||
|
||||
x="hello"
|
||||
|
||||
|
||||
|
||||
if li_std_string.test_ccvalue(x) != x:
|
||||
if li_std_string_extra.test_ccvalue(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if li_std_string.test_cvalue(x) != x:
|
||||
if li_std_string_extra.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)
|
||||
if li_std_string_extra.test_value(x) != x:
|
||||
print x, li_std_string_extra.test_value(x)
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if li_std_string.test_const_reference(x) != x:
|
||||
if li_std_string_extra.test_const_reference(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
|
||||
s = li_std_string.string("he")
|
||||
s = li_std_string_extra.string("he")
|
||||
#s += "ll"
|
||||
#s.append('o')
|
||||
s = s + "llo"
|
||||
|
|
@ -30,21 +30,21 @@ if s != x:
|
|||
if s[1:4] != x[1:4]:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if li_std_string.test_value(s) != x:
|
||||
if li_std_string_extra.test_value(s) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if li_std_string.test_const_reference(s) != x:
|
||||
if li_std_string_extra.test_const_reference(s) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
a = li_std_string.A(s)
|
||||
a = li_std_string_extra.A(s)
|
||||
|
||||
if li_std_string.test_value(a) != x:
|
||||
if li_std_string_extra.test_value(a) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if li_std_string.test_const_reference(a) != x:
|
||||
if li_std_string_extra.test_const_reference(a) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
b = li_std_string.string(" world")
|
||||
b = li_std_string_extra.string(" world")
|
||||
|
||||
s = a + b
|
||||
if a + b != "hello world":
|
||||
|
|
@ -54,49 +54,53 @@ if a + b != "hello world":
|
|||
if a + " world" != "hello world":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
# This is expected to fail with -builtin option
|
||||
# Reverse operators not supported in builtin types
|
||||
if "hello" + b != "hello world":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
# This is expected to fail with -builtin option
|
||||
# Reverse operators not supported in builtin types
|
||||
c = "hello" + b
|
||||
if c.find_last_of("l") != 9:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
s = "hello world"
|
||||
|
||||
b = li_std_string.B("hi")
|
||||
b = li_std_string_extra.B("hi")
|
||||
|
||||
b.name = li_std_string.string("hello")
|
||||
b.name = li_std_string_extra.string("hello")
|
||||
if b.name != "hello":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
|
||||
b.a = li_std_string.A("hello")
|
||||
b.a = li_std_string_extra.A("hello")
|
||||
if b.a != "hello":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
|
||||
if li_std_string.test_value_basic1(x) != x:
|
||||
if li_std_string_extra.test_value_basic1(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
if li_std_string.test_value_basic2(x) != x:
|
||||
if li_std_string_extra.test_value_basic2(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
|
||||
if li_std_string.test_value_basic3(x) != x:
|
||||
if li_std_string_extra.test_value_basic3(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
|
||||
# Global variables
|
||||
s = "initial string"
|
||||
if li_std_string.cvar.GlobalString2 != "global string 2":
|
||||
if li_std_string_extra.cvar.GlobalString2 != "global string 2":
|
||||
raise RuntimeError, "GlobalString2 test 1"
|
||||
li_std_string.cvar.GlobalString2 = s
|
||||
if li_std_string.cvar.GlobalString2 != s:
|
||||
li_std_string_extra.cvar.GlobalString2 = s
|
||||
if li_std_string_extra.cvar.GlobalString2 != s:
|
||||
raise RuntimeError, "GlobalString2 test 2"
|
||||
if li_std_string.cvar.ConstGlobalString != "const global string":
|
||||
if li_std_string_extra.cvar.ConstGlobalString != "const global string":
|
||||
raise RuntimeError, "ConstGlobalString test"
|
||||
|
||||
# Member variables
|
||||
myStructure = li_std_string.Structure()
|
||||
myStructure = li_std_string_extra.Structure()
|
||||
if myStructure.MemberString2 != "member string 2":
|
||||
raise RuntimeError, "MemberString2 test 1"
|
||||
myStructure.MemberString2 = s
|
||||
|
|
@ -105,28 +109,28 @@ if myStructure.MemberString2 != s:
|
|||
if myStructure.ConstMemberString != "const member string":
|
||||
raise RuntimeError, "ConstMemberString test"
|
||||
|
||||
if li_std_string.cvar.Structure_StaticMemberString2 != "static member string 2":
|
||||
if li_std_string_extra.cvar.Structure_StaticMemberString2 != "static member string 2":
|
||||
raise RuntimeError, "StaticMemberString2 test 1"
|
||||
li_std_string.cvar.Structure_StaticMemberString2 = s
|
||||
if li_std_string.cvar.Structure_StaticMemberString2 != s:
|
||||
li_std_string_extra.cvar.Structure_StaticMemberString2 = s
|
||||
if li_std_string_extra.cvar.Structure_StaticMemberString2 != s:
|
||||
raise RuntimeError, "StaticMemberString2 test 2"
|
||||
if li_std_string.cvar.Structure_ConstStaticMemberString != "const static member string":
|
||||
if li_std_string_extra.cvar.Structure_ConstStaticMemberString != "const static member string":
|
||||
raise RuntimeError, "ConstStaticMemberString test"
|
||||
|
||||
|
||||
if li_std_string.test_reference_input("hello") != "hello":
|
||||
if li_std_string_extra.test_reference_input("hello") != "hello":
|
||||
raise RuntimeError
|
||||
s = li_std_string.test_reference_inout("hello")
|
||||
s = li_std_string_extra.test_reference_inout("hello")
|
||||
if s != "hellohello":
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
if li_std_string.stdstring_empty() != "":
|
||||
if li_std_string_extra.stdstring_empty() != "":
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
if li_std_string.c_empty() != "":
|
||||
if li_std_string_extra.c_empty() != "":
|
||||
raise RuntimeError
|
||||
|
||||
if li_std_string.c_null() != None:
|
||||
if li_std_string_extra.c_null() != None:
|
||||
raise RuntimeError
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
%module li_std_vector
|
||||
|
||||
%warnfilter(509) overloaded1;
|
||||
%warnfilter(509) overloaded2;
|
||||
|
||||
%include "std_string.i"
|
||||
%include "std_vector.i"
|
||||
%include "cpointer.i"
|
||||
%include "carrays.i"
|
||||
|
||||
%{
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
%template() vector<short>;
|
||||
%template(IntVector) vector<int>;
|
||||
%template(BoolVector) vector<bool>;
|
||||
%template() vector<string>;
|
||||
}
|
||||
|
||||
%template(DoubleVector) std::vector<double>;
|
||||
|
||||
|
||||
%template(sizeVector) std::vector<size_t>;
|
||||
%{
|
||||
template <class T>
|
||||
struct Param
|
||||
{
|
||||
T val;
|
||||
|
||||
Param(T v = 0): val(v) {
|
||||
}
|
||||
|
||||
operator T() const { return val; }
|
||||
};
|
||||
%}
|
||||
specialize_std_vector(Param<int>,PyInt_Check,PyInt_AsLong,PyInt_FromLong);
|
||||
%template(PIntVector) std::vector<Param<int> >;
|
||||
|
||||
%inline %{
|
||||
typedef float Real;
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
%template(RealVector) vector<Real>;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
|
||||
double average(std::vector<int> v) {
|
||||
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||
}
|
||||
|
||||
std::vector<Real> half(const std::vector<Real>& v) {
|
||||
std::vector<Real> w(v);
|
||||
for (std::vector<Real>::size_type i=0; i<w.size(); i++)
|
||||
w[i] /= 2.0;
|
||||
return w;
|
||||
}
|
||||
|
||||
void halve_in_place(std::vector<double>& v) {
|
||||
std::transform(v.begin(),v.end(),v.begin(),
|
||||
std::bind2nd(std::divides<double>(),2.0));
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%template(IntPtrVector) std::vector<int *>;
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
%{
|
||||
#include <iostream>
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
|
||||
namespace Test {
|
||||
struct A {
|
||||
virtual ~A() {}
|
||||
virtual int f(const int i) const = 0;
|
||||
};
|
||||
|
||||
struct B : public A {
|
||||
int val;
|
||||
|
||||
B(int i = 0) : val(i)
|
||||
{
|
||||
}
|
||||
|
||||
int f(const int i) const { return i + val; }
|
||||
};
|
||||
|
||||
|
||||
int vecAptr(const std::vector<A*>& v) {
|
||||
return v[0]->f(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<short> halfs(const std::vector<short>& v) {
|
||||
std::vector<short> w(v);
|
||||
for (std::vector<short>::size_type i=0; i<w.size(); i++)
|
||||
w[i] /= 2;
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> vecStr(std::vector<std::string> v) {
|
||||
v[0] += v[1];
|
||||
return v;
|
||||
}
|
||||
|
||||
%}
|
||||
%template(VecB) std::vector<Test::B>;
|
||||
%template(VecA) std::vector<Test::A*>;
|
||||
|
||||
%pointer_class(int,PtrInt)
|
||||
%array_functions(int,ArrInt)
|
||||
|
||||
|
||||
%template(pyvector) std::vector<swig::PyObject_ptr>;
|
||||
|
||||
namespace std {
|
||||
%template(ConstIntVector) vector<const int *>;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
std::string overloaded1(std::vector<double> vi) { return "vector<double>"; }
|
||||
std::string overloaded1(std::vector<int> vi) { return "vector<int>"; }
|
||||
std::string overloaded2(std::vector<int> vi) { return "vector<int>"; }
|
||||
std::string overloaded2(std::vector<double> vi) { return "vector<double>"; }
|
||||
std::string overloaded3(std::vector<int> *vi) { return "vector<int> *"; }
|
||||
std::string overloaded3(int i) { return "int"; }
|
||||
%}
|
||||
|
||||
24
Examples/test-suite/python/li_std_vector_enum_runme.py
Normal file
24
Examples/test-suite/python/li_std_vector_enum_runme.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import li_std_vector_enum
|
||||
|
||||
def check(a, b):
|
||||
if (a != b):
|
||||
raise RuntimeError("Not equal: ", a, b)
|
||||
|
||||
ev = li_std_vector_enum.EnumVector()
|
||||
|
||||
check(ev.nums[0], 10)
|
||||
check(ev.nums[1], 20)
|
||||
check(ev.nums[2], 30)
|
||||
|
||||
it = ev.nums.iterator()
|
||||
v = it.value()
|
||||
check(v, 10)
|
||||
it.next()
|
||||
v = it.value()
|
||||
check(v, 20)
|
||||
|
||||
expected = 10
|
||||
for val in ev.nums:
|
||||
check(val, expected)
|
||||
expected += 10
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from li_std_vector import *
|
||||
from li_std_vector_extra import *
|
||||
|
||||
iv = IntVector(4)
|
||||
for i in range(0,4):
|
||||
|
|
@ -133,3 +133,44 @@ if overloaded3(None) != "vector<int> *":
|
|||
if overloaded3(100) != "int":
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
# vector pointer checks
|
||||
ip = makeIntPtr(11)
|
||||
dp = makeDoublePtr(33.3)
|
||||
error = 0
|
||||
try:
|
||||
vi = IntPtrVector((ip, dp)) # check vector<int *> does not accept double * element
|
||||
error = 1
|
||||
except:
|
||||
pass
|
||||
|
||||
if error:
|
||||
raise RuntimeError
|
||||
|
||||
vi = IntPtrVector((ip, makeIntPtr(22)))
|
||||
if extractInt(vi[0]) != 11:
|
||||
raise RuntimeError
|
||||
|
||||
if extractInt(vi[1]) != 22:
|
||||
raise RuntimeError
|
||||
|
||||
# vector const pointer checks
|
||||
csp = makeConstShortPtr(111)
|
||||
|
||||
error = 0
|
||||
try:
|
||||
vcs = ConstShortPtrVector((csp, dp)) # check vector<const unsigned short *> does not accept double * element
|
||||
error = 1
|
||||
except:
|
||||
pass
|
||||
|
||||
if error:
|
||||
raise RuntimeError
|
||||
|
||||
vcs = ConstShortPtrVector((csp, makeConstShortPtr(222)))
|
||||
if extractConstShort(vcs[0]) != 111:
|
||||
raise RuntimeError
|
||||
|
||||
if extractConstShort(vcs[1]) != 222:
|
||||
raise RuntimeError
|
||||
|
||||
8
Examples/test-suite/python/li_std_vector_ptr_runme.py
Normal file
8
Examples/test-suite/python/li_std_vector_ptr_runme.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from li_std_vector_ptr import *
|
||||
|
||||
ip1 = makeIntPtr(11)
|
||||
ip2 = makeIntPtr(22)
|
||||
|
||||
vi = IntPtrVector((ip1, ip2))
|
||||
displayVector(vi)
|
||||
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
%module li_std_vectora
|
||||
|
||||
%include std_vectora.i
|
||||
|
||||
|
||||
%{
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
%}
|
||||
|
||||
|
||||
%template(vector_i) std::vector<int, std::allocator<int> >;
|
||||
|
||||
%template(matrix_i) std::vector<std::vector<int,std::allocator<int> >,std::allocator<std::vector<int,std::allocator<int> > > >;
|
||||
|
||||
%inline
|
||||
{
|
||||
typedef
|
||||
std::vector<std::vector<int,std::allocator<int> >,
|
||||
std::allocator<std::vector<int,std::allocator<int> > > >
|
||||
imatrix;
|
||||
|
||||
std::vector<int> vident(const std::vector<int,std::allocator<int> >& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
imatrix mident(const imatrix& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%template(DoubleVector) std::vector<double, std::allocator<double> >;
|
||||
|
||||
%inline %{
|
||||
typedef float Real;
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
%template(RealVector) vector<Real, std::allocator<Real> >;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
|
||||
double average(std::vector<int, std::allocator<int> > v) {
|
||||
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||
}
|
||||
|
||||
std::vector<Real,std::allocator<Real> >
|
||||
half(const std::vector<Real,std::allocator<Real> >& v) {
|
||||
std::vector<Real> w(v);
|
||||
for (unsigned int i=0; i<w.size(); i++)
|
||||
w[i] /= 2.0;
|
||||
return w;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%template(IntPtrVector) std::vector<int *,std::allocator<int *> >;
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
%module li_std_wstream
|
||||
|
||||
%inline %{
|
||||
struct A;
|
||||
%}
|
||||
|
||||
%include <std_wiostream.i>
|
||||
%include <std_wsstream.i>
|
||||
|
||||
|
||||
|
||||
%callback(1) A::bar;
|
||||
|
||||
%inline %{
|
||||
|
||||
struct B {
|
||||
virtual ~B()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct A : B
|
||||
{
|
||||
void __add__(int a)
|
||||
{
|
||||
}
|
||||
|
||||
void __add__(double a)
|
||||
{
|
||||
}
|
||||
|
||||
static int bar(int a){
|
||||
return a;
|
||||
}
|
||||
|
||||
static int foo(int a, int (*pf)(int a))
|
||||
{
|
||||
return pf(a);
|
||||
}
|
||||
|
||||
|
||||
std::wostream& __rlshift__(std::wostream& out)
|
||||
{
|
||||
out << "A class";
|
||||
return out;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%extend std::basic_ostream<wchar_t>{
|
||||
std::basic_ostream<wchar_t>&
|
||||
operator<<(const A& a)
|
||||
{
|
||||
*self << "A class";
|
||||
return *self;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
%module li_std_wstring
|
||||
%include <std_basic_string.i>
|
||||
%include <std_wstring.i>
|
||||
|
||||
|
||||
%inline %{
|
||||
|
||||
struct A : std::wstring
|
||||
{
|
||||
A(const std::wstring& s) : std::wstring(s)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct B
|
||||
{
|
||||
B(const std::wstring& s) : cname(0), name(s), a(s)
|
||||
{
|
||||
}
|
||||
|
||||
char *cname;
|
||||
std::wstring name;
|
||||
A a;
|
||||
|
||||
};
|
||||
|
||||
|
||||
wchar_t test_wcvalue(wchar_t x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
const wchar_t* test_ccvalue(const wchar_t* x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
wchar_t* test_cvalue(wchar_t* x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
std::wstring test_value(std::wstring x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
const std::wstring& test_const_reference(const std::wstring &x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
void test_pointer(std::wstring *x) {
|
||||
}
|
||||
|
||||
std::wstring *test_pointer_out() {
|
||||
static std::wstring x = L"x";
|
||||
return &x;
|
||||
}
|
||||
|
||||
void test_const_pointer(const std::wstring *x) {
|
||||
}
|
||||
|
||||
const std::wstring *test_const_pointer_out() {
|
||||
static std::wstring x = L"x";
|
||||
return &x;
|
||||
}
|
||||
|
||||
void test_reference(std::wstring &x) {
|
||||
}
|
||||
|
||||
std::wstring& test_reference_out() {
|
||||
static std::wstring x = L"x";
|
||||
return x;
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
void test_throw() throw(std::wstring){
|
||||
static std::wstring x = L"x";
|
||||
|
||||
throw x;
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
|
||||
|
|
@ -4,21 +4,21 @@ x=u"h"
|
|||
|
||||
if li_std_wstring.test_wcvalue(x) != x:
|
||||
print li_std_wstring.test_wcvalue(x)
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
x=u"hello"
|
||||
if li_std_wstring.test_ccvalue(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
if li_std_wstring.test_cvalue(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
if li_std_wstring.test_value(x) != x:
|
||||
print x, li_std_wstring.test_value(x)
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
if li_std_wstring.test_const_reference(x) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
|
||||
s = li_std_wstring.wstring(u"he")
|
||||
|
|
@ -26,39 +26,41 @@ s = s + u"llo"
|
|||
|
||||
if s != x:
|
||||
print s, x
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
if s[1:4] != x[1:4]:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
if li_std_wstring.test_value(s) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
if li_std_wstring.test_const_reference(s) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
a = li_std_wstring.A(s)
|
||||
|
||||
if li_std_wstring.test_value(a) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
if li_std_wstring.test_const_reference(a) != x:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
b = li_std_wstring.wstring(" world")
|
||||
|
||||
if a + b != "hello world":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
if a + " world" != "hello world":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
# This is expected to fail if -builtin is used
|
||||
if "hello" + b != "hello world":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
# This is expected to fail if -builtin is used
|
||||
c = "hello" + b
|
||||
if c.find_last_of("l") != 9:
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
s = "hello world"
|
||||
|
||||
|
|
@ -66,11 +68,11 @@ b = li_std_wstring.B("hi")
|
|||
|
||||
b.name = li_std_wstring.wstring(u"hello")
|
||||
if b.name != "hello":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
|
||||
b.a = li_std_wstring.A("hello")
|
||||
if b.a != u"hello":
|
||||
raise RuntimeError, "bad string mapping"
|
||||
raise RuntimeError("bad string mapping")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,3 +41,6 @@ memberPtr = NULLPT
|
|||
check ("Square area ", 100.0, do_op(s,AREAPT))
|
||||
check ("Square perim", 40.0, do_op(s,PERIMPT))
|
||||
|
||||
check ("Add by value", 3, call1(ADD_BY_VALUE, 1, 2))
|
||||
check ("Add by pointer", 7, call2(ADD_BY_POINTER, 3, 4))
|
||||
check ("Add by reference", 11, call3(ADD_BY_REFERENCE, 5, 6))
|
||||
|
|
|
|||
6
Examples/test-suite/python/memberin_extend_c_runme.py
Normal file
6
Examples/test-suite/python/memberin_extend_c_runme.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import memberin_extend_c
|
||||
|
||||
t = memberin_extend_c.Person()
|
||||
t.name = "Fred Bloggs"
|
||||
if t.name != "FRED BLOGGS":
|
||||
raise RuntimeError("name wrong")
|
||||
13
Examples/test-suite/python/nested_workaround_runme.py
Normal file
13
Examples/test-suite/python/nested_workaround_runme.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from nested_workaround import *
|
||||
|
||||
inner = Inner(5)
|
||||
outer = Outer()
|
||||
newInner = outer.doubleInnerValue(inner)
|
||||
if newInner.getValue() != 10:
|
||||
raise RuntimeError
|
||||
|
||||
outer = Outer()
|
||||
inner = outer.createInner(3)
|
||||
newInner = outer.doubleInnerValue(inner)
|
||||
if outer.getInnerValue(newInner) != 6:
|
||||
raise RuntimeError
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
%module nondynamic
|
||||
|
||||
/*
|
||||
Use the %pythonnondynamic directuve to make the wrapped class a
|
||||
nondynamic one, ie, a python class that doesn't dynamically add new
|
||||
attributes. Hence, for the class
|
||||
|
||||
%pythonnondynamic A;
|
||||
struct A
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
you will get:
|
||||
|
||||
aa = A()
|
||||
aa.a = 1 # Ok
|
||||
aa.b = 1 # Ok
|
||||
aa.c = 3 # error
|
||||
|
||||
Since "nondynamic" is a feature, if you use
|
||||
|
||||
%pythonnondynamic;
|
||||
|
||||
it will make all the wrapped class nondynamic ones.
|
||||
|
||||
The implementation is based on the recipe:
|
||||
|
||||
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158
|
||||
|
||||
and works for modern (-modern) and plain python.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
%pythonnondynamic A;
|
||||
%pythondynamic C;
|
||||
|
||||
|
||||
%inline %{
|
||||
|
||||
struct A
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
|
||||
struct C
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
import nondynamic
|
||||
|
||||
aa = nondynamic.A()
|
||||
|
||||
aa.a = 1
|
||||
aa.b = 2
|
||||
try:
|
||||
aa.c = 2
|
||||
err = 0
|
||||
except:
|
||||
err = 1
|
||||
|
||||
if not err:
|
||||
raise RuntimeError, "A is not static"
|
||||
|
||||
|
||||
class B(nondynamic.A):
|
||||
c = 4
|
||||
def __init__(self):
|
||||
nondynamic.A.__init__(self)
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
|
||||
bb = B()
|
||||
bb.c = 3
|
||||
try:
|
||||
bb.d = 2
|
||||
err = 0
|
||||
except:
|
||||
err = 1
|
||||
|
||||
if not err:
|
||||
raise RuntimeError, "B is not static"
|
||||
|
||||
|
||||
cc = nondynamic.C()
|
||||
cc.d = 3
|
||||
0
Examples/test-suite/python/overload_complicated_runme.py
Executable file → Normal file
0
Examples/test-suite/python/overload_complicated_runme.py
Executable file → Normal file
|
|
@ -1,4 +0,0 @@
|
|||
// Simple tests of overloaded functions
|
||||
%module("castmode") overload_simple_cast
|
||||
|
||||
%include overload_simple.i
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
from overload_template_fast import *
|
||||
f = foo()
|
||||
|
||||
a = max(3,4)
|
||||
b = max(3.4,5.2)
|
||||
a = maximum(3,4)
|
||||
b = maximum(3.4,5.2)
|
||||
|
||||
# mix 1
|
||||
if (mix1("hi") != 101):
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from overload_template import *
|
||||
f = foo()
|
||||
|
||||
a = max(3,4)
|
||||
b = max(3.4,5.2)
|
||||
a = maximum(3,4)
|
||||
b = maximum(3.4,5.2)
|
||||
|
||||
# mix 1
|
||||
if (mix1("hi") != 101):
|
||||
|
|
|
|||
16
Examples/test-suite/python/pointer_reference_runme.py
Normal file
16
Examples/test-suite/python/pointer_reference_runme.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import pointer_reference
|
||||
|
||||
s = pointer_reference.get()
|
||||
if s.value != 10:
|
||||
raise RuntimeError, "get test failed"
|
||||
|
||||
ss = pointer_reference.Struct(20)
|
||||
pointer_reference.set(ss)
|
||||
if pointer_reference.cvar.Struct_instance.value != 20:
|
||||
raise RuntimeError, "set test failed"
|
||||
|
||||
if pointer_reference.overloading(1) != 111:
|
||||
raise RuntimeError, "overload test 1 failed"
|
||||
|
||||
if pointer_reference.overloading(ss) != 222:
|
||||
raise RuntimeError, "overload test 2 failed"
|
||||
11
Examples/test-suite/python/preproc_defined_runme.py
Normal file
11
Examples/test-suite/python/preproc_defined_runme.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import preproc_defined
|
||||
|
||||
if preproc_defined.call_checking() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
d = preproc_defined.Defined()
|
||||
d.defined = 10
|
||||
|
||||
preproc_defined.thing(10)
|
||||
preproc_defined.stuff(10)
|
||||
preproc_defined.bumpf(10)
|
||||
23
Examples/test-suite/python/preproc_include_runme.py
Normal file
23
Examples/test-suite/python/preproc_include_runme.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import preproc_include
|
||||
|
||||
if preproc_include.multiply10(10) != 100:
|
||||
raise RuntimeError
|
||||
|
||||
if preproc_include.multiply20(10) != 200:
|
||||
raise RuntimeError
|
||||
|
||||
if preproc_include.multiply30(10) != 300:
|
||||
raise RuntimeError
|
||||
|
||||
if preproc_include.multiply40(10) != 400:
|
||||
raise RuntimeError
|
||||
|
||||
if preproc_include.multiply50(10) != 500:
|
||||
raise RuntimeError
|
||||
|
||||
if preproc_include.multiply60(10) != 600:
|
||||
raise RuntimeError
|
||||
|
||||
if preproc_include.multiply70(10) != 700:
|
||||
raise RuntimeError
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
%module pybuf
|
||||
%include<pybuffer.i>
|
||||
|
||||
%pybuffer_mutable_binary(char *buf1, int len);
|
||||
%pybuffer_mutable_string(char *buf2);
|
||||
%pybuffer_binary(const char *buf3, int len);
|
||||
%pybuffer_string(const char *buf4);
|
||||
|
||||
%inline %{
|
||||
void func1(char *buf1, int len)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<len; ++i)
|
||||
buf1[i] = 'a';
|
||||
return;
|
||||
}
|
||||
void func2(char *buf2)
|
||||
{
|
||||
strcpy(buf2, "Hello world!");
|
||||
}
|
||||
int func3(const char *buf3, int len)
|
||||
{
|
||||
int count = 0;
|
||||
int i;
|
||||
for(i=0; i<len; ++i)
|
||||
if (isalnum(buf3[i]))
|
||||
++count;
|
||||
return count;
|
||||
}
|
||||
int func4(const char *buf4)
|
||||
{
|
||||
return strlen(buf4);
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
%module pybuf_benchmark
|
||||
|
||||
%include<pybuffer.i>
|
||||
%include<cstring.i>
|
||||
%pybuffer_mutable_string(char *str1);
|
||||
%cstring_mutable(char *str2);
|
||||
|
||||
%inline %{
|
||||
void title(char *str) {
|
||||
int outword = 0;
|
||||
while(*str) {
|
||||
if (isalnum(*str)) {
|
||||
if (outword) {
|
||||
outword = 1;
|
||||
*str = toupper(*str);
|
||||
}
|
||||
}
|
||||
else {
|
||||
outword = 0;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
void title1(char *str1) {
|
||||
title(str1);
|
||||
}
|
||||
void title2(char *str2) {
|
||||
title(str2);
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import pybuf
|
||||
import time
|
||||
k=1000000
|
||||
n=7
|
||||
|
||||
t=time.time()
|
||||
a = bytearray(b'hello world')
|
||||
for i in range(k):
|
||||
pybuf.title1(a)
|
||||
print "Time used by bytearray:",time.time()-t
|
||||
|
||||
t=time.time()
|
||||
b = 'hello world'
|
||||
for i in range(k):
|
||||
pybuf.title2(b)
|
||||
print "Time used by string:",time.time()-t
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import pybuf
|
||||
import time
|
||||
k=1000000
|
||||
n=7
|
||||
|
||||
t=time.time()
|
||||
a = bytearray(b'hello world')
|
||||
for i in range(k):
|
||||
pybuf.title1(a)
|
||||
print("Time used by bytearray:",time.time()-t)
|
||||
|
||||
t=time.time()
|
||||
b = 'hello world'
|
||||
for i in range(k):
|
||||
pybuf.title2(b)
|
||||
print("Time used by string:",time.time()-t)
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
import pybuf
|
||||
buf1 = bytearray(10)
|
||||
buf2 = bytearray(50)
|
||||
|
||||
pybuf.func1(buf1)
|
||||
assert buf1 == b'a'*10
|
||||
|
||||
pybuf.func2(buf2)
|
||||
assert buf2.startswith(b"Hello world!\x00")
|
||||
|
||||
count = pybuf.func3(buf2)
|
||||
assert count==10 #number of alpha and number in 'Hello world!'
|
||||
|
||||
length = pybuf.func4(buf2)
|
||||
assert length==12
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
from abstractbase import *
|
||||
from python_abstractbase import *
|
||||
from collections import *
|
||||
|
||||
# This is expected to fail with -builtin option
|
||||
# Builtin types can't inherit from pure-python abstract bases
|
||||
|
||||
assert issubclass(Mapii, MutableMapping)
|
||||
assert issubclass(Multimapii, MutableMapping)
|
||||
assert issubclass(IntSet, MutableSet)
|
||||
4
Examples/test-suite/python/python_append_runme.py
Normal file
4
Examples/test-suite/python/python_append_runme.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from python_append import *
|
||||
t=Test()
|
||||
t.func()
|
||||
t.static_func()
|
||||
46
Examples/test-suite/python/python_nondynamic_runme.py
Normal file
46
Examples/test-suite/python/python_nondynamic_runme.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import python_nondynamic
|
||||
|
||||
aa = python_nondynamic.A()
|
||||
|
||||
aa.a = 1
|
||||
aa.b = 2
|
||||
try:
|
||||
aa.c = 2
|
||||
err = 0
|
||||
except:
|
||||
err = 1
|
||||
|
||||
if not err:
|
||||
raise RuntimeError, "A is not static"
|
||||
|
||||
class B(python_nondynamic.A):
|
||||
c = 4
|
||||
def __init__(self):
|
||||
python_nondynamic.A.__init__(self)
|
||||
pass
|
||||
pass
|
||||
|
||||
bb = B()
|
||||
|
||||
try:
|
||||
bb.c = 3
|
||||
err = 0
|
||||
except:
|
||||
err = 1
|
||||
|
||||
if not err:
|
||||
print "bb.c = %d" % bb.c
|
||||
print "B.c = %d" % B.c
|
||||
raise RuntimeError, "B.c class variable messes up nondynamic-ness of B"
|
||||
|
||||
try:
|
||||
bb.d = 2
|
||||
err = 0
|
||||
except:
|
||||
err = 1
|
||||
|
||||
if not err:
|
||||
raise RuntimeError, "B is not static"
|
||||
|
||||
cc = python_nondynamic.C()
|
||||
cc.d = 3
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from overload_simple_cast import *
|
||||
from python_overload_simple_cast import *
|
||||
|
||||
class Ai:
|
||||
def __init__(self,x):
|
||||
42
Examples/test-suite/python/python_pybuf_runme3.py
Normal file
42
Examples/test-suite/python/python_pybuf_runme3.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#run:
|
||||
# python python_pybuf_runme3.py benchmark
|
||||
#for the benchmark, other wise the test case will be run
|
||||
import python_pybuf
|
||||
import sys
|
||||
if len(sys.argv)>=2 and sys.argv[1]=="benchmark":
|
||||
#run the benchmark
|
||||
import time
|
||||
k=1000000 #number of times to excute the functions
|
||||
|
||||
t=time.time()
|
||||
a = bytearray(b'hello world')
|
||||
for i in range(k):
|
||||
pybuf.title1(a)
|
||||
print("Time used by bytearray:",time.time()-t)
|
||||
|
||||
t=time.time()
|
||||
b = 'hello world'
|
||||
for i in range(k):
|
||||
pybuf.title2(b)
|
||||
print("Time used by string:",time.time()-t)
|
||||
else:
|
||||
#run the test case
|
||||
buf1 = bytearray(10)
|
||||
buf2 = bytearray(50)
|
||||
|
||||
pybuf.func1(buf1)
|
||||
assert buf1 == b'a'*10
|
||||
|
||||
pybuf.func2(buf2)
|
||||
assert buf2.startswith(b"Hello world!\x00")
|
||||
|
||||
count = pybuf.func3(buf2)
|
||||
assert count==10 #number of alpha and number in 'Hello world!'
|
||||
|
||||
length = pybuf.func4(buf2)
|
||||
assert length==12
|
||||
|
||||
buf3 = bytearray(b"hello")
|
||||
pybuf.title1(buf3)
|
||||
assert buf3==b'Hello'
|
||||
|
||||
100
Examples/test-suite/python/python_richcompare_runme.py
Normal file
100
Examples/test-suite/python/python_richcompare_runme.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import python_richcompare
|
||||
|
||||
base1 = python_richcompare.BaseClass(1)
|
||||
base2 = python_richcompare.BaseClass(2)
|
||||
base3 = python_richcompare.BaseClass(3)
|
||||
a1 = python_richcompare.SubClassA(1)
|
||||
a2 = python_richcompare.SubClassA(2)
|
||||
a3 = python_richcompare.SubClassA(3)
|
||||
b1 = python_richcompare.SubClassB(1)
|
||||
b2 = python_richcompare.SubClassB(2)
|
||||
b3 = python_richcompare.SubClassB(3)
|
||||
|
||||
# Check == and != within a single type
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if not (base1 == base1) :
|
||||
raise RuntimeError("Object not == to itself")
|
||||
|
||||
if not (base1 == python_richcompare.BaseClass(1)) :
|
||||
raise RuntimeError("Object not == to an equivalent object")
|
||||
|
||||
if (base1 == base2) :
|
||||
raise RuntimeError("Comparing non-equivalent objects of the same type, == returned True")
|
||||
|
||||
if (base1 != base1) :
|
||||
raise RuntimeError("Object is != itself")
|
||||
|
||||
if (base1 != python_richcompare.BaseClass(1)) :
|
||||
raise RuntimeError("Object is != an equivalent object")
|
||||
|
||||
if not (base1 != base2) :
|
||||
raise RuntimeError("Comparing non-equivalent objects of the same type, != returned False")
|
||||
|
||||
|
||||
# Check redefined operator== in SubClassA
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if (a2 == base2) :
|
||||
raise RuntimeError("Redefined operator== in SubClassA failed")
|
||||
|
||||
if (a2 == b2) :
|
||||
raise RuntimeError("Redefined operator== in SubClassA failed")
|
||||
|
||||
if not (a1 == a2) :
|
||||
raise RuntimeError("Redefined operator== in SubClassA failed")
|
||||
|
||||
# Check up-casting of subclasses
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if (base2 != a2) :
|
||||
raise RuntimeError("Comparing equivalent base and subclass instances, != returned True")
|
||||
|
||||
if (a2 == base2) :
|
||||
raise RuntimeError("Comparing non-equivalent base and subclass instances, == returned True")
|
||||
|
||||
if (a1 == b1) :
|
||||
raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True")
|
||||
|
||||
if (b1 == a1) :
|
||||
raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True")
|
||||
|
||||
# Check inequalities
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if (a2 > b2) :
|
||||
raise RuntimeError("operator> failed")
|
||||
|
||||
if (a2 < b2) :
|
||||
raise RuntimeError("operator< failed")
|
||||
|
||||
if not (a2 >= b2) :
|
||||
raise RuntimeError("operator>= failed")
|
||||
|
||||
if not (a2 <= b2) :
|
||||
raise RuntimeError("operator<= failed")
|
||||
|
||||
# Check inequalities used for ordering
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
x = sorted([a2, a3, a1])
|
||||
|
||||
if not (x[0] is a1) :
|
||||
raise RuntimeError("Ordering failed")
|
||||
|
||||
if not (x[1] is a2) :
|
||||
raise RuntimeError("Ordering failed")
|
||||
|
||||
if not (x[2] is a3) :
|
||||
raise RuntimeError("Ordering failed")
|
||||
|
||||
x = sorted([base2, a3, b1])
|
||||
|
||||
if not (x[0] is b1) :
|
||||
raise RuntimeError("Ordering failed")
|
||||
|
||||
if not (x[1] is base2) :
|
||||
raise RuntimeError("Ordering failed")
|
||||
|
||||
if not (x[2] is a3) :
|
||||
raise RuntimeError("Ordering failed")
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import python_varargs_typemap
|
||||
|
||||
if (python_varargs_typemap.testfunc(1, 2.0, "three") != "three") :
|
||||
raise RuntimeError("testfunc failed!")
|
||||
|
|
@ -10,14 +10,14 @@ b2 = B.create(a)
|
|||
|
||||
|
||||
if a.ref_count() != 3:
|
||||
print "This program will crash... now"
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
|
||||
rca = b2.get_rca()
|
||||
b3 = B.create(rca)
|
||||
|
||||
if a.ref_count() != 5:
|
||||
print "This program will crash... now"
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
|
||||
v = vector_A(2)
|
||||
|
|
@ -27,6 +27,35 @@ v[1] = a
|
|||
x = v[0]
|
||||
del v
|
||||
|
||||
if a.ref_count() != 6:
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
# Check %newobject
|
||||
b4 = b2.cloner()
|
||||
if b4.ref_count() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
b5 = global_create(a)
|
||||
if b5.ref_count() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
b6 = Factory.create(a)
|
||||
if b6.ref_count() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
b7 = Factory().create2(a)
|
||||
if b7.ref_count() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
if a.ref_count() != 10:
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
del b4
|
||||
del b5
|
||||
del b6
|
||||
del b7
|
||||
|
||||
if a.ref_count() != 6:
|
||||
raise RuntimeError("Count = %d" % a.ref_count())
|
||||
|
||||
|
|
|
|||
13
Examples/test-suite/python/rename_pcre_encoder_runme.py
Normal file
13
Examples/test-suite/python/rename_pcre_encoder_runme.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from rename_pcre_encoder import *
|
||||
|
||||
s = SomeWidget()
|
||||
s.putBorderWidth(3)
|
||||
if s.getBorderWidth() != 3:
|
||||
raise RuntimeError("Border should be 3, not %d" % (s.getBorderWidth(),))
|
||||
|
||||
s.putSize(4, 5)
|
||||
a = AnotherWidget()
|
||||
a.DoSomething()
|
||||
|
||||
evt = wxEVTSomeEvent()
|
||||
t = xUnchangedName()
|
||||
6
Examples/test-suite/python/rename_strip_encoder_runme.py
Normal file
6
Examples/test-suite/python/rename_strip_encoder_runme.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from rename_strip_encoder import *
|
||||
|
||||
s = SomeWidget()
|
||||
a = AnotherWidget()
|
||||
a.DoSomething()
|
||||
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
%module simutry
|
||||
|
||||
%include "std_vector.i"
|
||||
|
||||
%inline {
|
||||
|
||||
namespace simuPOP
|
||||
{
|
||||
// some simple pop class
|
||||
template <class Type>
|
||||
struct Population {
|
||||
int m_a;
|
||||
Population(int a):m_a(a){}
|
||||
};
|
||||
|
||||
// base operator, output pop.m_a
|
||||
template<class Pop>
|
||||
struct Operator
|
||||
{
|
||||
Pop m_pop;
|
||||
Operator(int a):m_pop(a){}
|
||||
virtual ~Operator()
|
||||
{
|
||||
}
|
||||
|
||||
virtual int func() const
|
||||
{ return m_pop.m_a; }
|
||||
};
|
||||
|
||||
// derived operator, output double of pop.m_a
|
||||
template<class Pop>
|
||||
struct DerivedOperator: public Operator<Pop>
|
||||
{
|
||||
DerivedOperator(int a):Operator<Pop>(a){}
|
||||
virtual int func() const
|
||||
{ return 2*this->m_pop.m_a; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if 1
|
||||
namespace simuPOP
|
||||
{
|
||||
%template(population) Population< std::pair<unsigned long,unsigned long> >;
|
||||
}
|
||||
|
||||
%inline
|
||||
{
|
||||
namespace simuPOP
|
||||
{
|
||||
typedef Population< std::pair<unsigned long,unsigned long> > pop;
|
||||
}
|
||||
}
|
||||
#else
|
||||
%inline
|
||||
{
|
||||
namespace simuPOP
|
||||
{
|
||||
// %template(population) Population< std::pair<unsigned long,unsigned long> >;
|
||||
|
||||
struct pop {
|
||||
int m_a;
|
||||
pop(int a):m_a(a){}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
namespace simuPOP
|
||||
{
|
||||
%template(baseOperator) Operator< pop >;
|
||||
%template(derivedOperator) DerivedOperator< pop >;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
%template(vectorop) vector< simuPOP::Operator<simuPOP::pop> * >;
|
||||
}
|
||||
|
||||
%inline
|
||||
{
|
||||
namespace simuPOP
|
||||
{
|
||||
// test function, use of a vector of Operator*
|
||||
void test( const std::vector< Operator<pop>*>& para)
|
||||
{
|
||||
for( size_t i =0; i < para.size(); ++i)
|
||||
para[i]->func();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
123
Examples/test-suite/python/smart_pointer_const_overload_runme.py
Normal file
123
Examples/test-suite/python/smart_pointer_const_overload_runme.py
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
from smart_pointer_const_overload import *
|
||||
|
||||
CONST_ACCESS = 1
|
||||
MUTABLE_ACCESS = 2
|
||||
|
||||
def test(b, f):
|
||||
if f.x != 0:
|
||||
raise RuntimeError
|
||||
|
||||
# Test member variable get
|
||||
if b.x != 0:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != CONST_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test member variable set
|
||||
b.x = 1
|
||||
|
||||
if f.x != 1:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != MUTABLE_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test const method
|
||||
if b.getx() != 1:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != CONST_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test mutable method
|
||||
b.setx(2)
|
||||
|
||||
if f.x != 2:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != MUTABLE_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test extended const method
|
||||
if b.getx2() != 2:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != CONST_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test extended mutable method
|
||||
b.setx2(3)
|
||||
|
||||
if f.x != 3:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != MUTABLE_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test static method
|
||||
b.stat()
|
||||
|
||||
if f.access != CONST_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test const member
|
||||
f.access = MUTABLE_ACCESS
|
||||
|
||||
if b.y != 0:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != CONST_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test get through mutable pointer to const member
|
||||
f.access = MUTABLE_ACCESS
|
||||
|
||||
if get_int(b.yp) != 0:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != CONST_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test get through const pointer to mutable member
|
||||
f.x = 4
|
||||
f.access = MUTABLE_ACCESS
|
||||
|
||||
if get_int(b.xp) != 4:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != CONST_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test set through const pointer to mutable member
|
||||
f.access = MUTABLE_ACCESS
|
||||
set_int(b.xp, 5)
|
||||
|
||||
if f.x != 5:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != CONST_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
# Test set pointer to const member
|
||||
b.yp = new_int(6)
|
||||
|
||||
if f.y != 0:
|
||||
raise RuntimeError
|
||||
|
||||
if get_int(f.yp) != 6:
|
||||
raise RuntimeError
|
||||
|
||||
if f.access != MUTABLE_ACCESS:
|
||||
raise RuntimeError
|
||||
|
||||
delete_int(f.yp);
|
||||
|
||||
f = Foo()
|
||||
b = Bar(f)
|
||||
|
||||
f2 = Foo()
|
||||
b2 = Bar2(f2)
|
||||
|
||||
test(b, f)
|
||||
test(b2, f2)
|
||||
16
Examples/test-suite/python/special_variable_macros_runme.py
Normal file
16
Examples/test-suite/python/special_variable_macros_runme.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import special_variable_macros
|
||||
|
||||
name = special_variable_macros.Name()
|
||||
if special_variable_macros.testFred(name) != "none":
|
||||
raise "test failed"
|
||||
if special_variable_macros.testJack(name) != "$specialname":
|
||||
raise "test failed"
|
||||
if special_variable_macros.testJill(name) != "jilly":
|
||||
raise "test failed"
|
||||
if special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap":
|
||||
raise "test failed"
|
||||
if special_variable_macros.testJim(name) != "multiname num":
|
||||
raise "test failed"
|
||||
if special_variable_macros.testJohn(special_variable_macros.PairIntBool(10, False)) != 123:
|
||||
raise "test failed"
|
||||
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
%module std_containers
|
||||
|
||||
%{
|
||||
#include <set>
|
||||
%}
|
||||
%include std_vector.i
|
||||
%include std_string.i
|
||||
%include std_deque.i
|
||||
%include std_list.i
|
||||
%include std_set.i
|
||||
%include std_multiset.i
|
||||
%include std_pair.i
|
||||
%include std_map.i
|
||||
%include std_multimap.i
|
||||
%include std_complex.i
|
||||
|
||||
%template() std::vector<double>;
|
||||
%template() std::pair<std::string, int>;
|
||||
%template() std::pair<int,double>;
|
||||
|
||||
%template() std::vector< std::vector<double > > ;
|
||||
%template(ccube) std::vector< std::vector< std::vector<double > > >;
|
||||
|
||||
%inline
|
||||
{
|
||||
typedef
|
||||
std::vector<std::vector<std::vector<double > > >
|
||||
ccube;
|
||||
|
||||
ccube cident(const ccube& c)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
struct C
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
%template(map_si) std::map<std::string, int>;
|
||||
%template(pair_iC) std::pair<int, C*>;
|
||||
%template(map_iC) std::map<int, C*>;
|
||||
%template(mmap_si) std::multimap<std::string, int>;
|
||||
%template(set_i) std::set<int>;
|
||||
%template(multiset_i) std::multiset<int>;
|
||||
%template(list_i) std::list<int>;
|
||||
%template(deque_i) std::deque<int>;
|
||||
|
||||
%template(vector_b) std::vector<bool>;
|
||||
%template(vector_i) std::vector<int>;
|
||||
%template(vector_c) std::vector<std::complex<double> >;
|
||||
%template(vector_ui) std::vector<unsigned int>;
|
||||
|
||||
%template(bmatrix) std::vector<std::vector<bool> >;
|
||||
%template(imatrix) std::vector<std::vector<int> >;
|
||||
%template(cmatrix) std::vector<std::vector<std::complex<double> > >;
|
||||
|
||||
%apply std::vector<int> *INOUT {std::vector<int> *INOUT2};
|
||||
|
||||
%inline
|
||||
{
|
||||
typedef std::vector<std::vector<int> > imatrix;
|
||||
imatrix midenti(const imatrix& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
typedef std::vector<std::vector<bool> > bmatrix;
|
||||
bmatrix midentb(const bmatrix& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
std::map<int,C*> mapidentc(const std::map<int,C*>& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
std::map<int,int> mapidenti(const std::map<int,int>& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
std::map<std::string,int> mapident(const std::map<std::string,int>& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
std::multimap<std::string,int> mapident(const std::multimap<std::string,int>& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
std::vector<int> vident(const std::vector<int>& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
std::set<int> sident(const std::set<int>& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
std::vector<unsigned int> videntu(const std::vector<unsigned int>& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
int get_elem(const std::vector<int>& v, int index)
|
||||
{
|
||||
return v[index];
|
||||
}
|
||||
|
||||
std::pair<int,double> pident(const std::pair<int,double>& p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
v_inout(std::vector<int> *INOUT) {
|
||||
*INOUT = *INOUT;
|
||||
}
|
||||
|
||||
void
|
||||
v_inout2(std::vector<int> *INOUT, std::vector<int> *INOUT2) {
|
||||
std::swap(*INOUT, *INOUT2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
%{
|
||||
|
||||
template <class C> struct Param
|
||||
{
|
||||
};
|
||||
%}
|
||||
|
||||
|
||||
template <class C> struct Param
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
%template(Param_c) Param<std::complex<double> >;
|
||||
%inline
|
||||
{
|
||||
int hello(Param<std::complex<double> > c)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%inline
|
||||
{
|
||||
struct A
|
||||
{
|
||||
A(int aa = 0) : a(aa)
|
||||
{
|
||||
}
|
||||
int a;
|
||||
};
|
||||
}
|
||||
|
||||
%template() std::pair<A,int>;
|
||||
%template(pair_iA) std::pair<int,A>;
|
||||
%template(vector_piA) std::vector<std::pair<int,A> >;
|
||||
|
||||
|
||||
%inline {
|
||||
std::pair<A,int> ident(std::pair<int,A> a, const std::pair<int,int>& b)
|
||||
{
|
||||
return std::pair<A,int>();
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::pair<int,A> > pia_vident(std::vector<std::pair<int,A> > a )
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
struct Foo
|
||||
{
|
||||
Foo(int i) {
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
%std_nodefconst_type(Foo);
|
||||
|
||||
%template(vector_Foo) std::vector<Foo>;
|
||||
%template(deque_Foo) std::deque<Foo>;
|
||||
%template(list_Foo) std::list<Foo>;
|
||||
|
||||
|
||||
20
Examples/test-suite/python/struct_initialization_runme.py
Normal file
20
Examples/test-suite/python/struct_initialization_runme.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from struct_initialization import *
|
||||
|
||||
if cvar.instanceC1.x != 10:
|
||||
raise RuntimeError
|
||||
|
||||
if cvar.instanceD1.x != 10:
|
||||
raise RuntimeError
|
||||
|
||||
if cvar.instanceD2.x != 20:
|
||||
raise RuntimeError
|
||||
|
||||
if cvar.instanceD3.x != 30:
|
||||
raise RuntimeError
|
||||
|
||||
if cvar.instanceE1.x != 1:
|
||||
raise RuntimeError
|
||||
|
||||
if cvar.instanceF1.x != 1:
|
||||
raise RuntimeError
|
||||
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
%module swigobject
|
||||
|
||||
|
||||
|
||||
%inline
|
||||
{
|
||||
struct A {
|
||||
char name[4];
|
||||
};
|
||||
|
||||
const char* pointer_str(A *a){
|
||||
static char result[1024];
|
||||
sprintf(result,"0x%lx", (unsigned long)(void *)a);
|
||||
return result;
|
||||
}
|
||||
|
||||
A *a_ptr(A *a){
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
void *v_ptr(void *a){
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,11 +12,17 @@ if a1.this != a2.this:
|
|||
|
||||
|
||||
lthis = long(a.this)
|
||||
xstr1 = "0x%x" % (lthis,)
|
||||
# match pointer value, but deal with leading zeros on 8/16 bit systems and different C++ compilers interpretation of %p
|
||||
xstr1 = "%016X" % (lthis,)
|
||||
xstr1 = str.lstrip(xstr1, '0')
|
||||
xstr2 = pointer_str(a)
|
||||
xstr2 = str.replace(xstr2, "0x", "")
|
||||
xstr2 = str.replace(xstr2, "0X", "")
|
||||
xstr2 = str.lstrip(xstr2, '0')
|
||||
xstr2 = str.upper(xstr2)
|
||||
|
||||
if xstr1 != xstr2:
|
||||
print xstr1, xstr2
|
||||
print xstr1, xstr2
|
||||
raise RuntimeError
|
||||
|
||||
s = str(a.this)
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
import enum_tag_no_clash_with_variable
|
||||
|
||||
error_action = error_action
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
%module template_matrix
|
||||
%{
|
||||
#include <vector>
|
||||
|
||||
struct pop
|
||||
{
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
%include "std_vector.i"
|
||||
|
||||
|
||||
%inline {
|
||||
namespace simuPOP
|
||||
{
|
||||
struct POP
|
||||
{
|
||||
};
|
||||
|
||||
template<class _POP1, class _POP2 = POP>
|
||||
class Operator
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
%template(vectorop) std::vector< simuPOP::Operator<pop> >;
|
||||
|
||||
|
||||
|
||||
namespace simuPOP
|
||||
{
|
||||
%template(baseOperator) Operator<pop>;
|
||||
}
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
namespace std
|
||||
{
|
||||
%template(vectori) vector<int>;
|
||||
%template(matrixi) vector< vector<int> >;
|
||||
%template(cubei) vector< vector< vector<int> > >;
|
||||
}
|
||||
|
||||
|
||||
|
||||
%inline %{
|
||||
std::vector<int>
|
||||
passVector(const std::vector<int>& a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
std::vector< std::vector<int> >
|
||||
passMatrix(const std::vector< std::vector<int> >& a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
std::vector< std::vector< std::vector<int> > >
|
||||
passCube(const std::vector< std::vector< std::vector<int> > >& a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue