<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> </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> </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> </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> </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> </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 <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> 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 </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 </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'> defined in class </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'> 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> 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 </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> </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> </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> </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 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> </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 <exception></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'> 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'> 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'> 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'> 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> </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> </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 <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> 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> </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> </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 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> </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> </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> </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> </o:p></p></div></div></div></body></html>