diff --git a/.travis.yml b/.travis.yml index 8521e0cc6..fe01df47e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,10 @@ matrix: env: SWIGLANG=python PY3=3 VER=3.3 - compiler: gcc env: SWIGLANG=python PY3=3 VER=3.4 + - compiler: gcc + env: SWIGLANG=python SWIG_FEATURES=-builtin + - compiler: gcc + env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=1 - compiler: gcc env: SWIGLANG=ruby - compiler: gcc diff --git a/CHANGES.current b/CHANGES.current index b305c7627..f56b07fb9 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.3 (in progress) =========================== +2014-10-06: wsfulton + [Python] Fixes when using -builtin and std::vector/std::list wrappers to allow deletion + of single elements, such as 'del vec[0]'. + 2014-09-30: oliverb [Javascript] Merge patch #216 by Richie765 - Added support for many versions of v8 javascript. diff --git a/Examples/python/check.list b/Examples/python/check.list index e9e7c8357..a43a5fca0 100644 --- a/Examples/python/check.list +++ b/Examples/python/check.list @@ -24,7 +24,6 @@ simple smartptr std_vector std_map -swigrun template varargs variables diff --git a/Examples/python/exception/example.i b/Examples/python/exception/example.i index 08672c3a8..817c5221c 100644 --- a/Examples/python/exception/example.i +++ b/Examples/python/exception/example.i @@ -10,3 +10,12 @@ /* Let's just grab the original header file here */ %include "example.h" +%inline %{ +// The -builtin SWIG option results in SWIGPYTHON_BUILTIN being defined +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} + diff --git a/Examples/python/exception/runme.py b/Examples/python/exception/runme.py index 718707861..9e9241194 100644 --- a/Examples/python/exception/runme.py +++ b/Examples/python/exception/runme.py @@ -20,10 +20,17 @@ try: except RuntimeError,e: print e.args[0] -try: - t.hosed() -except example.Exc,e: - print e.code, e.msg +if not example.is_python_builtin(): + try: + t.hosed() + except example.Exc,e: + print e.code, e.msg +else: + try: + t.hosed() + except BaseException,e: + # Throwing builtin classes as exceptions not supported (-builtin option) + print e for i in range(1,4): try: diff --git a/Examples/python/exceptproxy/example.i b/Examples/python/exceptproxy/example.i index 4a1e0bae9..0a46afbb6 100644 --- a/Examples/python/exceptproxy/example.i +++ b/Examples/python/exceptproxy/example.i @@ -109,6 +109,12 @@ %template(doubleQueue) Queue; - - +%inline %{ +// The -builtin SWIG option results in SWIGPYTHON_BUILTIN being defined +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/python/exceptproxy/runme.py b/Examples/python/exceptproxy/runme.py index a2ae55584..07e4b0a7f 100644 --- a/Examples/python/exceptproxy/runme.py +++ b/Examples/python/exceptproxy/runme.py @@ -1,10 +1,16 @@ # file: runme.py import example +if example.is_python_builtin(): + print "Skipping example: -builtin option does not support %exceptionclass" + exit(0) + q = example.intQueue(10) print "Inserting items into intQueue" +print type(example.FullError) + try: for i in range(0,100): q.enqueue(i) diff --git a/Examples/python/import_packages/from_init1/runme.py b/Examples/python/import_packages/from_init1/runme.py index c23a085fa..bbe092bab 100644 --- a/Examples/python/import_packages/from_init1/runme.py +++ b/Examples/python/import_packages/from_init1/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) + python 'import' in __init__.py" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + if sys.version_info < (3,0): import py2.pkg2 print " Finished importing py2.pkg2" diff --git a/Examples/python/import_packages/from_init2/runme.py b/Examples/python/import_packages/from_init2/runme.py index c23a085fa..bbe092bab 100644 --- a/Examples/python/import_packages/from_init2/runme.py +++ b/Examples/python/import_packages/from_init2/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) + python 'import' in __init__.py" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + if sys.version_info < (3,0): import py2.pkg2 print " Finished importing py2.pkg2" diff --git a/Examples/python/import_packages/from_init3/runme.py b/Examples/python/import_packages/from_init3/runme.py index c23a085fa..bbe092bab 100644 --- a/Examples/python/import_packages/from_init3/runme.py +++ b/Examples/python/import_packages/from_init3/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) + python 'import' in __init__.py" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + if sys.version_info < (3,0): import py2.pkg2 print " Finished importing py2.pkg2" diff --git a/Examples/python/import_packages/relativeimport1/runme.py b/Examples/python/import_packages/relativeimport1/runme.py index 44ce8d1c4..99b6e513e 100644 --- a/Examples/python/import_packages/relativeimport1/runme.py +++ b/Examples/python/import_packages/relativeimport1/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) with -relativeimport" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) with -relativeimport" + if sys.version_info < (3,0): import py2.pkg2.bar print " Finished importing py2.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport2/runme.py b/Examples/python/import_packages/relativeimport2/runme.py index ac60eb630..f0ab6c446 100644 --- a/Examples/python/import_packages/relativeimport2/runme.py +++ b/Examples/python/import_packages/relativeimport2/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) + python 'import' in __init__.py" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + if sys.version_info < (3,0): import py2.pkg2.bar print " Finished importing py2.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport2/runme3.py b/Examples/python/import_packages/relativeimport2/runme3.py deleted file mode 100644 index 4b0d112cf..000000000 --- a/Examples/python/import_packages/relativeimport2/runme3.py +++ /dev/null @@ -1,9 +0,0 @@ -# Test import of modules content from within __init__.py -print("Testing %module(package=...) + python 'import' in __init__.py") -import sys -if sys.version_info < (3, 0): - import py2.pkg2.bar - print(" Finished importing py2.pkg2.bar") -else: - import py3.pkg2.bar - print(" Finished importing py3.pkg2.bar") diff --git a/Examples/python/import_packages/relativeimport3/runme.py b/Examples/python/import_packages/relativeimport3/runme.py index 44ce8d1c4..99b6e513e 100644 --- a/Examples/python/import_packages/relativeimport3/runme.py +++ b/Examples/python/import_packages/relativeimport3/runme.py @@ -1,6 +1,10 @@ -# Test import of modules content from within __init__.py -print "Testing %module(package=...) with -relativeimport" import sys +import os.path + +# Test import of modules content from within __init__.py +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) with -relativeimport" + if sys.version_info < (3,0): import py2.pkg2.bar print " Finished importing py2.pkg2.bar" diff --git a/Examples/python/import_packages/same_modnames1/runme.py b/Examples/python/import_packages/same_modnames1/runme.py index 923f0e0bb..7bec1ec1e 100644 --- a/Examples/python/import_packages/same_modnames1/runme.py +++ b/Examples/python/import_packages/same_modnames1/runme.py @@ -1,5 +1,9 @@ +import os.path + # Test import of same modules from different packages -print "Testing %module(package=...) + %import + same modules in different packages" +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + import pkg2.foo print " Finished importing pkg2.foo" diff --git a/Examples/python/import_packages/same_modnames2/runme.py b/Examples/python/import_packages/same_modnames2/runme.py index af8f78194..eec6121eb 100644 --- a/Examples/python/import_packages/same_modnames2/runme.py +++ b/Examples/python/import_packages/same_modnames2/runme.py @@ -1,3 +1,8 @@ +import os.path + +testname = os.path.basename(os.path.dirname(os.path.abspath(__file__))) +print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py" + import pkg1.pkg2.foo print " Finished importing pkg1.pkg2.foo" diff --git a/Examples/python/swigrun/Makefile b/Examples/python/swigrun/Makefile deleted file mode 100644 index 94f7d04e0..000000000 --- a/Examples/python/swigrun/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx -TARGET = example -INTERFACE = example.i -LIBS = -lm -SWIGOPT = - -check: build - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run - -build: - $(SWIG) -python -external-runtime - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp - -static: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static - -clean: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean - rm -f swigpyrun.h diff --git a/Examples/python/swigrun/example.cxx b/Examples/python/swigrun/example.cxx deleted file mode 100644 index 2d2471301..000000000 --- a/Examples/python/swigrun/example.cxx +++ /dev/null @@ -1,20 +0,0 @@ -/* File : example.cxx */ - -#include -#include "swigpyrun.h" -#include "example.h" - - -Manager* convert_to_Manager(PyObject *py_obj) -{ - Manager* c_ptr; - swig_type_info *ty = SWIG_TypeQuery("Manager *"); - printf("manager ty %p \n", (void *)ty); - if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty, 0) == -1) { - c_ptr = 0; - } else { - Py_XINCREF(py_obj); - } - return c_ptr; -} - diff --git a/Examples/python/swigrun/example.h b/Examples/python/swigrun/example.h deleted file mode 100644 index e89f7baaa..000000000 --- a/Examples/python/swigrun/example.h +++ /dev/null @@ -1,58 +0,0 @@ -/* File : example.h */ - -#include -#include -#include -#include -#include - -class Employee { -private: - std::string name; -public: - Employee(const char* n): name(n) {} - virtual std::string getTitle() { return getPosition() + " " + getName(); } - virtual std::string getName() { return name; } - virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } -}; - - -class Manager: public Employee { -public: - Manager(const char* n): Employee(n) {} - virtual std::string getPosition() const { return "Manager"; } -}; - - -class EmployeeList { - std::vector list; -public: - EmployeeList() { - list.push_back(new Employee("Bob")); - list.push_back(new Employee("Jane")); - list.push_back(new Manager("Ted")); - } - void addEmployee(Employee *p) { - list.push_back(p); - std::cout << "New employee added. Current employees are:" << std::endl; - std::vector::iterator i; - for (i=list.begin(); i!=list.end(); i++) { - std::cout << " " << (*i)->getTitle() << std::endl; - } - } - const Employee *get_item(int i) { - return list[i]; - } - ~EmployeeList() { - std::vector::iterator i; - std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; - for (i=list.begin(); i!=list.end(); i++) { - delete *i; - } - std::cout << "~EmployeeList empty." << std::endl; - } -}; - -Manager* convert_to_Manager(PyObject *obj); - diff --git a/Examples/python/swigrun/example.i b/Examples/python/swigrun/example.i deleted file mode 100644 index c8ec32e09..000000000 --- a/Examples/python/swigrun/example.i +++ /dev/null @@ -1,15 +0,0 @@ -/* File : example.i */ -%module(directors="1") example -%{ -#include "example.h" -%} - -%include "std_vector.i" -%include "std_string.i" - -/* turn on director wrapping for Manager */ -%feature("director") Employee; -%feature("director") Manager; - -%include "example.h" - diff --git a/Examples/python/swigrun/runme.py b/Examples/python/swigrun/runme.py deleted file mode 100644 index abcd96463..000000000 --- a/Examples/python/swigrun/runme.py +++ /dev/null @@ -1,28 +0,0 @@ -# file: runme.py - -# This file illustrates the cross language polymorphism using directors. - -import example - - -# CEO class, which overrides Employee::getPosition(). - -class CEO(example.Manager): - def __init__(self, name): - example.Manager.__init__(self, name) - def getPosition(self): - return "CEO" - def __del__(self): - print "CEO.__del__(),", self.getName() - # for proxy class extensions that are not "disowned" and - # define a __del__ method, it is very important to call the - # base class __del__. otherwise the c++ objects will never - # be deleted. - example.Manager.__del__(self) - - - - -e = CEO("Alice") -m = example.convert_to_Manager(e) -print m diff --git a/Examples/test-suite/autodoc.i b/Examples/test-suite/autodoc.i index 599a3f12f..d85899756 100644 --- a/Examples/test-suite/autodoc.i +++ b/Examples/test-suite/autodoc.i @@ -133,3 +133,11 @@ typedef int Integer; void banana(S *a, const struct tagS *b, int c, Integer d) {} %} +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} + diff --git a/Examples/test-suite/default_constructor.i b/Examples/test-suite/default_constructor.i index 091adff20..f7fc8cfa6 100644 --- a/Examples/test-suite/default_constructor.i +++ b/Examples/test-suite/default_constructor.i @@ -168,5 +168,11 @@ public: } }; - +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/test-suite/director_exception.i b/Examples/test-suite/director_exception.i index 43aeea22a..2559ae566 100644 --- a/Examples/test-suite/director_exception.i +++ b/Examples/test-suite/director_exception.i @@ -152,4 +152,10 @@ Foo *launder(Foo *f) { virtual Bar return_Bar() { return Bar(); } virtual ~ReturnAllTypes() {} }; + +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif %} diff --git a/Examples/test-suite/exception_order.i b/Examples/test-suite/exception_order.i index 4dd13858a..bca745c7e 100644 --- a/Examples/test-suite/exception_order.i +++ b/Examples/test-suite/exception_order.i @@ -125,6 +125,13 @@ } }; int A::sfoovar = 1; + +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif + %} %template(ET_i) ET; diff --git a/Examples/test-suite/import_nomodule.i b/Examples/test-suite/import_nomodule.i index 4fd5cbf65..60ef7e0f6 100644 --- a/Examples/test-suite/import_nomodule.i +++ b/Examples/test-suite/import_nomodule.i @@ -8,7 +8,7 @@ %import "import_nomodule.h" -#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP) && !defined(SWIGD) +#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGPYTHON_BUILTIN) /** * The proxy class does not have Bar derived from Foo, yet an instance of Bar @@ -40,3 +40,10 @@ class Bar : public Foo { }; #endif +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/test-suite/li_std_except_as_class.i b/Examples/test-suite/li_std_except_as_class.i index 0400c9a82..01ed1f07c 100644 --- a/Examples/test-suite/li_std_except_as_class.i +++ b/Examples/test-suite/li_std_except_as_class.i @@ -23,3 +23,11 @@ void test_domain_error() throw(std::domain_error) %include void test_domain_error() throw(std::domain_error) { throw std::domain_error("std::domain_error"); } + +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/test-suite/li_std_string_extra.i b/Examples/test-suite/li_std_string_extra.i index aa758532a..6bef12ff4 100644 --- a/Examples/test-suite/li_std_string_extra.i +++ b/Examples/test-suite/li_std_string_extra.i @@ -49,6 +49,12 @@ std::basic_string,std::allocator > test_value_ return x; } +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif + %} %include "li_std_string.i" diff --git a/Examples/test-suite/li_std_wstring.i b/Examples/test-suite/li_std_wstring.i index e0ecde53b..80f860338 100644 --- a/Examples/test-suite/li_std_wstring.i +++ b/Examples/test-suite/li_std_wstring.i @@ -92,6 +92,12 @@ void test_throw() throw(std::wstring){ #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) #endif +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif + %} diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index c00d8844c..c39a9c806 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -86,19 +86,6 @@ C_TEST_CASES += \ include $(srcdir)/../common.mk -BUILTIN_BROKEN = \ - default_constructor.cpptest \ - director_exception.cpptest \ - exception_order.cpptest \ - li_std_string_extra.cpptest \ - li_std_wstring.cpptest \ - python_abstractbase.cpptest \ - threads_exception.cpptest - -BUILTIN_NOT_BROKEN = $(filter-out $(BUILTIN_BROKEN),$(NOT_BROKEN_TEST_CASES)) - -builtin-check : $(BUILTIN_NOT_BROKEN) - # Overridden variables here SCRIPTDIR = . LIBS = -L. diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py index 5776ad3ef..3cc9400f6 100644 --- a/Examples/test-suite/python/autodoc_runme.py +++ b/Examples/test-suite/python/autodoc_runme.py @@ -1,15 +1,24 @@ from autodoc import * import sys -def check(got, expected): - if expected != got: - raise RuntimeError("\n" + "Expected: [" + str(expected) + "]\n" + "Got : [" + str(got) + "]") +def check(got, expected, expected_builtin = None, skip = False): + if not skip: + expect = expected_builtin if is_python_builtin() and expected_builtin != None else expected + if expect != got: + raise RuntimeError("\n" + "Expected: [" + str(expect) + "]\n" + "Got : [" + str(got) + "]") -check(A.__doc__, "Proxy of C++ A class") +skip = True # skip builtin check - the autodoc is missing, but it probably should not be + +check(A.__doc__, "Proxy of C++ A class", "::A") check(A.funk.__doc__, "just a string") -check(A.func0.__doc__, "func0(self, arg2, hello) -> int") -check(A.func1.__doc__, "func1(A self, short arg2, Tuple hello) -> int") -check(A.func2.__doc__, "\n" +check(A.func0.__doc__, +"func0(self, arg2, hello) -> int", +"func0(arg2, hello) -> int") +check(A.func1.__doc__, +"func1(A self, short arg2, Tuple hello) -> int", +"func1(short arg2, Tuple hello) -> int") +check(A.func2.__doc__, +"\n" " func2(self, arg2, hello) -> int\n" "\n" " Parameters:\n" @@ -17,8 +26,18 @@ check(A.func2.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func2(arg2, hello) -> int\n" +"\n" +"Parameters:\n" +" arg2: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func3.__doc__, "\n" +check(A.func3.__doc__, +"\n" " func3(A self, short arg2, Tuple hello) -> int\n" "\n" " Parameters:\n" @@ -26,19 +45,41 @@ check(A.func3.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func3(short arg2, Tuple hello) -> int\n" +"\n" +"Parameters:\n" +" arg2: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func0default.__doc__, "\n" +check(A.func0default.__doc__, +"\n" " func0default(self, e, arg3, hello, f=2) -> int\n" " func0default(self, e, arg3, hello) -> int\n" " " +, +"\n" +"func0default(e, arg3, hello, f=2) -> int\n" +"func0default(e, arg3, hello) -> int\n" +"" ) -check(A.func1default.__doc__, "\n" +check(A.func1default.__doc__, +"\n" " func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n" " func1default(A self, A e, short arg3, Tuple hello) -> int\n" " " +, +"\n" +"func1default(A e, short arg3, Tuple hello, double f=2) -> int\n" +"func1default(A e, short arg3, Tuple hello) -> int\n" +"" ) -check(A.func2default.__doc__, "\n" +check(A.func2default.__doc__, +"\n" " func2default(self, e, arg3, hello, f=2) -> int\n" "\n" " Parameters:\n" @@ -55,8 +96,27 @@ check(A.func2default.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func2default(e, arg3, hello, f=2) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +" f: double\n" +"\n" +"func2default(e, arg3, hello) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func3default.__doc__, "\n" +check(A.func3default.__doc__, +"\n" " func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n" "\n" " Parameters:\n" @@ -73,19 +133,50 @@ check(A.func3default.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func3default(A e, short arg3, Tuple hello, double f=2) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +" f: double\n" +"\n" +"func3default(A e, short arg3, Tuple hello) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func0static.__doc__, "\n" +check(A.func0static.__doc__, +"\n" " func0static(e, arg2, hello, f=2) -> int\n" " func0static(e, arg2, hello) -> int\n" " " +, +"\n" +"func0static(e, arg2, hello, f=2) -> int\n" +"func0static(e, arg3, hello) -> int\n" +"" ) -check(A.func1static.__doc__, "\n" +check(A.func1static.__doc__, +"\n" " func1static(A e, short arg2, Tuple hello, double f=2) -> int\n" " func1static(A e, short arg2, Tuple hello) -> int\n" " " +, +"\n" +"func1static(A e, short arg2, Tuple hello, double f=2) -> int\n" +"func1static(A e, short arg3, Tuple hello) -> int\n" +"" ) -check(A.func2static.__doc__, "\n" +check(A.func2static.__doc__, +"\n" " func2static(e, arg2, hello, f=2) -> int\n" "\n" " Parameters:\n" @@ -102,8 +193,27 @@ check(A.func2static.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func2static(e, arg2, hello, f=2) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg2: short\n" +" hello: int tuple[2]\n" +" f: double\n" +"\n" +"func2static(e, arg3, hello) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) -check(A.func3static.__doc__, "\n" +check(A.func3static.__doc__, +"\n" " func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" "\n" " Parameters:\n" @@ -120,31 +230,65 @@ check(A.func3static.__doc__, "\n" " hello: int tuple[2]\n" "\n" " " +, +"\n" +"func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg2: short\n" +" hello: int tuple[2]\n" +" f: double\n" +"\n" +"func3static(A e, short arg3, Tuple hello) -> int\n" +"\n" +"Parameters:\n" +" e: A *\n" +" arg3: short\n" +" hello: int tuple[2]\n" +"\n" +"" ) if sys.version_info[0:2] > (2, 4): # Python 2.4 does not seem to work - check(A.variable_a.__doc__, "A_variable_a_get(self) -> int") - check(A.variable_b.__doc__, "A_variable_b_get(A self) -> int") - check(A.variable_c.__doc__, "\n" + check(A.variable_a.__doc__, + "A_variable_a_get(self) -> int", + "A.variable_a" + ) + check(A.variable_b.__doc__, + "A_variable_b_get(A self) -> int", + "A.variable_b" + ) + check(A.variable_c.__doc__, + "\n" "A_variable_c_get(self) -> int\n" "\n" "Parameters:\n" " self: A *\n" "\n" + , + "A.variable_c" ) - check(A.variable_d.__doc__, "\n" + check(A.variable_d.__doc__, + "\n" "A_variable_d_get(A self) -> int\n" "\n" "Parameters:\n" " self: A *\n" "\n" + , + "A.variable_d" ) -check(B.__doc__, "Proxy of C++ B class") -check(C.__init__.__doc__, "__init__(self, a, b, h) -> C") -check(D.__init__.__doc__, "__init__(D self, int a, int b, Hola h) -> D") -check(E.__init__.__doc__, "\n" +check(B.__doc__, +"Proxy of C++ B class", +"::B" +) +check(C.__init__.__doc__, "__init__(self, a, b, h) -> C", None, skip) +check(D.__init__.__doc__, "__init__(D self, int a, int b, Hola h) -> D", None, skip) +check(E.__init__.__doc__, +"\n" " __init__(self, a, b, h) -> E\n" "\n" " Parameters:\n" @@ -153,8 +297,10 @@ check(E.__init__.__doc__, "\n" " h: enum Hola\n" "\n" " " +, None, skip ) -check(F.__init__.__doc__, "\n" +check(F.__init__.__doc__, +"\n" " __init__(F self, int a, int b, Hola h) -> F\n" "\n" " Parameters:\n" @@ -163,14 +309,23 @@ check(F.__init__.__doc__, "\n" " h: enum Hola\n" "\n" " " +, None, skip ) -check(B.funk.__doc__, "funk(B self, int c, int d) -> int") +check(B.funk.__doc__, +"funk(B self, int c, int d) -> int", +"funk(int c, int d) -> int") check(funk.__doc__, "funk(A e, short arg2, int c, int d) -> int") -check(funkdefaults.__doc__, "\n" +check(funkdefaults.__doc__, +"\n" " funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n" " funkdefaults(A e, short arg2, int c, int d) -> int\n" " " +, +"\n" +"funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n" +"funkdefaults(A e, short arg2, int c, int d) -> int\n" +"" ) check(func_input.__doc__, "func_input(int * INPUT) -> int") diff --git a/Examples/test-suite/python/default_constructor_runme.py b/Examples/test-suite/python/default_constructor_runme.py index 59b130559..e6532031b 100644 --- a/Examples/test-suite/python/default_constructor_runme.py +++ b/Examples/test-suite/python/default_constructor_runme.py @@ -1,8 +1,10 @@ +import _default_constructor + # 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 +if _default_constructor.is_python_builtin(): + exit(0) dc = _default_constructor diff --git a/Examples/test-suite/python/director_exception_runme.py b/Examples/test-suite/python/director_exception_runme.py index 510845a5a..de3ef22a5 100644 --- a/Examples/test-suite/python/director_exception_runme.py +++ b/Examples/test-suite/python/director_exception_runme.py @@ -68,14 +68,13 @@ if not ok: # This is expected to fail with -builtin option # Throwing builtin classes as exceptions not supported -try: - raise Exception2() -except Exception2: - pass +if not is_python_builtin(): + 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: - pass + try: + raise Exception1() + except Exception1: + pass diff --git a/Examples/test-suite/python/exception_order_runme.py b/Examples/test-suite/python/exception_order_runme.py index 38b53eb0c..8f095eb98 100644 --- a/Examples/test-suite/python/exception_order_runme.py +++ b/Examples/test-suite/python/exception_order_runme.py @@ -2,6 +2,8 @@ from exception_order import * # This test is expected to fail with -builtin option. # Throwing builtin classes as exceptions not supported +if is_python_builtin(): + exit(0) a = A() diff --git a/Examples/test-suite/python/import_nomodule_runme.py b/Examples/test-suite/python/import_nomodule_runme.py index ba0abfd9a..efcff9c48 100644 --- a/Examples/test-suite/python/import_nomodule_runme.py +++ b/Examples/test-suite/python/import_nomodule_runme.py @@ -1,5 +1,10 @@ from import_nomodule import * +# This test is expected to fail with -builtin option. +# The base class is needed for the builtin class hierarchy +if is_python_builtin(): + exit(0) + f = create_Foo() test1(f,42) delete_Foo(f) diff --git a/Examples/test-suite/python/li_std_except_as_class_runme.py b/Examples/test-suite/python/li_std_except_as_class_runme.py index 386a878bf..a86e7a562 100644 --- a/Examples/test-suite/python/li_std_except_as_class_runme.py +++ b/Examples/test-suite/python/li_std_except_as_class_runme.py @@ -1,9 +1,19 @@ from li_std_except_as_class import * -# std::domain_error hierarchy -try: test_domain_error() -except domain_error: pass -try: test_domain_error() -except logic_error: pass -try: test_domain_error() -except exception: pass +# This test is expected to fail with -builtin option. +# Throwing builtin classes as exceptions not supported +if is_python_builtin(): + try: test_domain_error() + except RuntimeError: pass + try: test_domain_error() + except RuntimeError: pass + try: test_domain_error() + except RuntimeError: pass +else: + # std::domain_error hierarchy + try: test_domain_error() + except domain_error: pass + try: test_domain_error() + except logic_error: pass + try: test_domain_error() + except exception: pass diff --git a/Examples/test-suite/python/li_std_string_extra_runme.py b/Examples/test-suite/python/li_std_string_extra_runme.py index 9e9e3d2c3..503d09eb5 100644 --- a/Examples/test-suite/python/li_std_string_extra_runme.py +++ b/Examples/test-suite/python/li_std_string_extra_runme.py @@ -56,14 +56,13 @@ if a + " world" != "hello world": # 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" +if not li_std_string_extra.is_python_builtin(): + 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" + c = "hello" + b + if c.find_last_of("l") != 9: + raise RuntimeError, "bad string mapping" s = "hello world" diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py index fecc527e0..a467ae8bc 100644 --- a/Examples/test-suite/python/li_std_wstring_runme.py +++ b/Examples/test-suite/python/li_std_wstring_runme.py @@ -60,13 +60,14 @@ if a + " world" != "hello world": raise RuntimeError("bad string mapping") # This is expected to fail if -builtin is used -if "hello" + b != "hello world": - raise RuntimeError("bad string mapping") +# Reverse operators not supported in builtin types +if not li_std_wstring.is_python_builtin(): + if "hello" + b != "hello world": + 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") + c = "hello" + b + if c.find_last_of("l") != 9: + raise RuntimeError("bad string mapping") s = "hello world" diff --git a/Examples/test-suite/python/python_abstractbase_runme3.py b/Examples/test-suite/python/python_abstractbase_runme3.py index 94dee3ff7..9b189964d 100644 --- a/Examples/test-suite/python/python_abstractbase_runme3.py +++ b/Examples/test-suite/python/python_abstractbase_runme3.py @@ -3,6 +3,8 @@ from collections import * # This is expected to fail with -builtin option # Builtin types can't inherit from pure-python abstract bases +if is_python_builtin(): + exit(0) assert issubclass(Mapii, MutableMapping) assert issubclass(Multimapii, MutableMapping) diff --git a/Examples/test-suite/python/python_append_runme.py b/Examples/test-suite/python/python_append_runme.py index 41cebad58..54d7a3e00 100644 --- a/Examples/test-suite/python/python_append_runme.py +++ b/Examples/test-suite/python/python_append_runme.py @@ -1,11 +1,16 @@ from python_append import * + +# test not relevant for -builtin +if is_python_builtin(): + exit(0) + t=Test() t.func() t.static_func() if grabpath() != os.path.dirname(mypath): - raise RuntimeError + raise RuntimeError("grabpath failed") if grabstaticpath() != os.path.basename(mypath): - raise RuntimeError + raise RuntimeError("grabstaticpath failed") diff --git a/Examples/test-suite/python/threads_exception_runme.py b/Examples/test-suite/python/threads_exception_runme.py index d4b8855fc..6fe6947ec 100644 --- a/Examples/test-suite/python/threads_exception_runme.py +++ b/Examples/test-suite/python/threads_exception_runme.py @@ -20,15 +20,16 @@ except RuntimeError,e: # This is expected fail with -builtin option # Throwing builtin classes as exceptions not supported -try: - t.hosed() -except threads_exception.Exc,e: - code = e.code - if code != 42: - raise RuntimeError, "bad... code: %d" % code - msg = e.msg - if msg != "Hosed": - raise RuntimeError, "bad... msg: '%s' len: %d" % (msg, len(msg)) +if not threads_exception.is_python_builtin(): + try: + t.hosed() + except threads_exception.Exc,e: + code = e.code + if code != 42: + raise RuntimeError, "bad... code: %d" % code + msg = e.msg + if msg != "Hosed": + raise RuntimeError, "bad... msg: '%s' len: %d" % (msg, len(msg)) for i in range(1,4): try: diff --git a/Examples/test-suite/python_abstractbase.i b/Examples/test-suite/python_abstractbase.i index f72688237..65f3d9931 100644 --- a/Examples/test-suite/python_abstractbase.i +++ b/Examples/test-suite/python_abstractbase.i @@ -16,3 +16,11 @@ namespace std %template(IntVector) vector; %template(IntList) list; } + +%inline %{ +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif +%} diff --git a/Examples/test-suite/python_append.i b/Examples/test-suite/python_append.i index 0ac54656f..f37a6c199 100644 --- a/Examples/test-suite/python_append.i +++ b/Examples/test-suite/python_append.i @@ -46,5 +46,10 @@ public: void func() {}; }; +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif %} diff --git a/Examples/test-suite/threads_exception.i b/Examples/test-suite/threads_exception.i index b374f0ce6..caa79c78e 100644 --- a/Examples/test-suite/threads_exception.i +++ b/Examples/test-suite/threads_exception.i @@ -52,4 +52,10 @@ public: return 1; } }; + +#ifdef SWIGPYTHON_BUILTIN +bool is_python_builtin() { return true; } +#else +bool is_python_builtin() { return false; } +#endif %} diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index 425cc45fc..e5543cd6b 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -874,6 +874,13 @@ namespace swig *(swig::getpos(self,i)) = x; } +#if defined(SWIGPYTHON_BUILTIN) + // This will be called through the mp_ass_subscript slot to delete an entry. + void __setitem__(difference_type i) throw (std::out_of_range) { + self->erase(swig::getpos(self,i)); + } +#endif + void append(const value_type& x) { self->push_back(x); } @@ -892,6 +899,13 @@ namespace swig *(swig::getpos(self,i)) = x; } +#if defined(SWIGPYTHON_BUILTIN) + // This will be called through the mp_ass_subscript slot to delete an entry. + void __setitem__(difference_type i) throw (std::out_of_range) { + self->erase(swig::getpos(self,i)); + } +#endif + void append(value_type x) { self->push_back(x); }