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 829 - Segfault in Shiboken::Converter<QVariant>::toCpp(_object*) when converting dict with non-string keys to QVariant
: Segfault in Shiboken::Converter<QVariant>::toCpp(_object*) when converting di...
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: Shiboken
: HEAD
: PC Linux
: P2 normal
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2011-04-16 14:57 EEST by Thomas Perl
Modified: 2011-05-26 17:04 EEST (History)
8 users (show)

See Also:


Attachments
Test case for this bug - set a dictionary as value in QSettings (239 bytes, text/x-python)
2011-04-16 15:02 EEST, Thomas Perl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Perl 2011-04-16 14:57:21 EEST
When trying to set the value {1: 'a'} in a QSettings object, PySide crashes. A
run through gdb reveals:

#0  0x00392939 in ?? () from /lib/libc.so.6
#1  0x00394f33 in malloc () from /lib/libc.so.6
#2  0x080809af in PyList_New ()
#3  0x0808fef3 in PyDict_Keys ()
#4  0x004d49d1 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#5  0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#6  0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#7  0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#8  0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#9  0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#10 0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#11 0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#12 0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#13 0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#14 0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#15 0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#16 0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#17 0x004d4bd4 in Shiboken::Converter<QVariant>::toCpp(_object*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so

I'll attach a test case.
Comment 1 Thomas Perl 2011-04-16 15:02:25 EEST
Created attachment 310 [details]
Test case for this bug - set a dictionary as value in QSettings

Uninformed guess on what could be the problem: QVariant only knows about
QMap<QString, QVariant> and QHash<QString, QVariant>. Converting the dictionary
key (which is an int) to str before calling setValue prevents the crash. I'm
not sure if it's okay for PySide to do this implicitly (convert all keys to
strings), but it would fix the problem.
Comment 2 renato filho 2011-04-28 17:08:56 EEST
fixed on pyside commit:
commit 955316b5cabafa2134a9c98269161be6df7ead54
Author: Renato Filho <renato.filho@openbossa.org>
Date:   Wed Apr 27 15:02:38 2011 -0300
Comment 3 renato filho 2011-04-29 18:06:21 EEST
PySide release 1.0.2
Comment 4 Thomas Perl 2011-04-30 19:52:28 EEST
(In reply to comment #3)
> PySide release 1.0.2

I can still reproduce the segfault when running using a locally-compiled PySide
using the following repository revisions:

apiextractor: 1daec54e0ded18c111ce1d72f247265d29a6fd80
generatorrunner: a160d96a2ca2475457211f23ace38b4f23842388
pyside: af37aaf259e9500a8aaf438c469cb094f5aeeb88
shiboken: 14ab3d24bd15f977b6775cb9700cc45193ebd33f

GDB backtrace below:

thp@thpmbp:/tmp$ gdb --args python bug829.py 
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
(gdb) r
Starting program: /usr/bin/python bug829.py
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x080fa527 in ?? ()
(gdb) bt
#0  0x080fa527 in ?? ()
#1  0x080f43ec in PyImport_Import ()
#2  0x080f4612 in PyImport_ImportModule ()
#3  0x006b1fc0 in PySide::operator<<(QDataStream&, PySide::PyObjectWrapper
const&) () from /home/thp/pkg/pyside-sandbox/lib/libpyside-python2.6.so.1.0
#4  0x006b25ee in void
qMetaTypeSaveHelper<PySide::PyObjectWrapper>(QDataStream&,
PySide::PyObjectWrapper const*) ()
   from /home/thp/pkg/pyside-sandbox/lib/libpyside-python2.6.so.1.0
#5  0x00a91f8a in QMetaType::save(QDataStream&, int, void const*) ()
   from /usr/lib/libQtCore.so.4
#6  0x00aaa55c in QVariant::save(QDataStream&) const ()
   from /usr/lib/libQtCore.so.4
#7  0x00aaa699 in operator<<(QDataStream&, QVariant const&) ()
   from /usr/lib/libQtCore.so.4
#8  0x00a49020 in ?? () from /usr/lib/libQtCore.so.4
#9  0x00a4a45b in ?? () from /usr/lib/libQtCore.so.4
#10 0x00a4d78e in ?? () from /usr/lib/libQtCore.so.4
#11 0x00a4d8d4 in ?? () from /usr/lib/libQtCore.so.4
#12 0x00a3f7c1 in ?? () from /usr/lib/libQtCore.so.4
#13 0x00a40116 in QSettings::~QSettings() () from /usr/lib/libQtCore.so.4
#14 0x0057b5ea in QSettingsWrapper::~QSettingsWrapper() ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
---Type <return> to continue, or q <return> to quit---
#15 0x0057d396 in void Shiboken::callCppDestructor<QSettings>(void*) ()
   from
/home/thp/pkg/pyside-sandbox/lib/python2.6/site-packages/PySide/QtCore.so
#16 0x00917bf8 in SbkDeallocWrapper ()
   from /home/thp/pkg/pyside-sandbox/lib/libshiboken-python2.6.so.1.0
#17 0x0808c4d9 in ?? ()
#18 0x0808e837 in PyDict_SetItem ()
#19 0x080904c3 in _PyModule_Clear ()
#20 0x080effa5 in PyImport_Cleanup ()
#21 0x080fd19c in Py_Finalize ()
#22 0x0805b086 in Py_Main ()
#23 0x0805a8ab in main ()
Comment 5 renato filho 2011-05-09 22:38:33 EEST
This is caused because the QSettings destructor is called after python
interpreter be destroyed.

Then I recommend to you call the "del" explicitly to make sure of the object
destructor, or call the "syc()" method manually (more safe, destryctor
functions does not work well GC, you never know when this will be called).


BTW the crash was fixed on pyside commit:

commit 450d1a98a59db29a43dc7bb4b21f33af3e2101e8
Author: Renato Filho <renato.filho@openbossa.org>
Date:   Mon May 9 15:58:25 2011 -0300
Comment 6 renato filho 2011-05-26 17:04:06 EEST
PySide release 1.0.3