Merged with recent changes from trunk.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11187 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Maciej Drwal 2009-04-11 16:46:47 +00:00
commit 8c74fa0f46
703 changed files with 21126 additions and 9266 deletions

View file

@ -2,16 +2,37 @@
# Makefile for python test-suite
#######################################################################
ifeq (,$(PY3))
PYBIN = @PYTHON@
else
PYBIN = @PYTHON3@
endif
LANGUAGE = python
PYTHON = @PYTHON@
SCRIPTSUFFIX = _runme.py
PYTHON = $(PYBIN)
#*_runme.py for Python 2.x, *_runme3.py for Python 3.x
PY2SCRIPTSUFFIX = _runme.py
PY3SCRIPTSUFFIX = _runme3.py
ifeq (,$(PY3))
SCRIPTSUFFIX = $(PY2SCRIPTSUFFIX)
else
SCRIPTSUFFIX = $(PY3SCRIPTSUFFIX)
endif
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
PY2TO3 = 2to3 -x import
CPP_TEST_CASES += \
argcargvtest \
autodoc \
python_autodoc \
python_append \
callback \
complextest \
director_stl \
@ -22,32 +43,38 @@ CPP_TEST_CASES += \
input \
inplaceadd \
implicittest \
kwargs \
li_cstring \
li_cwstring \
li_factory \
li_implicit \
li_std_vectora \
li_std_vector_extra \
li_std_map \
li_std_pair_extra \
li_std_set \
li_std_stream \
li_std_string_extra \
li_std_wstream \
li_std_wstring \
nondynamic \
overload_simple_cast \
primitive_types \
python_abstractbase \
python_kwargs \
python_nondynamic \
python_overload_simple_cast \
std_containers \
swigobject \
template_matrix \
simutry \
vector
simutry
# li_std_carray
# director_profile
# python_pybuf
C_TEST_CASES += \
file_test \
li_cstring \
li_cwstring \
nondynamic
python_nondynamic
#
# This test only works with modern C compilers
@ -77,17 +104,42 @@ VALGRIND_OPT += --suppressions=pythonswig.supp
+$(swig_and_compile_multi_cpp)
$(run_testcase)
# Call 2to3 to generate Python 3.x test from the Python 2.x's *_runme.py file
%$(PY3SCRIPTSUFFIX): %$(PY2SCRIPTSUFFIX)
cp $< $@
$(PY2TO3) -w $@ >/dev/null 2>&1
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.py appended after the testcase name.
# 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)
py2_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX)
py3_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX)
ifeq (,$(PY3))
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX);) \
$(run_python);)\
fi;
else
run_testcase = \
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
@ -101,14 +153,15 @@ cvsignore:
@echo clientdata_prop_b.py
@echo imports_a.py
@echo imports_b.py
@echo mod_a.py mod_b.py
@echo mod_a.py mod_b.py
@echo hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py
@echo template_typedef_import.py
hugemod_runme = hugemod$(SCRIPTPREFIX)
hugemod:
perl hugemod.pl
perl hugemod.pl $(hugemod_runme)
$(MAKE) hugemod_a.cpptest
$(MAKE) hugemod_b.cpptest
time $(PYTHON) hugemod_runme.py
time $(PYTHON) hugemod_runme.py
sh -c "time $(PYTHON) $(hugemod_runme)"
sh -c "time $(PYTHON) $(hugemod_runme)"

View file

@ -1,4 +1,8 @@
See ../README for common README file.
Any testcases which have _runme.py appended after the testcase name will be detected and run.
Any testcases which have _runme.py (or _runme3.py for Python 3) appended after the testcase name will be detected and run.
If you intend to write a testcase for both Python 2.x and 3.x, do *not* directly put the _runme3.py in this directory. Just write Python 2.x's _runme.py testcase and it will be automatically converted to Python 3 code during test.
You can run make with PY3=y to run test case with Python 3.x, eg.
$ make voidtest.cpptest PY3=y

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,20 +3,20 @@ import cpp_namespace
n = cpp_namespace.fact(4)
if n != 24:
raise "Bad return value!"
raise RuntimeError("Bad return value!")
if cpp_namespace.cvar.Foo != 42:
raise "Bad variable value!"
raise RuntimeError("Bad variable value!")
t = cpp_namespace.Test()
if t.method() != "Test::method":
raise "Bad method return value!"
raise RuntimeError("Bad method return value!")
if cpp_namespace.do_method(t) != "Test::method":
raise "Bad return value!"
raise RuntimeError("Bad return value!")
if cpp_namespace.do_method2(t) != "Test::method":
raise "Bad return value!"
raise RuntimeError("Bad return value!")
cpp_namespace.weird("hello", 4)
@ -28,18 +28,18 @@ t4 = cpp_namespace.Test4()
t5 = cpp_namespace.Test5()
if cpp_namespace.foo3(42) != 42:
raise "Bad return value!"
raise RuntimeError("Bad return value!")
if cpp_namespace.do_method3(t2,40) != "Test2::method":
raise "Bad return value!"
raise RuntimeError("Bad return value!")
if cpp_namespace.do_method3(t3,40) != "Test3::method":
raise "Bad return value!"
raise RuntimeError("Bad return value!")
if cpp_namespace.do_method3(t4,40) != "Test4::method":
raise "Bad return value!"
raise RuntimeError("Bad return value!")
if cpp_namespace.do_method3(t5,40) != "Test5::method":
raise "Bad return value!"
raise RuntimeError("Bad return value!")

View file

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

View file

@ -1,56 +1,56 @@
from director_classic import *
class TargetLangPerson(Person):
def __init__(self):
Person.__init__(self)
def id(self):
identifier = "TargetLangPerson"
return identifier
def __init__(self):
Person.__init__(self)
def id(self):
identifier = "TargetLangPerson"
return identifier
class TargetLangChild(Child):
def __init__(self):
Child.__init__(self)
def id(self):
identifier = "TargetLangChild"
return identifier
def __init__(self):
Child.__init__(self)
def id(self):
identifier = "TargetLangChild"
return identifier
class TargetLangGrandChild(GrandChild):
def __init__(self):
GrandChild.__init__(self)
def id(self):
identifier = "TargetLangGrandChild"
return identifier
def __init__(self):
GrandChild.__init__(self)
def id(self):
identifier = "TargetLangGrandChild"
return identifier
# Semis - don't override id() in target language
class TargetLangSemiPerson(Person):
def __init__(self):
Person.__init__(self)
def __init__(self):
Person.__init__(self)
# No id() override
class TargetLangSemiChild(Child):
def __init__(self):
Child.__init__(self)
def __init__(self):
Child.__init__(self)
# No id() override
class TargetLangSemiGrandChild(GrandChild):
def __init__(self):
GrandChild.__init__(self)
def __init__(self):
GrandChild.__init__(self)
# No id() override
# Orphans - don't override id() in C++
class TargetLangOrphanPerson(OrphanPerson):
def __init__(self):
OrphanPerson.__init__(self)
def id(self):
identifier = "TargetLangOrphanPerson"
return identifier
def __init__(self):
OrphanPerson.__init__(self)
def id(self):
identifier = "TargetLangOrphanPerson"
return identifier
class TargetLangOrphanChild(OrphanChild):
def __init__(self):
Child.__init__(self)
def id(self):
identifier = "TargetLangOrphanChild"
return identifier
def __init__(self):
Child.__init__(self)
def id(self):
identifier = "TargetLangOrphanChild"
return identifier
def check(person, expected):
@ -61,7 +61,7 @@ def check(person, expected):
if (debug):
print(ret)
if (ret != expected):
raise ("Failed. Received: " + ret + " Expected: " + expected)
raise RuntimeError("Failed. Received: " + str(ret) + " Expected: " + expected)
# Polymorphic call from C++
caller = Caller()
@ -70,7 +70,7 @@ def check(person, expected):
if (debug):
print(ret)
if (ret != expected):
raise ("Failed. Received: " + ret + " Expected: " + expected)
raise RuntimeError("Failed. Received: " + str(ret) + " Expected: " + expected)
# Polymorphic call of object created in target language and passed to C++ and back again
baseclass = caller.baseClass()
@ -78,7 +78,7 @@ def check(person, expected):
if (debug):
print(ret)
if (ret != expected):
raise ("Failed. Received: " + ret + " Expected: " + expected)
raise RuntimeError("Failed. Received: " + str(ret)+ " Expected: " + expected)
caller.resetCallback()
if (debug):

View file

@ -1,5 +1,8 @@
from director_exception import *
from exceptions import *
class MyException(Exception):
def __init__(self, a, b):
self.msg = a + b
class MyFoo(Foo):
def ping(self):
@ -7,39 +10,62 @@ class MyFoo(Foo):
class MyFoo2(Foo):
def ping(self):
return true
return True
pass # error: should return a string
ok = 0
class MyFoo3(Foo):
def ping(self):
raise MyException("foo", "bar")
# Check that the NotImplementedError raised by MyFoo.ping() is returned by
# MyFoo.pong().
ok = 0
a = MyFoo()
b = launder(a)
try:
b.pong()
except NotImplementedError, e:
ok = 1
if str(e) == "MyFoo::ping() EXCEPTION":
ok = 1
else:
print "Unexpected error message: %s" % str(e)
except:
pass
if not ok:
raise RuntimeError
ok = 0
# Check that the director returns the appropriate TypeError if the return type
# is wrong.
ok = 0
a = MyFoo2()
b = launder(a)
try:
b.pong()
except:
ok = 1
except TypeError, e:
if str(e) == "Swig director type mismatch in output value of type 'std::string'":
ok = 1
else:
print "Unexpected error message: %s" % str(e)
if not ok:
raise RuntimeError
# Check that the director can return an exception which requires two arguments
# to the constructor, without mangling it.
ok = 0
a = MyFoo3()
b = launder(a)
try:
b.pong()
except MyException, e:
if e.msg == 'foobar':
ok = 1
else:
print "Unexpected error message: %s" % str(e)
if not ok:
raise RuntimeError
try:
raise Exception2()
except Exception2:

View file

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

View file

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

View file

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

View file

@ -1,7 +1,8 @@
import sys
import file_test
file_test.nfile(sys.stdout)
if sys.version_info < (3,0):
file_test.nfile(sys.stdout)
cstdout = file_test.GetStdOut()

View file

@ -2,8 +2,12 @@
use strict;
my $modsize = 399; #adjust it so you can have a smaller or bigger hugemod
my $runme = shift @ARGV;
open HEADER, ">hugemod.h" or die "error";
open TEST, ">hugemod_runme.py" or die "error";
open TEST, ">$runme" or die "error";
open I1, ">hugemod_a.i" or die "error";
open I2, ">hugemod_b.i" or die "error";
@ -21,7 +25,7 @@ print I2 "\%inline \%{\n";
my $i;
for ($i = 0; $i < 6000; $i++) {
for ($i = 0; $i < $modsize; $i++) {
my $t = $i * 4;
print HEADER "class type$i { public: int a; };\n";
print I2 "class dtype$i : public type$i { public: int b; };\n";

View file

@ -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;
};
}

View file

@ -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"

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

View file

@ -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);

View file

@ -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;
}
};
%}

View file

@ -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;
}
%}

View file

@ -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; }
%}

View file

@ -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

View file

@ -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()

View file

@ -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>;

View file

@ -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>;
}

View file

@ -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*> >;
}

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

View file

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

View file

@ -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>;

View file

@ -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;
}
}

View file

@ -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

View file

@ -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":
@ -63,40 +63,40 @@ if c.find_last_of("l") != 9:
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 +105,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

View file

@ -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"; }
%}

View file

@ -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,24 @@ 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

View file

@ -0,0 +1,8 @@
from li_std_vector_ptr import *
ip1 = makeIntPtr(11)
ip2 = makeIntPtr(22)
vi = IntPtrVector((ip1, ip2))
displayVector(vi)

View file

@ -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 *> >;

View file

@ -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;
}
}

View file

@ -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
%}

View file

@ -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;
};
%}

View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
import operbool
assert not operbool.Test()

View file

@ -1,4 +0,0 @@
// Simple tests of overloaded functions
%module("castmode") overload_simple_cast
%include overload_simple.i

View file

@ -0,0 +1,8 @@
from python_abstractbase import *
from collections import *
assert issubclass(Mapii, MutableMapping)
assert issubclass(Multimapii, MutableMapping)
assert issubclass(IntSet, MutableSet)
assert issubclass(IntMultiset, MutableSet)
assert issubclass(IntVector, MutableSequence)
assert issubclass(IntList, MutableSequence)

View file

@ -0,0 +1,4 @@
from python_append import *
t=Test()
t.func()
t.static_func()

View file

@ -1,4 +1,4 @@
from kwargs import *
from python_kwargs import *
class MyFoo(Foo):
def __init__(self, a , b = 0):

View file

@ -1,6 +1,6 @@
import nondynamic
import python_nondynamic
aa = nondynamic.A()
aa = python_nondynamic.A()
aa.a = 1
aa.b = 2
@ -14,10 +14,10 @@ if not err:
raise RuntimeError, "A is not static"
class B(nondynamic.A):
class B(python_nondynamic.A):
c = 4
def __init__(self):
nondynamic.A.__init__(self)
python_nondynamic.A.__init__(self)
pass
pass
@ -35,5 +35,5 @@ if not err:
raise RuntimeError, "B is not static"
cc = nondynamic.C()
cc = python_nondynamic.C()
cc.d = 3

View file

@ -1,4 +1,4 @@
from overload_simple_cast import *
from python_overload_simple_cast import *
class Ai:
def __init__(self,x):

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

View file

@ -0,0 +1,6 @@
from rename_strip_encoder import *
s = SomeWidget()
a = AnotherWidget()
a.DoSomething()

View file

@ -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();
}
}
}

View file

@ -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>;

View file

@ -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;
}
}

View file

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

View file

@ -1,3 +0,0 @@
import enum_tag_no_clash_with_variable
error_action = error_action

View file

@ -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

View file

@ -1,4 +1,3 @@
import string
from template_typedef_cplx2 import *
#
@ -13,7 +12,7 @@ except:
raise RuntimeError
s = '%s' % d
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print d, "is not an ArithUnaryFunction"
raise RuntimeError
@ -25,7 +24,7 @@ except:
raise RuntimeError
s = '%s' % e
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print e, "is not an ArithUnaryFunction"
raise RuntimeError
@ -42,7 +41,7 @@ except:
raise RuntimeError
s = '%s' % c
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print c, "is not an ArithUnaryFunction"
raise RuntimeError
@ -54,7 +53,7 @@ except:
raise RuntimeError
s = '%s' % f
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print f, "is not an ArithUnaryFunction"
raise RuntimeError
@ -70,7 +69,7 @@ except:
raise RuntimeError
s = '%s' % g
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print g, "is not an ArithUnaryFunction"
raise RuntimeError
@ -83,7 +82,7 @@ except:
raise RuntimeError
s = '%s' % h
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print h, "is not an ArithUnaryFunction"
raise RuntimeError

View file

@ -1,4 +1,3 @@
import string
from template_typedef_cplx import *
#
@ -13,7 +12,7 @@ except:
raise RuntimeError
s = '%s' % d
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print d, "is not an ArithUnaryFunction"
raise RuntimeError
@ -25,7 +24,7 @@ except:
raise RuntimeError
s = '%s' % e
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print e, "is not an ArithUnaryFunction"
raise RuntimeError
@ -42,7 +41,7 @@ except:
raise RuntimeError
s = '%s' % c
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print c, "is not an ArithUnaryFunction"
raise RuntimeError
@ -54,7 +53,7 @@ except:
raise RuntimeError
s = '%s' % f
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print f, "is not an ArithUnaryFunction"
raise RuntimeError
@ -70,7 +69,7 @@ except:
raise RuntimeError
s = '%s' % g
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print g, "is not an ArithUnaryFunction"
raise RuntimeError
@ -83,6 +82,6 @@ except:
raise RuntimeError
s = '%s' % h
if string.find(s, 'ArithUnaryFunction') == -1:
if str.find(s, 'ArithUnaryFunction') == -1:
print h, "is not an ArithUnaryFunction"
raise RuntimeError

View file

@ -1,51 +0,0 @@
%module vector
%{
#include <vector>
%}
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
public:
typedef size_t size_type;
typedef CTYPE value_type;
size_type size() const;
vector();
%extend {
static std::vector<CTYPE > *Repeat(const value_type& value, int count) /*throw (std::out_of_range)*/ {
// if (count < 0)
// throw std::out_of_range("count");
return new std::vector<CTYPE >(count, value);
}
}
%enddef
namespace std {
// primary (unspecialized) class template for std::vector
// does not require operator== to be defined
template<class T> class vector {
SWIG_STD_VECTOR_MINIMUM(T, T)
};
}
%define SWIG_STD_VECTOR_SPECIALIZE(CSTYPE, CTYPE...)
namespace std {
template<> class vector<CTYPE > {
SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE)
};
}
%enddef
SWIG_STD_VECTOR_SPECIALIZE(float, float)
%inline %{
typedef float Real;
%}
#if 1
//fails
namespace std {
%template(RealVector) vector<Real>;
}
#else
//works
%template(RealVector) std::vector<Real>;
#endif