Go to file
Thomas Maslach de6b433cb1 Fix Python crash when using -threads iterating containers
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…
2014-09-23 22:33:25 +01:00
CCache CCache: always generate docs in source directory 2014-05-29 02:24:33 +02:00
Doc [PHP] Add support for specifying any PHP interfaces a wrapped class 2014-09-12 12:48:37 -03:00
Examples Fix Python crash when using -threads iterating containers 2014-09-23 22:33:25 +01:00
Lib Fix Python crash when using -threads iterating containers 2014-09-23 22:33:25 +01:00
Source Fix one case where we test goout rather than has_goout. The effect 2014-09-12 17:46:21 -07:00
Tools Update AX_BOOST_BASE autoconf macro to serial 23 2014-05-29 19:54:13 +01:00
Win The great merge 2002-11-30 22:01:28 +00:00
debian Remove cvsignore files: this is stored on svn:igonre property now 2006-12-03 08:28:42 +00:00
vms file changed 2002-12-11 22:43:46 +00:00
.gitattributes Add .gitattributes file 2013-05-12 19:14:59 +01:00
.gitignore Add generated Go files to .gitignore. 2014-08-25 15:58:10 -07:00
.travis.yml Suppress Octave failing the build 2014-09-16 19:19:48 +01:00
ANNOUNCE Bump version to 3.0.3 2014-06-06 19:56:38 +01:00
CHANGES Fix incorrect examples of regex %rename 2014-08-12 14:33:25 +12:00
CHANGES.current Fix Python crash when using -threads iterating containers 2014-09-23 22:33:25 +01:00
COPYRIGHT Restore missing copyright info in javascript branch 2014-04-25 07:57:32 +01:00
INSTALL The great merge 2002-11-30 22:01:28 +00:00
LICENSE SWIG license change - Licenses put in place and bump version to 2.0.0 - Source moves to GPLv3. The Examples and Lib move to a very permissive license, removing the BSD license restrictions as agreed by committers since it was inadvertently introduced. 2010-02-27 23:04:21 +00:00
LICENSE-GPL SWIG license change - Licenses put in place and bump version to 2.0.0 - Source moves to GPLv3. The Examples and Lib move to a very permissive license, removing the BSD license restrictions as agreed by committers since it was inadvertently introduced. 2010-02-27 23:04:21 +00:00
LICENSE-UNIVERSITIES Fix grammatical error introduced by previous fix. 2010-06-21 03:37:08 +00:00
Makefile.in check-maintainer-clean: print skipping message for in-source-tree builds 2014-05-29 14:40:50 +02:00
README Bump version to 3.0.3 2014-06-06 19:56:38 +01:00
RELEASENOTES Add 3.0.2 release date 2014-06-04 08:48:04 +01:00
TODO PHP directors now done. WAD has been removed. 2011-06-03 13:49:18 +00:00
autogen.sh update some comments 2008-11-07 21:25:31 +00:00
configure.ac Merge pull request #188 from jschueller/python_pep8 2014-06-10 23:48:38 +12:00
preinst-swig.in Quote $builddir and @srcdir@ to protect from the shell. 2008-05-10 10:30:31 +00:00
swig.spec.in Replace references to Subversion with Git 2013-01-12 01:24:22 +00:00

README

SWIG (Simplified Wrapper and Interface Generator)

Version: 3.0.3 (in progress)

Tagline: SWIG is a compiler that integrates C and C++ with languages
         including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua,
         Octave, R, Scheme (Guile, MzScheme/Racket, CHICKEN), Ocaml,
         Modula-3, Common Lisp (CLISP, Allegro CL, CFFI, UFFI) and Pike.
         SWIG can also export its parse tree into Lisp s-expressions and
         XML.

SWIG reads annotated C/C++ header files and creates wrapper code (glue
code) in order to make the corresponding C/C++ libraries available to
the listed languages, or to extend C/C++ programs with a scripting
language.

Up-to-date SWIG related information can be found at

        http://www.swig.org

A SWIG FAQ and other hints can be found on the SWIG Wiki:

        http://www.dabeaz.com/cgi-bin/wiki.pl

License
=======
Please see the LICENSE file for details of the SWIG license. For
further insight into the license including the license of SWIG's
output code, please visit

        http://www.swig.org/legal.html

Release Notes
=============
Please see the CHANGES.current file for a detailed list of bug fixes and
new features for the current release. The CHANGES file contains bug fixes
and new features for older versions. A summary of changes in each release
can be found in the RELEASENOTES file.

Documentation
=============
The Doc/Manual directory contains the most recent set of updated
documentation for this release. The documentation is available in
three different formats, each of which contains identical content.
These format are, pdf (Doc/Manual/SWIGDocumentation.pdf), single
page html (Doc/Manual/SWIGDocumentation.html) or multiple page html
(other files in Doc/Manual). Please select your chosen format and
copy/install to wherever takes your fancy.

There is some technical developer documentation available in the
Doc/Devel subdirectory.  This is not necessarily up-to-date, but it
has some information on SWIG internals.

Documentation is also online at http://www.swig.org/doc.html.

Backwards Compatibility
=======================
The developers strive their best to preserve backwards compatibility
between releases, but this is not always possible as the overriding
aim is to provide the best wrapping experience. Where backwards
compatibility is known to be broken, it is clearly marked as an
incompatibility in the CHANGES and CHANGES.current files.

See the documentation for details of the SWIG_VERSION preprocessor
symbol if you have backward compatibility issues and need to use more
than one version of SWIG.

Installation
============
Please read the Doc/Manual/Preface.html#Preface_installation for
full installation instructions for Windows, Unix and Mac OS X.
The INSTALL file has generic build and installation instructions for
Unix users.

Testing
=======
The typical 'make -k check' can be performed on Unix operating systems.
Please read Doc/Manual/Preface.html#Preface_testing for details.

Examples
========
The Examples directory contains a variety of examples of using SWIG
and it has some browsable documentation.  Simply point your browser to
the file "Example/index.html".

The Examples directory also includes Visual C++ project 6 (.dsp) files for
building some of the examples on Windows. Later versions of Visual Studio
will convert these old style project files into a current solution file.

Known Issues
============
There are minor known bugs, details of which are in the bug tracker, see
http://www.swig.org/bugs.html.

Troubleshooting
===============
In order to operate correctly, SWIG relies upon a set of library
files.  If after building SWIG, you get error messages like this,

    $ swig foo.i
    :1. Unable to find 'swig.swg'
    :3. Unable to find 'tcl8.swg'

it means that SWIG has either been incorrectly configured or
installed.  To fix this:

    1.  Make sure you remembered to do a 'make install' and that
        the installation actually worked.  Make sure you have
        write permission on the install directory.

    2.  If that doesn't work, type 'swig -swiglib' to find out
        where SWIG thinks its library is located.

    3.  If the location is not where you expect, perhaps
        you supplied a bad option to configure.  Use
        ./configure --prefix=pathname to set the SWIG install
        location.   Also, make sure you don't include a shell
        escape character such as ~ when you specify the path.

    4.  The SWIG library can be changed by setting the SWIG_LIB
        environment variable.  However, you really shouldn't
        have to do this.

If you are having other troubles, you might look at the SWIG Wiki at
http://www.dabeaz.com/cgi-bin/wiki.pl.

Participate!
============
Please report any errors and submit patches (if possible)!  We only
have access to a limited variety of hardware (Linux, Solaris, OS-X,
and Windows). All contributions help.

If you would like to join the SWIG development team or contribute a
language module to the distribution, please contact the swig-devel
mailing list, details at http://www.swig.org/mail.html.


 -- The SWIG Maintainers