diff --git a/CHANGES.current b/CHANGES.current index d5dcb05f6..781b21c1c 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-09-23: wsfulton + [Python] Add patch from Thomas Maslach to fix crash in wrappers when using -threads in + the STL iterators (SwigPyIterator destructor). + 2014-09-17: wsfulton [C#] Merge patch #229 from contre - Add bool array types to arrays_csharp.i diff --git a/Examples/test-suite/python/python_threads_runme.py b/Examples/test-suite/python/python_threads_runme.py new file mode 100644 index 000000000..d00e2458f --- /dev/null +++ b/Examples/test-suite/python/python_threads_runme.py @@ -0,0 +1,10 @@ +from python_threads import * + +action = ActionGroup() +count = 1 +for child in action.GetActionList(): + if child.val != count: + raise RuntimeError("Expected: " + str(count) + " got: " + str(child.val)) + count = count + 1 + +# Was seg faulting at the end here diff --git a/Examples/test-suite/python_threads.i b/Examples/test-suite/python_threads.i new file mode 100644 index 000000000..08eddef11 --- /dev/null +++ b/Examples/test-suite/python_threads.i @@ -0,0 +1,40 @@ +%module(threads=1) python_threads + +%include + +%inline %{ +struct Action { + int val; + Action(int val = 0) : val(val) {} +}; +%} + +%template(VectorActionPtr) std::vector; + +%inline %{ +#include +#include +template struct myStlVector : public std::vector { +}; +typedef myStlVector ActionList; + +%} + +%template(ActionList) myStlVector; + +%inline %{ +class ActionGroup +{ +public: + ActionList &GetActionList () const { + static ActionList list; + list.push_back(new Action(1)); + list.push_back(new Action(2)); + list.push_back(new Action(3)); + list.push_back(new Action(4)); + return list; + } +}; +%} + + 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