[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] unable to retrieve python exception type objects (C api)
From:       "Mathias Born" <mathias.born () gmx ! de>
Date:       2017-05-04 19:44:00
Message-ID: 02cb01d2c50e$c7cb01f0$576105d0$ () gmx ! de
[Download RAW message or body]

This is a multipart message in MIME format.

[Attachment #2 (multipart/alternative)]
This is a multipart message in MIME format.


Hi,

 

I can't offer any help, but let you know that I've been working around this bug since \
years in a similar way, but never bothered to file a bug report.

 

Best Regards,

Mathias

 

From: PyQt [mailto:pyqt-bounces@riverbankcomputing.com] On Behalf Of Philip Scott
Sent: Freitag, 21. April 2017 14:13
To: pyqt@riverbankcomputing.com
Subject: [PyQt] unable to retrieve python exception type objects (C api)

 

Hi Folks,

 

According to the documentation online:

SIP generates a Python object for each exception defined with the  \
<http://pyqt.sourceforge.net/Docs/sip4/directives.html#directive-%Exception> \
%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/

{

%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  \
<http://pyqt.sourceforge.net/Docs/sip4/c_api.html#c.sipFindType> 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

 


[Attachment #5 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type \
content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 \
(filtered medium)"><style><!-- /* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p
	{mso-style-priority:99;
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Times New Roman",serif;}
code
	{mso-style-priority:99;
	font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
	{mso-style-name:msonormal;
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Times New Roman",serif;}
span.gmail-pre
	{mso-style-name:gmail-pre;}
span.EmailStyle21
	{mso-style-type:personal-reply;
	font-family:"Calibri",sans-serif;
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri",sans-serif;
	mso-fareast-language:EN-US;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=DE link=blue vlink=purple><div \
class=WordSection1><p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'>Hi,<o:p></o:p></span></p><p \
class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'>I \
can't offer any help, but let you know that I've been working around this bug since \
years in a similar way, but never bothered to file a bug \
report.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'>Best \
Regards,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'>Mathias<o:p></o:p></span></p><p \
class=MsoNormal><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'><o:p>&nbsp;</o:p></span></p><div \
style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div \
style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p \
class=MsoNormal><b><span lang=EN-US \
style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span \
lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif'> PyQt \
[mailto:pyqt-bounces@riverbankcomputing.com] <b>On Behalf Of </b>Philip \
Scott<br><b>Sent:</b> Freitag, 21. April 2017 14:13<br><b>To:</b> \
pyqt@riverbankcomputing.com<br><b>Subject:</b> [PyQt] unable to retrieve python \
exception type objects (C api)<o:p></o:p></span></p></div></div><p \
class=MsoNormal><o:p>&nbsp;</o:p></p><div><p class=MsoNormal><span \
style='font-family:"Arial",sans-serif'>Hi Folks,</span><o:p></o:p></p><div><p \
class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal><span \
style='font-family:"Arial",sans-serif'>According to the documentation \
online:</span><o:p></o:p></p></div><blockquote \
style='margin-left:30.0pt;margin-right:0cm'><div><p \
style='text-align:justify;line-height:11.7pt'><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>SIP generates a \
Python object for each exception defined with the&nbsp;<a \
href="http://pyqt.sourceforge.net/Docs/sip4/directives.html#directive-%Exception"><span \
class=gmail-pre><b><span style='font-size:10.0pt;font-family:"Courier \
New";color:#4186CB'>%Exception</span></b></span></a>&nbsp;directive.</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
style='text-align:justify;line-height:11.7pt'><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>These objects are \
named with the fully qualified exception name (i.e. including any enclosing scope) \
prefixed by&nbsp;</span><span class=gmail-pre><span \
style='font-size:10.0pt;font-family:"Courier \
New";color:black'>sipException_</span></span><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>. For example, the \
type object for enum&nbsp;</span><span class=gmail-pre><span \
style='font-size:10.0pt;font-family:"Courier \
New";color:black'>Except</span></span><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>&nbsp;defined in \
class&nbsp;</span><span class=gmail-pre><span \
style='font-size:10.0pt;font-family:"Courier \
New";color:black'>Klass</span></span><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>&nbsp;is</span><span \
class=gmail-pre><span style='font-size:10.0pt;font-family:"Courier \
New";color:black'>sipException_Klass_Except</span></span><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>.</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
style='text-align:justify;line-height:11.7pt'><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>The objects of all \
imported exceptions are available to handwritten code.</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div></blockquote><div><p \
style='text-align:justify;line-height:11.7pt'><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>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 <i>is</i>&nbsp;an #define in sipAPIfoo.h of the \
form</span><span style='font-size:9.0pt;color:black'><o:p></o:p></span></p><p \
style='text-align:justify;line-height:11.7pt'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>#define \
sipException_my_exception sipExportedExceptions_foo[0]</span><o:p></o:p></p><p \
class=MsoNormal style='text-align:justify'><span \
style='font-family:"Arial",sans-serif'>However, the array&nbsp;</span><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>sipExportedExceptions_foo \
is defined in 'sipfoocmodule.cpp' but not declared in any header \
file.</span><o:p></o:p></p></div><p class=MsoNormal \
style='text-align:justify'><o:p>&nbsp;</o:p></p><p class=MsoNormal \
style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>I managed to work \
around this in one module by simply declaring it before my handwritten C \
code:</span><o:p></o:p></p><p class=MsoNormal \
style='text-align:justify'><o:p>&nbsp;</o:p></p><p class=MsoNormal \
style='text-align:justify'><span style='font-size:9.0pt;font-family:"Courier \
New";color:black'>extern PyObject \
*sipExportedExceptions_foo[3];</span><o:p></o:p></p><p class=MsoNormal \
style='text-align:justify'><o:p>&nbsp;</o:p></p><p class=MsoNormal \
style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Arial",sans-serif;color:black'>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&nbsp;it was also taken from the \
PyQt example documentation somewhere):</span><o:p></o:p></p><p class=MsoNormal \
style='text-align:justify'><o:p>&nbsp;</o:p></p><div><p class=MsoNormal \
style='text-align:justify'><span style='font-size:9.0pt;font-family:"Courier \
New";color:black'>%Exception std::exception(SIP_Exception) \
/PyName=StdException/</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>{</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier \
New";color:black'>%TypeHeaderCode</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>#include \
&lt;exception&gt;</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>%End</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>%RaiseCode</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>&nbsp;     const char* \
what = sipExceptionRef.what();</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>&nbsp;     \
SIP_BLOCK_THREADS</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>&nbsp; &nbsp; \
PyErr_SetString(sipException_std_exception, what);</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>&nbsp;     \
SIP_UNBLOCK_THREADS</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>%End</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;font-family:"Courier New";color:black'>};</span><span \
style='font-size:9.0pt;color:black'><o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;color:black'><o:p>&nbsp;</o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;color:black'>I wonder if this is related to the \
incompatibility notes from the 4.19 release:<o:p></o:p></span></p></div><div><p \
class=MsoNormal style='text-align:justify'><span \
style='font-size:9.0pt;color:black'><o:p>&nbsp;</o:p></span></p></div><blockquote \
style='margin-left:30.0pt;margin-right:0cm'><div><p class=MsoNormal \
style='text-align:justify'><span style='font-size:9.0pt;color:black'>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&nbsp;<a \
href="http://pyqt.sourceforge.net/Docs/sip4/c_api.html#c.sipFindType" \
title=sipFindType><span class=gmail-pre><b><span \
style='font-size:10.0pt;font-family:"Courier \
New";color:#4186CB'>sipFindType()</span></b></span></a>&nbsp;to obtain a pointer to \
the required type structure.<o:p></o:p></span></p></div><div><p class=MsoNormal \
style='text-align:justify'><span \
style='font-size:9.0pt;color:black'><o:p>&nbsp;</o:p></span></p></div></blockquote><p \
class=MsoNormal><span style='font-size:9.0pt;color:black'>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.</span><o:p></o:p></p><div><p \
class=MsoNormal><o:p>&nbsp;</o:p></p></div><p class=MsoNormal \
style='text-align:justify'><span style='font-size:9.0pt;color:black'>Apologies if \
this question has been asked already - I did do a quick ctrl+f of the post titles to \
the mailing&nbsp;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?</span><o:p></o:p></p><p class=MsoNormal \
style='text-align:justify'><o:p>&nbsp;</o:p></p><p class=MsoNormal \
style='text-align:justify'><span style='font-size:9.0pt;color:black'>Anyhow, any \
pointers would be greatly appreciated.</span><o:p></o:p></p><p class=MsoNormal \
style='text-align:justify'><o:p>&nbsp;</o:p></p><p class=MsoNormal \
style='text-align:justify'><span style='font-size:9.0pt;color:black'>All the \
best,</span><o:p></o:p></p><p class=MsoNormal \
style='text-align:justify'><o:p>&nbsp;</o:p></p><p class=MsoNormal \
style='text-align:justify'><span \
style='font-size:9.0pt;color:black'>Philip</span><o:p></o:p></p><p class=MsoNormal \
style='text-align:justify'><o:p>&nbsp;</o:p></p></div></div></div></body></html>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic