#827 RuntimeError in garbage collection with shadowed functions

closed-fixed
python (259)
5
2009-11-14
2007-05-29
Luke Moore
No

When swig wraps the following overloaded functions:
foo(const std::vector<float>& values);
foo(const std::vector<std::string>& values);
the wrapper code it generates calls swig::asptr() to check if the argument is a vector of floats or a vector of strings. However, if swig::asptr() fails, it raises a Python RuntimeError that often isn't apparent until garbage collection occurs.

Attached is an example illustrating the problem. It wraps the above functions into a module named shadow, and then runs the following:

luke@lasalle:~/shadow_problem$ python2.5
Python 2.5.1 (r251:54863, Apr 25 2007, 21:31:46)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gc
>>> import shadow
>>> shadow.foo(("one", "two"))
one two
>>> gc.collect()
Exception exceptions.RuntimeError: 'in sequence element 0' in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
Aborted
luke@lasalle:~/shadow_problem$

The run_it.sh script in the tarball will invoke swig, compile the shared object, and invoke Python.

I'm using swig 1.3.31 and gcc 4.1.3 on Debian unstable.

Discussion

  • Luke Moore

    Luke Moore - 2007-05-29

    Sample to reproduce the problem

     
    Attachments
  • Luke Moore

    Luke Moore - 2007-05-29

    Logged In: YES
    user_id=1437974
    Originator: YES

    I was able to avoid the RuntimeError by changing swig::traits_asptr_stdseq::asptr to pass false to PySequence_Cont::check() so it doesn't set the error. I don't know if this is the proper fix, though.

     
  • William Fulton

    William Fulton - 2009-11-14
    • assigned_to: marcelomatus --> wsfulton
    • status: open --> closed-fixed
     
  • William Fulton

    William Fulton - 2009-11-14

    swig-1.3.34 fixed various STL containers conversion problems which seems to have solved this problem too.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks