From d5b765d3888d82d8b6a420b80047278c81c4ef95 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Fri, 2 May 2014 16:16:11 +0200 Subject: Whitespace cleanup of all Makefiles* - some of the %.clean rules in the test-suite Makefiles were using a single tab as an empty rule, dangerous! I've replaced these with the safer '@exit 0'. --- Lib/python/Makefile.in | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'Lib/python') diff --git a/Lib/python/Makefile.in b/Lib/python/Makefile.in index 71effea70..27c384449 100644 --- a/Lib/python/Makefile.in +++ b/Lib/python/Makefile.in @@ -1,6 +1,6 @@ # --------------------------------------------------------------- # SWIG Python Makefile -# +# # This file can be used to build various Python extensions with SWIG. # By default this file is set up for dynamic loading, but it can # be easily customized for static extensions by modifying various @@ -17,11 +17,11 @@ # script and should already reflect your machine. #---------------------------------------------------------------- -SRCS = -CXXSRCS = -OBJCSRCS = -OBJS = -INTERFACE = +SRCS = +CXXSRCS = +OBJCSRCS = +OBJS = +INTERFACE = WRAPFILE = $(INTERFACE:.i=_wrap.c) WRAPOBJ = $(INTERFACE:.i=_wrap.o) TARGET = module@SO@ # Use this kind of target for dynamic loading @@ -32,8 +32,8 @@ exec_prefix = @exec_prefix@ CC = @CC@ CXX = @CXX@ -OBJC = @CC@ -Wno-import # -Wno-import needed for gcc -CFLAGS = +OBJC = @CC@ -Wno-import # -Wno-import needed for gcc +CFLAGS = INCLUDES = LIBS = @@ -42,9 +42,9 @@ LIBS = # SWIGOPT = SWIG compiler options # SWIGCC = Compiler used to compile the wrapper file -SWIG = $(exec_prefix)/bin/swig -SWIGOPT = -python -SWIGCC = $(CC) +SWIG = $(exec_prefix)/bin/swig +SWIGOPT = -python +SWIGCC = $(CC) # SWIG Library files. Uncomment if rebuilding the Python interpreter #SWIGLIBS = -lembed.i @@ -67,11 +67,11 @@ BUILD = @LDSHARED@ # need to provide additional link libraries (this is not always required). #DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \ - -L/usr/local/lib -lg++ -lstdc++ -lgcc + -L/usr/local/lib -lg++ -lstdc++ -lgcc # Python installation -PY_INCLUDE = -DHAVE_CONFIG_H @PYINCLUDE@ +PY_INCLUDE = -DHAVE_CONFIG_H @PYINCLUDE@ PY_LIB = @PYLIB@ # Build libraries (needed for static builds) @@ -107,7 +107,7 @@ all: $(TARGET) # Convert the wrapper file into an object file $(WRAPOBJ) : $(WRAPFILE) - $(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(WRAPFILE) $(INCLUDES) $(PY_INCLUDE) + $(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(WRAPFILE) $(INCLUDES) $(PY_INCLUDE) $(WRAPFILE) : $(INTERFACE) $(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIBS) $(INTERFACE) @@ -117,7 +117,3 @@ $(TARGET): $(WRAPOBJ) $(ALLOBJS) clean: rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET) - - - - -- cgit v1.2.1 From 9846f3f1eac0835e9d1870f41ea0c03f3006a687 Mon Sep 17 00:00:00 2001 From: Harvey Falcic Date: Wed, 16 Apr 2014 11:13:21 -0400 Subject: Python 3 byte string output: use errors="surrogateescape" ... if available on the version of Python that's in use. This allows obtaining the original byte string (and potentially trying a fallback encoding) if the bytes can't be decoded as UTF-8. Previously, a UnicodeDecodeError would be raised with no way to treat the data as bytes or try another codec. --- Lib/python/pystrings.swg | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Lib/python') diff --git a/Lib/python/pystrings.swg b/Lib/python/pystrings.swg index f6a4eba8a..2b14547ad 100644 --- a/Lib/python/pystrings.swg +++ b/Lib/python/pystrings.swg @@ -89,7 +89,11 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size) SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void(); } else { %#if PY_VERSION_HEX >= 0x03000000 +%#if PY_VERSION_HEX >= 0x03010000 + return PyUnicode_DecodeUTF8(carray, %numeric_cast(size,int), "surrogateescape"); +%#else return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int)); +%#endif %#else return PyString_FromStringAndSize(carray, %numeric_cast(size,int)); %#endif -- cgit v1.2.1 From 0d589349a19aded355e2e1489e63c5b6ee126da5 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 6 Jun 2014 11:03:46 +0200 Subject: Fixed pep8 issues E701, E203, E231, E261 --- Lib/python/pyiterators.swg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Lib/python') diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg index f93594c4c..110c431fe 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -344,7 +344,8 @@ namespace swig %feature("python:slot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__; #else %extend SwigPyIterator { - %pythoncode {def __iter__(self): return self} + %pythoncode {def __iter__(self): + return self} } #endif -- cgit v1.2.1 From f4fffbf668781f5308d1e944dc25238c93082b1c Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 6 Jun 2014 15:13:23 +0200 Subject: Fixed another E701 --- Lib/python/pycontainer.swg | 3 ++- Lib/python/std_map.i | 12 ++++++++---- Lib/python/std_unordered_map.i | 12 ++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'Lib/python') diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index dcada87c7..425cc45fc 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -710,7 +710,8 @@ namespace swig #if defined(SWIGPYTHON_BUILTIN) %feature("python:slot", "tp_iter", functype="getiterfunc") iterator; #else - %pythoncode {def __iter__(self): return self.iterator()} + %pythoncode {def __iter__(self): + return self.iterator()} #endif } diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 66ed68da5..58902bca4 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -176,10 +176,14 @@ #else %extend { - %pythoncode {def __iter__(self): return self.key_iterator()} - %pythoncode {def iterkeys(self): return self.key_iterator()} - %pythoncode {def itervalues(self): return self.value_iterator()} - %pythoncode {def iteritems(self): return self.iterator()} + %pythoncode {def __iter__(self): + return self.key_iterator()} + %pythoncode {def iterkeys(self): + return self.key_iterator()} + %pythoncode {def itervalues(self): + return self.value_iterator()} + %pythoncode {def iteritems(self): + return self.iterator()} } #endif diff --git a/Lib/python/std_unordered_map.i b/Lib/python/std_unordered_map.i index b456035e2..737468234 100644 --- a/Lib/python/std_unordered_map.i +++ b/Lib/python/std_unordered_map.i @@ -231,10 +231,14 @@ return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); } - %pythoncode {def __iter__(self): return self.key_iterator()} - %pythoncode {def iterkeys(self): return self.key_iterator()} - %pythoncode {def itervalues(self): return self.value_iterator()} - %pythoncode {def iteritems(self): return self.iterator()} + %pythoncode {def __iter__(self): + return self.key_iterator()} + %pythoncode {def iterkeys(self): + return self.key_iterator()} + %pythoncode {def itervalues(self): + return self.value_iterator()} + %pythoncode {def iteritems(self): + return self.iterator()} } %enddef -- cgit v1.2.1 From 6fe71da9fa6ff525808a7076f96b0df2c522bef7 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Sat, 7 Jun 2014 13:09:15 +0200 Subject: Fixed remaining pep8 errors --- Lib/python/std_pair.i | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'Lib/python') diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i index 782969574..73d47e198 100644 --- a/Lib/python/std_pair.i +++ b/Lib/python/std_pair.i @@ -176,18 +176,20 @@ SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c) %define %swig_pair_methods(pair...) #if !defined(SWIGPYTHON_BUILTIN) %extend { -%pythoncode {def __len__(self): return 2 -def __repr__(self): return str((self.first, self.second)) +%pythoncode {def __len__(self): + return 2 +def __repr__(self): + return str((self.first, self.second)) def __getitem__(self, index): - if not (index % 2): - return self.first - else: - return self.second + if not (index % 2): + return self.first + else: + return self.second def __setitem__(self, index, val): - if not (index % 2): - self.first = val - else: - self.second = val} + if not (index % 2): + self.first = val + else: + self.second = val} } #endif %enddef -- cgit v1.2.1 From de6b433cb178c2e4b7b2f3c7dfc02a90ddedfccf Mon Sep 17 00:00:00 2001 From: Thomas Maslach Date: Tue, 23 Sep 2014 20:22:20 +0100 Subject: Fix Python crash when using -threads iterating containers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fixes li_std_vector_enum testcase when run with -threads. Patch supplied on swig-devel mailing list on 12 Sep with details... ============================================== I just wanted to mention that I found a crash issue in bug.. I am using SWIG 2.0.11 with python and have –threads enabled. I have a C++ std::vector that I instantiate in SWIG with %template. I also have a method in a class that returns this vector. I also include std_vector.i, btw.. When I iterate like so: children = Action.getActionList() for child in children: pass Everything is fine.. When I iterate like this: for child in Action.getActionList() pass Product crashes. The problem is the following. This code gets called first: SWIGINTERN PyObject *_wrap_delete_SwigPyIterator(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; swig::SwigPyIterator *arg1 = (swig::SwigPyIterator *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; if(!PyArg_UnpackTuple(args,(char *)"delete_SwigPyIterator",1,1,&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_SwigPyIterator" "', argument " "1"" of type '" "swig::SwigPyIterator *""'"); } arg1 = reinterpret_cast< swig::SwigPyIterator * >(argp1); { SWIG_PYTHON_THREAD_BEGIN_ALLOW; delete arg1; SWIG_PYTHON_THREAD_END_ALLOW; } resultobj = SWIG_Py_Void(); return resultobj; fail: return NULL; } Note the SWIG_PYTHON_THREAD_BEGIN_ALLOW/END_ALLOW. In between those two statements, we delete arg1. That in turn will eventually end up in this code: namespace swig { class SwigPtr_PyObject { protected: PyObject *_obj; public: … snip! … ~SwigPtr_PyObject() { Py_XDECREF(_obj); } Uh-oh! We call Py_XDECREF when we aren’t supposed to because we are in a SWIG_PYTHON_THREAD_BEGIN_ALLOW/END_ALLOW section! This takes care of the issue: namespace swig { class SwigPtr_PyObject { protected: PyObject *_obj; public: … snip! … ~SwigPtr_PyObject() { SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XDECREF(_obj); SWIG_PYTHON_THREAD_END_BLOCK; } There are several other methods in this class that use the Python API, but don’t have the BEGIN/END block defined. I’m not sure if they are required for all of them, but I believe they are.. I have attached a modified pyclasses.swg with what I believe are the correct changes. This code is from 2.0.11, but as far as I can tell, it’s the same as what is in 3.0.2… Apologies for not doing more here (making/running tests, getting it in the code repository, etc..), but I’m under some pressure to get some unrelated things done… --- Lib/python/pyclasses.swg | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Lib/python') diff --git a/Lib/python/pyclasses.swg b/Lib/python/pyclasses.swg index b73ebdbb8..9d6299ff1 100644 --- a/Lib/python/pyclasses.swg +++ b/Lib/python/pyclasses.swg @@ -72,27 +72,35 @@ namespace swig { SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(_obj); + SWIG_PYTHON_THREAD_END_BLOCK; } SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj) { if (initial_ref) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(_obj); + SWIG_PYTHON_THREAD_END_BLOCK; } } SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XINCREF(item._obj); Py_XDECREF(_obj); _obj = item._obj; + SWIG_PYTHON_THREAD_END_BLOCK; return *this; } ~SwigPtr_PyObject() { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_XDECREF(_obj); + SWIG_PYTHON_THREAD_END_BLOCK; } operator PyObject *() const -- cgit v1.2.1 From a89a8928431034c389afbb9ef7bd3f8c5691d968 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 6 Oct 2014 20:22:51 +0100 Subject: Fixes when using python -builtin and STL container wrappers. Deletion of single elements previously failed. Test case li_std_containers_int now works. --- Lib/python/pycontainer.swg | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Lib/python') 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); } -- cgit v1.2.1 From a6efdb7999298de6be8c5b4f1fca4ff60ac1fb20 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 28 Oct 2014 06:59:30 +0000 Subject: Fix when is 'self' used as a parameter name in Python Fix corner case for variable names called 'self' after merging in patch #201 --- Lib/python/pythonkw.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/python') diff --git a/Lib/python/pythonkw.swg b/Lib/python/pythonkw.swg index 8ad0ef11b..2f76a664a 100644 --- a/Lib/python/pythonkw.swg +++ b/Lib/python/pythonkw.swg @@ -130,7 +130,7 @@ PYTHONKW(None); /* 'self' is also a bad Name */ -PYTHONBN(self); +PYTHONKW(self); #undef PYTHONBN #undef PYTHONKW -- cgit v1.2.1 From 7d4af72dde1d9e8413173628c11534f5ac815ef8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 29 Oct 2014 09:42:11 +0000 Subject: Revert "Fix when is 'self' used as a parameter name in Python" This reverts commit a6efdb7999298de6be8c5b4f1fca4ff60ac1fb20. --- Lib/python/pythonkw.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/python') diff --git a/Lib/python/pythonkw.swg b/Lib/python/pythonkw.swg index 2f76a664a..8ad0ef11b 100644 --- a/Lib/python/pythonkw.swg +++ b/Lib/python/pythonkw.swg @@ -130,7 +130,7 @@ PYTHONKW(None); /* 'self' is also a bad Name */ -PYTHONKW(self); +PYTHONBN(self); #undef PYTHONBN #undef PYTHONKW -- cgit v1.2.1 From 6029b2f7d83251dbc6349de2c1c606859c727044 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 30 Oct 2014 07:22:59 +0000 Subject: Fix for 'self' being used as a parameter name --- Lib/python/pythonkw.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/python') diff --git a/Lib/python/pythonkw.swg b/Lib/python/pythonkw.swg index 8ad0ef11b..2f76a664a 100644 --- a/Lib/python/pythonkw.swg +++ b/Lib/python/pythonkw.swg @@ -130,7 +130,7 @@ PYTHONKW(None); /* 'self' is also a bad Name */ -PYTHONBN(self); +PYTHONKW(self); #undef PYTHONBN #undef PYTHONKW -- cgit v1.2.1 From 0ad384bb288bcd25347d26c71c4ca5b3c4e0aee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Sat, 25 Oct 2014 23:11:37 +0200 Subject: fixed python global object constants Fix for Python and -builtin Fix from Github issue #250 --- Lib/python/pyinit.swg | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Lib/python') diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index b44c2c893..38822e414 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -401,6 +401,12 @@ SWIG_init(void) { #else m = Py_InitModule((char *) SWIG_name, SwigMethods); #endif + +#ifdef SWIGPYTHON_BUILTIN + PyObject *self = m; + (void)self; +#endif + md = d = PyModule_GetDict(m); (void)md; -- cgit v1.2.1 From 1db561cf0862f39c24960eec31015be3e96730be Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 18 Dec 2014 06:54:09 +0000 Subject: Improve Python builtin and %constant structs Tweak to previous commit from issue #250 for C compatibility. Set self to zero too. --- Lib/python/pyinit.swg | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'Lib/python') diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 38822e414..47d3d9700 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -375,6 +375,7 @@ SWIG_init(void) { PyObject *public_interface, *public_symbol; PyObject *this_descr; PyObject *thisown_descr; + PyObject *self = 0; int i; (void)builtin_pytype; @@ -382,6 +383,7 @@ SWIG_init(void) { (void)builtin_basetype; (void)tuple; (void)static_getset; + (void)self; /* metatype is used to implement static member variables. */ metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type); @@ -402,11 +404,6 @@ SWIG_init(void) { m = Py_InitModule((char *) SWIG_name, SwigMethods); #endif -#ifdef SWIGPYTHON_BUILTIN - PyObject *self = m; - (void)self; -#endif - md = d = PyModule_GetDict(m); (void)md; -- cgit v1.2.1 From 38ba81811e4fd7743570cf3ca6b9a57a720444a1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 8 Jan 2015 23:33:47 +0000 Subject: Fix Python default argument handing broken since swig-3.0.3 Default values are no longer generated as Python code by default. They must be explicitly turned on using the "python:defaultargs" feature. Closes #294 Closes #296 The problems in these two issues when "python:defaultargs" is turned on still need to be fixed and should be addressed in separate patches. The important thing is the default code generation is now fixed. --- Lib/python/pyuserdir.swg | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Lib/python') diff --git a/Lib/python/pyuserdir.swg b/Lib/python/pyuserdir.swg index d3c3eb188..2a1d80790 100644 --- a/Lib/python/pyuserdir.swg +++ b/Lib/python/pyuserdir.swg @@ -185,6 +185,16 @@ These methods "may be called" if needed. #define %clearpythonappend %feature("pythonappend","") +/* ------------------------------------------------------------------------- */ +/* + Python default argument handling (for non-builtin) +*/ + +#define %pythondefaultargs %feature("python:defaultargs") +#define %nopythondefaultargs %feature("python:defaultargs", "0") +#define %clearpythondefaultargs %feature("python:defaultargs", "") + + /* ------------------------------------------------------------------------- */ /* -- cgit v1.2.1 From 9d87b9f099cf1dd3978375d3a4a109221570e7f9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 12 Jan 2015 21:35:47 +0000 Subject: Revert introduction of python:defaultargs feature See issue #294 --- Lib/python/pyuserdir.swg | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'Lib/python') diff --git a/Lib/python/pyuserdir.swg b/Lib/python/pyuserdir.swg index 2a1d80790..00aec07d5 100644 --- a/Lib/python/pyuserdir.swg +++ b/Lib/python/pyuserdir.swg @@ -185,17 +185,6 @@ These methods "may be called" if needed. #define %clearpythonappend %feature("pythonappend","") -/* ------------------------------------------------------------------------- */ -/* - Python default argument handling (for non-builtin) -*/ - -#define %pythondefaultargs %feature("python:defaultargs") -#define %nopythondefaultargs %feature("python:defaultargs", "0") -#define %clearpythondefaultargs %feature("python:defaultargs", "") - - - /* ------------------------------------------------------------------------- */ /* %extend_smart_pointer extend the smart pointer support. -- cgit v1.2.1