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

List:       pykde
Subject:    [PyQt] Slot lookup fails when inheritance depth is larger than one
From:       Matt Newell <newellm () blur ! com>
Date:       2015-01-28 15:56:19
Message-ID: 6829777.fzf571Td0A () obsidian
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I first discovered this with comparison not working as 
expected with a wrapped type.  The __eq__ slot lookup 
was failing because sip only looks at the 
sipClassTypeDef and the direct parent.  Neither contain 
slots because they are defined in the grandparent.

Attached is a patch that implements a depth first 
recursive algorithm for slot lookup, which fixes the 
problem for me.

Matt

[Attachment #5 (unknown)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" \
"http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" \
content="1" /><style type="text/css"> p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'DejaVu Sans Mono'; font-size:9pt; \
font-weight:400; font-style:normal;"> <p style="-qt-paragraph-type:empty; \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; ">&nbsp;</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">I first discovered this with comparison not \
working as expected with a wrapped type.  The __eq__ slot lookup was failing because \
sip only looks at the sipClassTypeDef and the direct parent.  Neither contain slots \
because they are defined in the grandparent.</p> <p style="-qt-paragraph-type:empty; \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; ">&nbsp;</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">Attached is a patch that implements a depth first \
recursive algorithm for slot lookup, which fixes the problem for me.</p> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; ">&nbsp;</p> <p style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Matt</p></body></html>


["slot_lookup.patch" (slot_lookup.patch)]

Index: siplib.c.in
===================================================================
--- siplib.c.in	(revision 16327)
+++ siplib.c.in	(working copy)
@@ -635,7 +635,8 @@
 static void addClassSlots(sipWrapperType *wt, const sipClassTypeDef *ctd);
 static void addTypeSlots(PyHeapTypeObject *heap_to, sipPySlotDef *slots);
 static void *findSlot(PyObject *self, sipPySlotType st);
-static void *findSlotInType(sipPySlotDef *psd, sipPySlotType st);
+static void *findSlotInType(sipClassTypeDef *psd, sipPySlotType st);
+static void *findSlotInSlotList(sipPySlotDef *psd, sipPySlotType st);
 static int objobjargprocSlot(PyObject *self, PyObject *arg1, PyObject *arg2,
         sipPySlotType st);
 static int ssizeobjargprocSlot(PyObject *self, SIP_SSIZE_T arg1,
@@ -9239,27 +9240,7 @@
 
         ctd = (sipClassTypeDef *)((sipWrapperType *)(py_type))->type;
 
-        if (ctd->ctd_pyslots != NULL)
-            slot = findSlotInType(ctd->ctd_pyslots, st);
-        else
-            slot = NULL;
-
-        if (slot == NULL)
-        {
-            sipEncodedTypeDef *sup;
-
-            /* Search any super-types. */
-            if ((sup = ctd->ctd_supers) != NULL)
-                do
-                {
-                    const sipClassTypeDef *sup_ctd = sipGetGeneratedClassType(
-                            sup, ctd);
-
-                    if (sup_ctd->ctd_pyslots != NULL)
-                        slot = findSlotInType(sup_ctd->ctd_pyslots, st);
-                }
-                while (slot == NULL && !sup++->sc_flag);
-        }
+        slot = findSlotInType(ctd, st);
     }
     else
     {
@@ -9272,7 +9253,7 @@
 
         assert(etd->etd_pyslots != NULL);
 
-        slot = findSlotInType(etd->etd_pyslots, st);
+        slot = findSlotInSlotList(etd->etd_pyslots, st);
     }
 
     return slot;
@@ -9282,8 +9263,36 @@
 /*
  * Find a particular slot function in a particular type.
  */
-static void *findSlotInType(sipPySlotDef *psd, sipPySlotType st)
+static void *findSlotInType(sipClassTypeDef *ctd, sipPySlotType st)
 {
+    void *slot;
+    if (ctd->ctd_pyslots != NULL)
+        slot = findSlotInSlotList(ctd->ctd_pyslots, st);
+    else
+        slot = NULL;
+
+    if (slot == NULL)
+    {
+        sipEncodedTypeDef *sup;
+
+        /* Search any super-types. */
+        if ((sup = ctd->ctd_supers) != NULL)
+            do
+            {
+                const sipClassTypeDef *sup_ctd = sipGetGeneratedClassType(
+                        sup, ctd);
+
+                slot = findSlotInType(sup_ctd, st);
+            }
+            while (slot == NULL && !sup++->sc_flag);
+    }
+
+    return slot;
+}
+
+
+static void *findSlotInSlotList(sipPySlotDef *psd, sipPySlotType st)
+{
     while (psd->psd_func != NULL)
     {
         if (psd->psd_type == st)

[Attachment #7 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://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