unable to retrieve python exception type objects (C api)

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

unable to retrieve python exception type objects (C api)

Philip Scott
Hi Folks,

According to the documentation online:

SIP generates a Python object for each exception defined with the <a class="gmail-reference gmail-internal" href="http://pyqt.sourceforge.net/Docs/sip4/directives.html#directive-%Exception" style="color:rgb(65,134,203);text-decoration-line:none">%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 issipException_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/
#include <exception>
  const char* what = sipExceptionRef.what();
    PyErr_SetString(sipException_std_exception, what);

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() 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,


PyQt mailing list    [hidden email]