Segfault sometime happen in exceptions when I use swig with python c++ and
I fix this enclosing %typemap(throws,noblock=1) SWIGTYPE with
SWIG_PYTHON_THREAD_BEGIN_BLOCK/END_BLOCK in typemaps/swigtype.swg exception
diff patch for typemaps/swigtype.swg lock problem
Thanks fo the patch. I can't apply this as-is, since it adds Python-specific macros in a generic file, so it will break all the other backends, but it shows what you did.
Looking at what gets called, some is already protected by SWIG_PYTHON_THREAD_BEGIN_BLOCK, but not everything. It would be good not to have a pointless nested lock here, but that needs a bit of refactoring.
Do you have a simple testcase?
I don't have a simple test case but maybe I can made a complex one ;)
In fact we're developping a framework who will be release next week (or few times later) who uses swig intensively.
Our api is made of different swig module and one is for exceptions, we also load some cpp modules that aren't wrapped with swig, when we throw an exceptions from that modules that are load with dlopen it arrives some time that it segfaut, in fact I launch serveral times the modules and from times to times it segfault (so it's certainly a threading lock problems). So i will try to make a small testcase with the exceptions lib, the loader lib and a modules who throw an exceptions if it can help.
Thank you very much !
There was some discussion of this bug with more patches on swig-devel titled "SWIG wrapped C++ method that throw exceptions causes Python to segfault when 'thread' mode is enabled" 15 Dec 2009.
Fix applied on trunk for swig-2.0.0 on 3 April 2010.