PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 984 - Segfault when deepcopy'ing some QtGui objects
: Segfault when deepcopy'ing some QtGui objects
Status: CLOSED ALREADYFIXED
Product: PySide
Classification: Unclassified
Component: QtGui
: 1.0.6
: PC Linux
: P3 normal
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-08-22 06:49 EEST by bbreslauer
Modified: 2011-09-21 21:19 EEST (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bbreslauer 2011-08-22 06:49:45 EEST
When I try to deepcopy a QFont or QPen, I receive a segfault. This does not
happen with a QPolygon, which copies just fine. I have not done a thorough test
of QT classes to see which ones segfault and which ones don't; I'm presuming
this is either something that is broken in one place, or it is easy to
determine by grep'ing the source. I am running Arch Linux, kernel 3.0.3 with
PySide 1.0.5 and Python 2.7.2.

Some code to reproduce this:

>>> from PySide.QtGui import QPen
>>> import copy
>>> copy.deepcopy(QPen())
Segmentation fault

>>> from PySide.QtGui import QFont
>>> import copy
>>> copy.deepcopy(QFont())
Segmentation fault

>>> from PySide.QtGui import QPolygon
>>> import copy
>>> copy.deepcopy(QPolygon())
<PySide.QtGui.QPolygon()  at 0x1d759e0>

I think that these segfaults stem from a TypeError raised by __reduce__ with
QFont and QPen, but not QPolygon. Specifically,

>>> from PySide.QtGui import QFont
>>> f = QFont()
>>> f.__reduce__()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle QFont objects

>>> from PySide.QtGui import QPen
>>> a = QPen()
>>> a.__reduce__()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle QPen objects

>>> from PySide.QtGui import QPolygon
>>> a = QPolygon()
>>> a.__reduce__()
(<type 'PySide.QtGui.QPolygon'>, ([],))
Comment 1 Hugo Parente Lima 2011-08-23 20:18:04 EEST
Here an exception is thrown: "Internal C++ object (PySide.QtGui.QPen) already
deleted."
Comment 2 Hugo Parente Lima 2011-08-31 00:01:47 EEST
With Python 1.0.6 it doesn't segfault, but returns a invalid object.

QPen and QBrush doesn't support pickling.

What it's expected to return if the object doesn't support pickling? The docs
of copy module says nothing about this situation.

Note: PyQt4 under py3k suffers the same problem
Comment 3 Hugo Parente Lima 2011-09-01 21:55:43 EEST
It doesn't segfault anymore.

The invalid object returned by copy.deepcopy function is caused because
deepcopy function doesn't support unpickleable objects like QPen and QFont.
Comment 4 bbreslauer 2011-09-02 00:48:46 EEST
Hmm, ok.  I am also getting just a RuntimeError instead of a segfault now, with
1.0.6.  Out of curiosity, why aren't QPen and others pickle-able?  Is there an
inherent reason why they shouldn't be?
Comment 5 Hugo Parente Lima 2011-09-02 00:57:12 EEST
(In reply to comment #4)
> Hmm, ok.  I am also getting just a RuntimeError instead of a segfault now, with
> 1.0.6.  Out of curiosity, why aren't QPen and others pickle-able?  Is there an
> inherent reason why they shouldn't be?

Just because QPen has a lot of attributes that can't be set in just one method
call.

Why do you need to pickle QPen?
Comment 6 bbreslauer 2011-09-02 01:15:18 EEST
I see. I had a method that was using deepcopy, not specifically pickling them
(deepcopy because I needed to create new dictionaries, which a simple copy
won't do).  I was using this method for all sorts of objects, and it was acting
on some Qt objects as well.  But for the classes that aren't pickle-able, I can
probably just copy them, so maybe this won't be an issue after all.

Thanks for all your work on my bug reports!
Comment 7 renato filho 2011-09-21 21:19:46 EEST
Release 1.0.7