From: SourceForge.net <no...@so...> - 2012-12-20 19:07:45
|
Bugs item #3597854, was opened at 2012-12-20 11:02 Message generated for change (Settings changed) made by ptomulik You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3597854&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None >Priority: 4 Private: No Submitted By: Paweł Tomulik (ptomulik) >Assigned to: William Fulton (wsfulton) Summary: std_except.i and bug with SWIG_STD_EXCEPTIONS_AS_CLASSES Initial Comment: Hello, I need to use standard exceptions as classes in python and can't make it work. With following simple module: ---- 8< ------------------------------ %module std_except_mod %inline %{ void foo() { throw std::logic_error("Hi there"); } %} %import <std_string.i> #define SWIG_STD_EXCEPTIONS_AS_CLASSES %include <std_except.i> void foo() { throw std::logic_error("Hi there"); } ---- 8< ------------------------------ I get a bunch of warnings when running swig on it and %exceptionclass is not applied to the standard exceptions classes being wrapped (so, I'm not able to catch them properly in python code). Compilation log says: ------- 8< --------------------------------------------------------------------------- swig -c++ -python std_except_mod.i && g++ -shared -fPIC -I . -I /usr/include/python2.7 -o _std_except_mod.so std_except_mod_wrap.cxx /usr/share/swig2.0/typemaps/std_except.swg:41: Warning 302: Identifier 'exception' redefined (ignored), /usr/share/swig2.0/std/std_except.i:13: Warning 302: previous definition of 'exception'. /usr/share/swig2.0/typemaps/std_except.swg:47: Warning 302: Identifier 'bad_exception' redefined (ignored), /usr/share/swig2.0/std/std_except.i:19: Warning 302: previous definition of 'bad_exception'. /usr/share/swig2.0/typemaps/std_except.swg:51: Warning 302: Identifier 'logic_error' redefined (ignored), /usr/share/swig2.0/std/std_except.i:23: Warning 302: previous definition of 'logic_error'. /usr/share/swig2.0/typemaps/std_except.swg:56: Warning 302: Identifier 'domain_error' redefined (ignored), /usr/share/swig2.0/std/std_except.i:28: Warning 302: previous definition of 'domain_error'. /usr/share/swig2.0/typemaps/std_except.swg:61: Warning 302: Identifier 'invalid_argument' redefined (ignored), /usr/share/swig2.0/std/std_except.i:33: Warning 302: previous definition of 'invalid_argument'. /usr/share/swig2.0/typemaps/std_except.swg:66: Warning 302: Identifier 'length_error' redefined (ignored), /usr/share/swig2.0/std/std_except.i:38: Warning 302: previous definition of 'length_error'. /usr/share/swig2.0/typemaps/std_except.swg:71: Warning 302: Identifier 'out_of_range' redefined (ignored), /usr/share/swig2.0/std/std_except.i:43: Warning 302: previous definition of 'out_of_range'. /usr/share/swig2.0/typemaps/std_except.swg:76: Warning 302: Identifier 'runtime_error' redefined (ignored), /usr/share/swig2.0/std/std_except.i:48: Warning 302: previous definition of 'runtime_error'. /usr/share/swig2.0/typemaps/std_except.swg:81: Warning 302: Identifier 'range_error' redefined (ignored), /usr/share/swig2.0/std/std_except.i:53: Warning 302: previous definition of 'range_error'. /usr/share/swig2.0/typemaps/std_except.swg:86: Warning 302: Identifier 'overflow_error' redefined (ignored), /usr/share/swig2.0/std/std_except.i:58: Warning 302: previous definition of 'overflow_error'. /usr/share/swig2.0/typemaps/std_except.swg:91: Warning 302: Identifier 'underflow_error' redefined (ignored), /usr/share/swig2.0/std/std_except.i:63: Warning 302: previous definition of 'underflow_error'. ------- 8< --------------------------------------------------------------------------- In my opinion, the problem sits in 'typemap/std_except.swg'. I'll post a patch proposition soon. Simple test in python interpreter reveals that the exception classes are not handled properly: ptomulik@barakus:$ python Python 2.7.3 (default, Sep 9 2012, 17:41:34) [GCC 4.7.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from std_except_mod import * >>> try: foo() ... except exception: pass ... Traceback (most recent call last): File "<stdin>", line 2, in <module> SystemError: 'finally' pops bad exception IHMO, the exception should be caught above. Attached is a mini-project to replicate the bug and possible patch. After patching, the project compiles without warnings and exceptions seem to be caughr correctly. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3597854&group_id=1645 |