[PyQt] unable to retrieve python exception type objects (C api)
phil at riverbankcomputing.com
Mon Apr 24 18:39:08 BST 2017
On 21 Apr 2017, at 1:13 pm, Philip Scott <safetyfirstphil at gmail.com> wrote:
> 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 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
> 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;
> 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.
Hmm, so little code, so many bugs...
Can you try tonight's snapshot?
More information about the PyQt