[PyQt] Crash in siplib.c:findSlot, with test case and fix

Matt Newell newellm at blur.com
Thu Apr 23 23:21:51 BST 2009


On Thursday 23 April 2009 10:32:59 Matt Newell wrote:
> It seems if a wrapped class A has slots and a wrapped subclass B does not
> then an assert is triggered when calling a slot from A on an instance of B.
>
> To build and run the test --
>
> ./build.sh
> python test.py
>
>
> findSlot function that fixes all problems for me
>
> static void *findSlot(PyObject *self, sipPySlotType st)
> {
>     sipPySlotDef *psd;
>     PyTypeObject *py_type = Py_TYPE(self);
>
> 	if( PySequence_Check( py_type->tp_bases ) ) {
> 		int i = 0, end = PySequence_Size( py_type->tp_mro );
> 		for( ; i < end; i++ ) {
> 			PyObject * type_o = PySequence_GetItem( py_type->tp_mro, i );
> 			if( PyType_Check(type_o) ) {
> 				PyTypeObject * py_type_to_check = (PyTypeObject*)type_o;
>
> 				/* If it is not a wrapper then it must be an enum. */
> 				if (PyObject_TypeCheck((PyObject *)py_type_to_check,
> &sipWrapperType_Type))
> 					psd = ((sipClassTypeDef *)((sipWrapperType *)
> (py_type_to_check))->type)->ctd_pyslots;
> 				else
> 				{
> 					assert(PyObject_TypeCheck((PyObject *)py_type_to_check,
> &sipEnumType_Type));
>
> 					psd = ((sipEnumTypeDef *)((sipEnumTypeObject *)
> (py_type_to_check))->type)->etd_pyslots;
> 				}
> 				while (psd && psd->psd_func != NULL)
> 				{
> 					if (psd->psd_type == st)
> 						return psd->psd_func;
>
> 					++psd;
> 				}
> 			} else
> 				printf( "mro member not a type object\n" );
> 		}
> 	}
>
>     assert(NULL);
>
>     /* This should never happen. */
>     return NULL;
> }



My "fix" fixes the test case but causes a crash with
QTreeWidgeItem() == None

so it's obviously not a solution.

Calling QTreeWidgetItem() == None without my change it ends up returning NULL 
from findSlot which the comment indicates should never happen.

Matt







More information about the PyQt mailing list