[PySide] Bug with new hash table feature
Hugo Parente Lima
hugo.lima at openbossa.org
Wed May 30 20:12:39 CEST 2012
On Wednesday, May 30, 2012 09:37:15 AM Nathan Smith wrote:
> 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?
You raise an exception using the Python C API.
Use the PyErr_* functions, e.g. PyErr_SetString
> Nathan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20120530/9e2028ee/attachment.sig>
More information about the PySide
mailing list