A segmentation fault is generated, when looping a wrapped public std::list from python, where the wrapper code was generated with the "-threads" argument.
E.g.:
== foo.cpp ==
#include <string>
#include <list>
class foo {
public:
foo() : bar() {}
std::list<std::string> bar;
};
==========
== foo.i ==
%module foo
%include <stl.i>
%include <std_list.i>
%template(StringList) std::list<std::string>;
%{
#include "foo.cpp"
%}
%include "foo.cpp"
========
$ swig -c++ -python -threads -o foo_wrap.cpp foo.i
$ g++ -fPIC -c foo_wrap.cpp -I<PYTHON_INCLUDE_PATH>
$ g++ -shared foo_wrap.o foo.o
$ python
>>> import foo
>>> f = foo.foo()
>>> print f.bar
<foo.StringList; proxy of <Swig Object of type 'std::list< std::string,std::allocator< std::string > > *' at 0x1004d0de0> >
>>> f.bar.append("test")
>>> f.bar[0]
'test'
>>> for i in f.bar:
... print i
...
test
Segmentation fault
Last g++ command is wrong. it should be:
$ g++ -shared foo_wrap.o -o _foo.so -l<PYTHON_LIBNAME>.
I find that if I comment/remove the SWIG_PYTHON_THREAD_BEGIN_ALLOW and SWIG_PYTHON_THREAD_END_ALLOW macros in the _wrap_delete_SwigPyIterator method then no segmentation fault is generated.
The testcase works with current SWIG git master so it seems the cause has been fixed in the meantime.