Merged from branches/szager-python-builtin

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12596 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Stefan Zager 2011-04-03 08:33:41 +00:00
commit bc9a32a658
53 changed files with 3413 additions and 563 deletions

View file

@ -0,0 +1,35 @@
ifeq (,$(PY3))
PYSCRIPT = runme.py
else
PYSCRIPT = runme3.py
endif
default : all
include ../../Makefile
SUBDIRS := constructor func hierarchy operator hierarchy_operator
all : $(SUBDIRS:%=%-build)
@for subdir in $(SUBDIRS); do \
echo Running $$subdir test... ; \
echo -------------------------------------------------------------------------------- ; \
cd $$subdir; \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT); \
cd ..; \
done
$(SUBDIRS) :
$(MAKE) -C $@
@echo Running $$subdir test...
@echo --------------------------------------------------------------------------------
cd $@ && env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT)
%-build :
$(MAKE) -C $*
%-clean :
$(MAKE) -s -C $* clean
clean : $(SUBDIRS:%=%-clean)
rm -f *.pyc

View file

@ -0,0 +1,21 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,8 @@
%inline %{
class MyClass {
public:
MyClass () {}
~MyClass () {}
void func () {}
};
%}

View file

@ -0,0 +1,11 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
for i in range(1000000) :
x = mod.MyClass()
harness.run(proc)

View file

@ -0,0 +1,23 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
default : all
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,8 @@
%inline %{
class MyClass {
public:
MyClass () {}
~MyClass () {}
void func () {}
};
%}

View file

@ -0,0 +1,12 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
x = mod.MyClass()
for i in range(10000000) :
x.func()
harness.run(proc)

View file

@ -0,0 +1,30 @@
#!/usr/bin/env
import sys
import time
import imp
from subprocess import *
def run (proc) :
try :
mod = imp.find_module(sys.argv[1])
mod = imp.load_module(sys.argv[1], *mod)
t1 = time.clock()
proc(mod)
t2 = time.clock()
print "%s took %f seconds" % (mod.__name__, t2 - t1)
except IndexError :
proc = Popen([sys.executable, 'runme.py', 'Simple_baseline'], stdout=PIPE)
(stdout, stderr) = proc.communicate()
print stdout
proc = Popen([sys.executable, 'runme.py', 'Simple_optimized'], stdout=PIPE)
(stdout, stderr) = proc.communicate()
print stdout
proc = Popen([sys.executable, 'runme.py', 'Simple_builtin'], stdout=PIPE)
(stdout, stderr) = proc.communicate()
print stdout

View file

@ -0,0 +1,23 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
default : all
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,52 @@
%inline %{
class A {
public:
A () {}
~A () {}
void func () {}
};
class B : public A {
public:
B () {}
~B () {}
};
class C : public B {
public:
C () {}
~C () {}
};
class D : public C {
public:
D () {}
~D () {}
};
class E : public D {
public:
E () {}
~E () {}
};
class F : public E {
public:
F () {}
~F () {}
};
class G : public F {
public:
G () {}
~G () {}
};
class H : public G {
public:
H () {}
~H () {}
};
%}

View file

@ -0,0 +1,12 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
x = mod.H()
for i in range(10000000) :
x.func()
harness.run(proc)

View file

@ -0,0 +1,23 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
default : all
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,53 @@
%inline %{
class A {
public:
A () {}
~A () {}
void func () {}
A& operator+= (int i) { return *this; }
};
class B : public A {
public:
B () {}
~B () {}
};
class C : public B {
public:
C () {}
~C () {}
};
class D : public C {
public:
D () {}
~D () {}
};
class E : public D {
public:
E () {}
~E () {}
};
class F : public E {
public:
F () {}
~F () {}
};
class G : public F {
public:
G () {}
~G () {}
};
class H : public G {
public:
H () {}
~H () {}
};
%}

View file

@ -0,0 +1,12 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
x = mod.H()
for i in range(10000000) :
x += i
harness.run(proc)

View file

@ -0,0 +1,23 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
default : all
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,8 @@
%inline %{
class MyClass {
public:
MyClass () {}
~MyClass () {}
MyClass& operator+ (int i) { return *this; }
};
%}

View file

@ -0,0 +1,12 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
x = mod.MyClass()
for i in range(10000000) :
x = x + i
harness.run(proc)

View file

@ -61,6 +61,7 @@ CPP_TEST_CASES += \
python_kwargs \
python_nondynamic \
python_overload_simple_cast \
python_richcompare \
std_containers \
swigobject \
template_matrix \

View file

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

View file

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

View file

@ -66,11 +66,15 @@ except MyException, e:
if not ok:
raise RuntimeError
# This is expected to fail with -builtin option
# Throwing builtin classes as exceptions not supported
try:
raise Exception2()
except Exception2:
pass
# This is expected to fail with -builtin option
# Throwing builtin classes as exceptions not supported
try:
raise Exception1()
except Exception1:

View file

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

View file

@ -11,3 +11,4 @@ if x != -37:
raise RuntimeError
grouping.cvar.test3 = 42
grouping.test3 = 42

View file

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

View file

@ -54,9 +54,13 @@ 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"

View file

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

View file

@ -1,5 +1,9 @@
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)

View file

@ -13,7 +13,6 @@ except:
if not err:
raise RuntimeError, "A is not static"
class B(python_nondynamic.A):
c = 4
def __init__(self):
@ -21,10 +20,19 @@ class B(python_nondynamic.A):
pass
pass
bb = B()
bb.c = 3
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
@ -33,7 +41,6 @@ except:
if not err:
raise RuntimeError, "B is not static"
cc = python_nondynamic.C()
cc.d = 3

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

View file

@ -18,8 +18,11 @@ except RuntimeError,e:
if e.args[0] != "I died.":
raise RuntimeError
# This is expected fail with -builtin option
# Throwing builtin classes as exceptions not supported
try:
t.hosed()
pass
except threads_exception.Exc,e:
if e.code != 42:
raise RuntimeError

View file

@ -0,0 +1,60 @@
/* Test the tp_richcompare functions generated with the -builtin option */
%module python_richcompare
%inline {
class BaseClass {
public:
BaseClass (int i_) : i(i_) {}
~BaseClass () {}
int getValue () const
{ return i; }
bool operator< (const BaseClass& x) const
{ return this->i < x.i; }
bool operator> (const BaseClass& x) const
{ return this->i > x.i; }
bool operator<= (const BaseClass& x) const
{ return this->i <= x.i; }
bool operator>= (const BaseClass& x) const
{ return this->i >= x.i; }
bool operator== (const BaseClass& x) const
{ return this->i == x.i; }
bool operator!= (const BaseClass& x) const
{ return this->i != x.i; }
int i;
};
class SubClassA : public BaseClass {
public:
SubClassA (int i_) : BaseClass(i_) {}
~SubClassA () {}
bool operator== (const SubClassA& x) const
{ return true; }
bool operator== (const BaseClass& x) const
{ return false; }
};
class SubClassB : public BaseClass {
public:
SubClassB (int i_) : BaseClass(i_) {}
~SubClassB () {}
bool operator== (const SubClassB& x) const
{ return true; }
bool operator== (const SubClassA& x) const
{ return false; }
};
}