[PyQt] Crash in sip_api_is_py_method() with PyQt 4.6

2009-10-13 Thread Victor Stinner
Hi,

I'm using Debian Sid, and my program crash since the last upgrade. The last 
upgrade installed PyQt 4.6 with SIP 4.9.

The crash is in sip_api_is_py_method(): if cls is not a PyTypeObject*, the 
dict value is a pointer to something is the memory, but not to a 
PyDictObject*. Attached patch fixes the crash.

But the new PyQt/SIP introduces a regression: I replaced contextMenu and 
mousePressEvent for some objects, and it doesn't work anymore. I don't know if 
this issue (sip_api_is_py_method() crash) is related.

-- 
Victor Stinner
http://www.haypocalc.com/
--- sip4-qt3-4.9.old/siplib/siplib.c	2009-09-26 17:14:32.0 +0200
+++ sip4-qt3-4.9/siplib/siplib.c	2009-10-13 21:12:39.0 +0200
@@ -6030,8 +6030,11 @@
 for (i = 0; i  PyTuple_GET_SIZE(mro); ++i)
 {
 PyObject *cls = PyTuple_GET_ITEM(mro, i);
-PyObject *dict = ((PyTypeObject *)cls)-tp_dict;
-
+PyObject *dict;
+if (PyClass_Check(cls))
+dict = ((PyClassObject *)cls)-cl_dict;
+else
+dict = ((PyTypeObject *)cls)-tp_dict;
 if (dict != NULL)
 {
 reimp = PyDict_GetItem(dict, mname_obj);
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Crash in sip_api_is_py_method() with PyQt 4.6

2009-10-13 Thread Victor Stinner
Hi,

A friend told me that there are snapshots. So I tested the last snapshot and 
the sip_api_is_py_method()'s crash is still present. But the other bug 
(methods redefined in Python) is different: I get an error on the number of 
arguments.

So here is a second patch against the snapshot. It fixes both issues: crash 
related to PyClassObject and the number of arguments for the redefined 
methods.

-- 
Victor Stinner
http://www.haypocalc.com/
--- siplib/siplib.c.orig	2009-10-13 21:54:05.0 +0200
+++ siplib/siplib.c	2009-10-13 22:10:45.0 +0200
@@ -6029,8 +6029,12 @@
  */
 
 if (sipSelf-dict != NULL)
+{
 /* Check the instance dictionary in case it has been monkey patched. */
 reimp = PyDict_GetItem(sipSelf-dict, mname_obj);
+if (reimp != NULL)
+return reimp;
+}
 else
 reimp = NULL;
 
@@ -6046,11 +6050,19 @@
 
 for (i = 0; i  PyTuple_GET_SIZE(mro); ++i)
 {
+PyObject *dict;
+
 cls = (PyTypeObject *)PyTuple_GET_ITEM(mro, i);
 
-if (cls-tp_dict != NULL)
+if (PyClass_Check(cls))
+dict = ((PyClassObject *)cls)-cl_dict;
+else
+dict = ((PyTypeObject *)cls)-tp_dict;
+
+
+if (dict != NULL)
 {
-PyObject *this_reimp = PyDict_GetItem(cls-tp_dict, mname_obj);
+PyObject *this_reimp = PyDict_GetItem(dict, mname_obj);
 
 /*
  * Check any reimplementation is Python code and is not the
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt