[PyQt] Problem catching exception from SIP-wrapped function

Phil Thompson phil at riverbankcomputing.com
Thu Sep 24 19:12:21 BST 2009


On Thu, 24 Sep 2009 20:05:06 +0200, Arve Knudsen <arve.knudsen at gmail.com>
wrote:
> Hi Phil
> 
> On Wed, Sep 23, 2009 at 9:43 PM, Phil Thompson
> <phil at riverbankcomputing.com>wrote:
> 
>> On Tue, 22 Sep 2009 20:28:09 +0200, Arve Knudsen
<arve.knudsen at gmail.com>
>> wrote:
>> > On Tue, Sep 22, 2009 at 7:27 PM, Phil Thompson
>> > <phil at riverbankcomputing.com>wrote:
>> >
>> >> On Tue, 22 Sep 2009 19:17:12 +0200, Arve Knudsen
>> <arve.knudsen at gmail.com>
>> >> wrote:
>> >> > On Tue, Sep 22, 2009 at 6:28 PM, Phil Thompson
>> >> > <phil at riverbankcomputing.com>wrote:
>> >> >
>> >> >> On Mon, 21 Sep 2009 18:40:35 +0200, Arve Knudsen
>> >> <arve.knudsen at gmail.com>
>> >> >> wrote:
>> >> >> > Hi
>> >> >> >
>> >> >> > I have run into this problem where a C++ exception is not
>> >> >> > correctly
>> >> >> > translated into Python on Linux (it works under VC++ on
Windows).
>> >> >> > The
>> >> >> > exception is apparently not caught as it should, but looking at
>> >> >> > the
>> >> >> > SIP-generated sourcecode I cannot see why (there is a try/catch
>> >> >> > block
>> >> >> > for
>> >> >> > the exception). Any ideas as to what might be going wrong here?
I
>> >> >> > have
>> >> >> > tried
>> >> >> > std::exception instead of my custom exception, and this gets
>> >> translated
>> >> >> > correctly to Python.
>> >> >> >
>> >> >> > Attached I have a simple library 'raiser', which is wrapped by
>> >> >> > the
>> >> >> > Python
>> >> >> > module 'raiser'. In order to build it, first build a shared
>> >> >> > library
>> >> >> > from
>> >> >> > 'raiser.cpp', then run 'configure.py' and make.
>> >> >>
>> >> >> Works fine for me on Linux with the current SIP snapshot. I did
>> change
>> >> >> your
>> >> >> code first to make everything in-line so it wasn't necessary to
>> >> >> build
>> >> >> a
>> >> >> separate library.
>> >> >
>> >> >
>> >> > By inlining you remove the problem of interest, which is to
>> >> > propagate
>> >> > an
>> >> > exception from one library to another. It also works for me when
>> >> inlining,
>> >> > so try my original version please.
>> >>
>> >> That implies it's a build system issue. Can you send me the Makefile
>> >> you
>> >> are using to build the library so that I know I'm exactly reproducing
>> >> what
>> >>  you are doing.
>> >
>> >
>> > For this particular case, you can do the simplest thing possible: g++
>> > -shared -o libraiser.so raiser.cpp.
>>
>> And add -fPIC presumably.
>>
> 
> I forgot about that actually, apparently it made no difference :)
> 
> You need to add "export_all=True" when creating the Makefile in your
>> configure.py.
>>
> 
> Thanks, this worked for my simple case. However, it does not help in our
> real project (although the exceptions' corresponding symbols in the
> binaries
> now seem more consistent with the throwing module), so I'm guessing that
> the
> issue is with different build parameters for our C++ and Python
subsystems.
> The C++ part of our project is built with QMake, is there any standard
way
> of passing parameters from a QMake setup to the SIP configuration system,
> so
> that they are consistent?

Not specifically, but SIP's spec files are copies of (old) qmake spec
files. You could copy in the qmake spec file you are using and see if that
helps. You could argue that, if using the same spec file, SIP generates
different compiler/linker flags to qmake then its a bug in SIP.

Phil


More information about the PyQt mailing list