[PyKDE] Bug in SIP 4.4.3 codegen for inplace operators +=, ...

Sylvain Defresne sylvain at eugensystems.com
Mon Jun 12 12:36:04 BST 2006


Hello,

I have found a bug in SIP 4.4.3 code generation for inplace operators 
like +=, -=, ... When presented with the following sip file,

 >    %Module vector
 >    class vector
 >    {
 >        vector(double, double, double);
 >        const vector& operator+=(const vector&);
 >    };

the code generated for the += operator is :

 >    static PyObject *slot_vector___iadd__(PyObject *sipSelf,PyObject 
*sipArg)
 >    {
 >        if (!PyObject_TypeCheck(sipSelf,(PyTypeObject *)sipClass_vector))
 >        {
 >            Py_INCREF(Py_NotImplemented);
 >            return Py_NotImplemented;
 >        }
 >
 >        vector *sipCpp = reinterpret_cast<vector 
*>(sipGetCppPtr((sipWrapper *)sipSelf,sipClass_vector));
 >
 >        if (!sipCpp)
 >            return 0;
 >
 >        int sipArgsParsed = 0;
 >
 >        {
 >            const vector * a0;
 >
 >            if 
(sipParseArgs(&sipArgsParsed,sipArg,"JA",sipClass_vector,&a0))
 >            {
 >                ((*sipCpp) += *a0));
 >
 >                Py_INCREF(sipSelf);
 >                return sipSelf;
 >            }
 >        }
 >
 >        PyErr_Clear();
 >
 >        Py_INCREF(Py_NotImplemented);
 >        return Py_NotImplemented;
 >    }

As you can see, closing parentheses are not matched with opening ones in 
the "((*sipCpp) += *a0));" code fragment. The attached patch correct 
this bug by not adding the superfluous parenthesis when the no value are 
returned. I don't know if it is the correct solution however, as I'm not 
fluent enought with the SIP code.

BTW, I hope this is a correct place to report such bug, I didn't find 
link to a bugtracker on the SIP site.

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

-------------- next part --------------
Index: sipgen/gencode.c
===================================================================
--- sipgen/gencode.c	(revision 50547)
+++ sipgen/gencode.c	(working copy)
@@ -8894,7 +8894,7 @@
 			break;
 		}
 
-  		if (needsNew && !generating_c)
+  		if (needsNew && !generating_c && is_result)
 			prcode(fp,")");
 
 		prcode(fp,";\n"


More information about the PyQt mailing list