Here's a patch.

Arve

On Sat, Jun 13, 2009 at 4:44 PM, Arve Knudsen <[email protected]>wrote:

> Phil, there seems to be bug in SIP 4.8's exception wrapping. I noticed
> Python would segfault when importing a SIP-generated module which defined an
> exception, and when looking at the generated source I see a rather
> suspicious block of code.
>
> For the attached SIP specification, the following block is generated for
> instantiating the Python exception (in siptstcmodule.cpp):
>
> if ((exceptionsTable[0] = PyErr_NewException((char
> *)"tst.MyException",PyExc_Exception,NULL)) == NULL ||
> PyDict_SetItemString(sipModuleDict,"MyException",exceptionsTable[0]) < 0)
>         return;
>         {
>             Py_DECREF(sip_sipmod);
>             Py_DECREF(sipModule);
>             SIP_MODULE_RETURN(0);
>         }
>
>
> That "return;" looks a bit misplaced doesn't it? When I remove it, the
> module no longer segfaults at least.
>
> Arve
>
diff -ru sip-4.8_old/sipgen/gencode.c sip-4.8/sipgen/gencode.c
--- sip-4.8_old/sipgen/gencode.c	2009-06-05 10:59:07.000000000 +0200
+++ sip-4.8/sipgen/gencode.c	2009-06-13 17:24:07.000000000 +0200
@@ -1906,12 +1906,11 @@
             prcode(fp, "sipException_%C", xd->base->iff->fqcname);
 
         prcode(fp, ",NULL)) == NULL || PyDict_SetItemString(sipModuleDict,\"%s\",exceptionsTable[%d]) < 0)\n"
-"        return;\n"
-"        {\n"
-"            Py_DECREF(sip_sipmod);\n"
-"            Py_DECREF(sipModule);\n"
-"            SIP_MODULE_RETURN(0);\n"
-"        }\n"
+"    {\n"
+"        Py_DECREF(sip_sipmod);\n"
+"        Py_DECREF(sipModule);\n"
+"        SIP_MODULE_RETURN(0);\n"
+"    }\n"
             , xd->pyname, xd->exceptionnr);
     }
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to