Merged the Python 3.0 support branch. The merging progress is not so smooth, so hope this commit won't make anything broken.

This is the (incomplemete) log produced by svnmerge.py:

Merged revisions 10405-10409,10420-10422,10426,10438,10445,10451,10454-10465,10467,10473-10475,10485,10488-10489,10493-10495,10497,10509-10510,10513-10514,10517,10520,10525,10528-10529,10533-10535,10554-10557,10570,10573,10593,10614,10666-10669,10673,10678,10687,10690,10704-10706,10731,10744,10750-10752,10755,10759,10770,10775-10776,10813,10819 via svnmerge from 
https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10834 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Haoyu Bai 2008-09-11 17:18:07 +00:00
commit 3d8ddfc442
75 changed files with 1603 additions and 246 deletions

View file

@ -2,14 +2,41 @@
# Makefile for python test-suite
#######################################################################
ifeq (,$(PY3))
PYBIN = @PYTHON@
else
PYBIN = @PYTHON3@
endif
LANGUAGE = python
PYTHON = @PYTHON@
SCRIPTSUFFIX = _runme.py
ifneq (,$(USE_VALGRIND))
PYTHON = valgrind --leak-check=full --suppressions=pyswig.supp $(PYBIN)
else
PYTHON = $(PYBIN)
endif
#*_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@
#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}'`
CPP_TEST_CASES += \
abstractbase \
argcargvtest \
autodoc \
callback \
@ -77,12 +104,35 @@ 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)
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
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;
endif
# Clean: remove the generated .py file
%.clean:
@ -101,14 +151,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

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

View file

@ -0,0 +1,8 @@
from 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

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

@ -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,4 @@
from director_exception import *
from exceptions import *
class MyException(Exception):
def __init__(self, a, b):

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

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

View file

@ -0,0 +1,34 @@
%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);
}
%}

View file

@ -0,0 +1,31 @@
%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);
}
%}

View file

@ -0,0 +1,16 @@
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

View file

@ -0,0 +1,16 @@
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)

View file

@ -0,0 +1,15 @@
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

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