[PySide] Bug with new hash table feature

Nathan Smith nathanjsmith at gmail.com
Wed May 30 16:37:15 CEST 2012


Hi all,

I uncovered a bug in the new hash feature of Shiboken in the repositories.
 I'll submit a bug report when the system comes back up, but I'm interested
in actually submitting a patch.

The new hash function doesn't check to see if the provided object is valid
before calculating the hash value.  This can be seen
in shiboken/libshiboken/basewrapper.cpp at line 754 and demonstrated using
the following code:

>>> from PySide import QtCore
>>> import shiboken
>>> a = QtCore.QObject()
>>> b = QtCore.QObject(a)
>>> shiboken.isValid(a)
True
>>> shiboken.isValid(b)
True
>>> del a
>>> shiboken.isValid(b)
False
>>> hash(b)
Segmentation Fault


I made the following change in the code, but it didn't do what I expected:

if (!isValid(pyObj)) {
  return 0L;
}


isValid raises a RuntimeException in addition to returning false, but I
never see that exception in Python.  So, I have two questions:

   1. Is there some other code that should be checking isValid before the
   call ever gets to the C++ hash() function?
   2. How do you correctly raise an exception from within Shiboken?

Nathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120530/8fdcc883/attachment.html>


More information about the PySide mailing list