[PySide] Is there a reason PySideSignalInstance source isn't incref'd?

Hugo Parente Lima hugo.lima at openbossa.org
Thu May 31 15:44:20 CEST 2012


On Wednesday, May 30, 2012 03:22:24 PM John Ehresman wrote:
> I'm getting a segfault when I run the following:
> 
> w.selectionModel().selectionChanged.connect(callback)
> 
> with updated sources from git.  I can work around it with
> 
> m = w.selectionModel()
> m.selectionChanged.connect(callback)
> 
> Stepping through the code in pysidesignal.cpp, it looks like d->source
> of a PySideSignalInstance object isn't incref'd so when the temporary
> ref returned by selectionModel is decref'd, the source is pointing at a
> invalid object.  The function that initializes a PySideSignalInstance is
> instanceInitialize

When we delete an QObject we want to have all their connections disconnected, 
e.g.

o = QObject()
o.connect(...)
del o
# The object must be destroyed and all connections disconnected.

But if the connection holds a reference to the sender this will never happen, 
IIRC we currently hold a weakref.

With w.selectionModel() the thing is different, because the object returned is 
owned by C++, so when you delete m or m goes out of scope the QSelectionModel 
shouldn't be deleted despite of not existing a single Python object pointing 
to it.

> Oddly this only happens in a larger program and not in a simple test
> case, but I don't see how source can be assumed to be valid without
> increfing it.

This need further investigation, file a bug, after all, it's a bug and the 
program shouldn't crash there.
 
> Thanks,
> 
> John
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
-------------- 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/20120531/22519591/attachment.sig>


More information about the PySide mailing list