[PyQt] unable to retrieve python exception type objects (C api)

Philip Scott safetyfirstphil at gmail.com
Fri Apr 21 13:13:21 BST 2017


Hi Folks,

According to the documentation online:

SIP generates a Python object for each exception defined with the %Exception
 directive.

These objects are named with the fully qualified exception name (i.e.
including any enclosing scope) prefixed by sipException_. For example, the
type object for enum Except defined in class Klass is
sipException_Klass_Except.

The objects of all imported exceptions are available to handwritten code.

This worked for us well in 4.17. I am trying to upgrade to 4.19 and came
across a problem. In 4.19, for a SIP module called say, 'foo,' there *is* an
#define in sipAPIfoo.h of the form

#define sipException_my_exception sipExportedExceptions_foo[0]
However, the array sipExportedExceptions_foo is defined in
'sipfoocmodule.cpp' but not declared in any header file.

I managed to work around this in one module by simply declaring it before
my handwritten C code:

extern PyObject *sipExportedExceptions_foo[3];

But unfortunately got completely stuck when I came a cross a SIP file that
was shared between a couple of different modules as the name of the module
it was going to be used in could not be known. The code looks a bit like
this (I believe it was also taken from the PyQt example documentation
somewhere):

%Exception std::exception(SIP_Exception) /PyName=StdException/
{
%TypeHeaderCode
#include <exception>
%End
%RaiseCode
  const char* what = sipExceptionRef.what();
  SIP_BLOCK_THREADS
    PyErr_SetString(sipException_std_exception, what);
  SIP_UNBLOCK_THREADS
%End
};

I wonder if this is related to the incompatibility notes from the 4.19
release:

Starting with this version only those type structures needed by the
generated code are automatically available to handwritten code possibly
resulting in compiler errors. Handwritten code should be changed to call
sipFindType()
<http://pyqt.sourceforge.net/Docs/sip4/c_api.html#c.sipFindType> to obtain
a pointer to the required type structure.

I did try using sipFindType to find my exception type but with no success,
and looking at the generated code I can't see anywhere that the exceptions
are registered in any way except in the python module dictionary.

Apologies if this question has been asked already - I did do a quick ctrl+f
of the post titles to the mailing list; I couldn't find a better way to
search. I've been googling for a solid day, I can't believe this hasn't
affected anyone else - perhaps our usage is non-standard in some way?

Anyhow, any pointers would be greatly appreciated.

All the best,

Philip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170421/b803977e/attachment.html>


More information about the PyQt mailing list