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

@ -1,5 +1,5 @@
TOP = ../../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
SWIGOPT = -I../../Include
SRCS =
TARGET = gifplot
@ -23,3 +23,4 @@ clean::
rm -f *.gif
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -1,5 +1,5 @@
TOP = ../../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
SWIGOPT = -I../../Interface
SRCS =
TARGET = gifplot
@ -23,3 +23,4 @@ clean::
rm -f *.gif
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -1,5 +1,5 @@
TOP = ../../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
SWIGOPT =
SRCS =
TARGET = simple
@ -23,3 +23,4 @@ clean::
rm -f *.gif
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -223,19 +223,39 @@ perl5_clean:
##################################################################
# Make sure these locate your Python installation
PYTHON_INCLUDE= $(DEFS) @PYINCLUDE@
PYTHON_LIB = @PYLIB@
ifeq (,$(PY3))
PYTHON_INCLUDE= $(DEFS) @PYINCLUDE@
PYTHON_LIB = @PYLIB@
PYTHON = @PYTHON@
else
PYTHON_INCLUDE= $(DEFS) @PY3INCLUDE@
PYTHON_LIB = @PY3LIB@
PYTHON = @PYTHON3@
endif
# Extra Python specific dynamic linking options
PYTHON_DLNK = @PYTHONDYNAMICLINKING@
# Extra Python specific linking options
ifeq (,$(PY3))
PYTHON_DLNK = @PYTHONDYNAMICLINKING@
PYTHON_LINK = @PYLINK@
else
PYTHON_DLNK = @PYTHON3DYNAMICLINKING@
PYTHON_LINK = @PY3LINK@
endif
PYTHON_SO = @PYTHON_SO@
# SWIG option for Python
ifeq (,$(PY3))
SWIGPYTHON = $(SWIG) -python
else
SWIGPYTHON = $(SWIG) -python -py3
endif
# ----------------------------------------------------------------
# Build a C dynamically loadable module
# ----------------------------------------------------------------
python: $(SRCS)
$(SWIG) -python $(SWIGOPT) $(INTERFACE)
$(SWIGPYTHON) $(SWIGOPT) $(INTERFACE)
$(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(PYTHON_INCLUDE)
$(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO)
@ -244,7 +264,7 @@ python: $(SRCS)
# -----------------------------------------------------------------
python_cpp: $(SRCS)
$(SWIG) -c++ -python $(SWIGOPT) $(INTERFACE)
$(SWIGPYTHON) -c++ $(SWIGOPT) $(INTERFACE)
$(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(PYTHON_INCLUDE)
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(PYTHON_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)_$(TARGET)$(PYTHON_SO)
@ -257,18 +277,37 @@ python_cpp: $(SRCS)
#TKINTER = -L/usr/X11R6.3/lib -L/usr/local/compat/lib -ltk4.0 -ltcl7.4 -lX11
TKINTER =
PYTHON_LIBOPTS = @PYLINK@ @LIBS@ $(TKINTER) $(SYSLIBS)
PYTHON_LIBOPTS = $(PYTHON_LINK) @LIBS@ $(TKINTER) $(SYSLIBS)
python_static: $(SRCS)
$(SWIG) -python -lembed.i $(SWIGOPT) $(INTERFACE)
$(SWIGPYTHON) -lembed.i $(SWIGOPT) $(INTERFACE)
$(CC) $(CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCS) $(INCLUDES) \
$(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)
python_static_cpp: $(SRCS)
$(SWIG) -c++ -python -lembed.i $(SWIGOPT) $(INTERFACE)
$(SWIGPYTHON) -c++ -lembed.i $(SWIGOPT) $(INTERFACE)
$(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \
$(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)
# -----------------------------------------------------------------
# Running a Python example
# -----------------------------------------------------------------
ifeq (,$(PY3))
SCRIPT = runme.py
else
SCRIPT = runme3.py
endif
PY2TO3 = 2to3 `2to3 -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'`
python_run: $(SCRIPT)
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(SCRIPT) >/dev/null
runme3.py: runme.py
cp $< $@
$(PY2TO3) -w $@ >/dev/null 2>&1
# -----------------------------------------------------------------
# Cleaning the python examples
# -----------------------------------------------------------------
@ -278,6 +317,7 @@ python_clean:
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@ *@PYTHON_SO@
##################################################################
##### OCTAVE ######
##################################################################

View file

@ -19,3 +19,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -18,3 +18,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -21,3 +21,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -18,3 +18,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -18,3 +18,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -19,3 +19,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -19,3 +19,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -19,3 +19,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -19,3 +19,4 @@ clean::
@rm -f foo.py bar.py spam.py base.py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -19,3 +19,4 @@ clean::
@rm -f foo.py bar.py spam.py base.py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,6 +17,7 @@ extern int gcd(int x, int y);
%typemap(in,fragment="t_output_helper") (int argc, char *argv[]) {
int i;
int l;
if (!PyList_Check($input)) {
SWIG_exception(SWIG_ValueError, "Expecting a list");
}
@ -27,11 +28,21 @@ extern int gcd(int x, int y);
$2 = (char **) malloc(($1+1)*sizeof(char *));
for (i = 0; i < $1; i++) {
PyObject *s = PyList_GetItem($input,i);
if (!PyString_Check(s)) {
%#if PY_VERSION_HEX >= 0x03000000
if (!PyUnicode_Check(s))
%#else
if (!PyString_Check(s))
%#endif
{
free($2);
SWIG_exception(SWIG_ValueError, "List items must be strings");
}
%#if PY_VERSION_HEX >= 0x03000000
$2[i] = PyUnicode_AsStringAndSize(s, &l);
%#else
$2[i] = PyString_AsString(s);
%#endif
}
$2[i] = 0;
}
@ -39,12 +50,21 @@ extern int gcd(int x, int y);
extern int gcdmain(int argc, char *argv[]);
%typemap(in) (char *bytes, int len) {
%#if PY_VERSION_HEX >= 0x03000000
if (!PyUnicode_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a string");
return NULL;
}
$1 = PyUnicode_AsStringAndSize($input, &$2);
%#else
if (!PyString_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a string");
return NULL;
}
$1 = PyString_AsString($input);
$2 = PyString_Size($input);
%#endif
}
extern int count(char *bytes, int len, char c);
@ -56,9 +76,15 @@ extern int count(char *bytes, int len, char c);
so that we don't violate it's mutability */
%typemap(in) (char *str, int len) {
%#if PY_VERSION_HEX >= 0x03000000
$2 = PyUnicode_GetSize($input);
$1 = (char *) malloc($2+1);
memmove($1,PyUnicode_AsString($input),$2);
%#else
$2 = PyString_Size($input);
$1 = (char *) malloc($2+1);
memmove($1,PyString_AsString($input),$2);
%#endif
}
/* Return the mutated string as a new object. The t_output_helper
@ -67,7 +93,11 @@ extern int count(char *bytes, int len, char c);
%typemap(argout) (char *str, int len) {
PyObject *o;
%#if PY_VERSION_HEX >= 0x03000000
o = PyUnicode_FromStringAndSize($1,$2);
%#else
o = PyString_FromStringAndSize($1,$2);
%#endif
$result = t_output_helper($result,o);
free($1);
}

View file

@ -19,3 +19,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -18,3 +18,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -19,3 +19,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -22,3 +22,4 @@ run:
python runme.py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -19,3 +19,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -22,3 +22,4 @@ clean::
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -19,3 +19,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -19,3 +19,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -237,6 +237,7 @@ CPP_TEST_CASES += \
null_pointer \
operator_overload \
operator_overload_break \
operbool \
ordering \
overload_copy \
overload_extend \

View file

@ -4,7 +4,7 @@
#ifndef SWIG_CSTRING_UNIMPL
%cstring_input_binary(char *in, int n);
%cstring_input_binary(char *str_in, int n);
%cstring_bounded_output(char *out1, 512);
%cstring_chunk_output(char *out2, 64);
%cstring_bounded_mutable(char *out3, 512);
@ -22,13 +22,13 @@
%inline %{
int count(char *in, int n, char c) {
int count(char *str_in, int n, char c) {
int r = 0;
while (n > 0) {
if (*in == c) {
if (*str_in == c) {
r++;
}
in++;
str_in++;
--n;
}
return r;

View file

@ -4,7 +4,7 @@
#ifndef SWIG_CWSTRING_UNIMPL
%cwstring_input_binary(wchar_t *in, int n);
%cwstring_input_binary(wchar_t *str_in, int n);
%cwstring_bounded_output(wchar_t *out1, 512);
%cwstring_chunk_output(wchar_t *out2, 64);
%cwstring_bounded_mutable(wchar_t *out3, 512);
@ -22,13 +22,13 @@
%inline %{
int count(wchar_t *in, int n, wchar_t c) {
int count(wchar_t *str_in, int n, wchar_t c) {
int r = 0;
while (n > 0) {
if (*in == c) {
if (*str_in == c) {
r++;
}
in++;
str_in++;
--n;
}
return r;

View file

@ -58,13 +58,12 @@ namespace std
%template(max_i) max<int>;
%inline {
/* silently rename the parameter names in csharp/java */
#ifdef SWIGR
double foo(double inparam, double out) { return 1.0; }
#else
double foo(double in, double out) { return 1.0; }
double foo(double abstract, double out) { return 1.0; }
#endif
double bar(double native, bool boolean) { return 1.0; }
}

View file

@ -75,7 +75,7 @@ namespace test {
class string_class;
#ifdef SWIGPYTHON
%typemap(in) string_class * {
$1 = new string_class(PyString_AsString($input));
$1 = new string_class(SWIG_Python_str_AsChar($input));
}
%typemap(freearg) string_class * {
delete $1;

View file

@ -0,0 +1,10 @@
%module operbool
%inline %{
class Test {
public:
operator bool() {
return false;
}
};
%}

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