Bug 253123 - KConfigSkeleton segfaults with PyQt4 API version 2
Summary: KConfigSkeleton segfaults with PyQt4 API version 2
Alias: None
Product: bindings
Classification: Developer tools
Component: pykde (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: HI crash
Target Milestone: ---
Assignee: kde-bindings
Depends on:
Reported: 2010-10-03 15:00 UTC by Wolfgang Rohdewald
Modified: 2018-11-17 05:27 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:


Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Rohdewald 2010-10-03 15:00:33 UTC
Version:           unspecified (using KDE 4.5.1) 
OS:                Linux

In the PyQt4 API version 2, there is no class QString, strings are transparently translated between QString and Python strings. The following code always prints random output because some variable is freed somewhere while still being needed.

If PyKDE4 does not yet support API version 2, it should at least check against this when starting but not segfault. Also,
says nothing about API version compatibilities. I think it should.

Reproducible: Always

Steps to Reproduce:
import sip
sip.setapi('QString', 2)

from PyKDE4.kdeui import KConfigSkeleton

a = KConfigSkeleton()
name = 'tilesetName'
value = 'I am a value'
s = a.addItemString(name, value)
print s.value()

(gdb) run bug.py

Actual Results:  
value is: 㟀翿!麨翿刐Ï @翿偈

Program received signal SIGSEGV, Segmentation fault.
~QString (node=0xcf6cff) at /usr/include/qt4/QtCore/qstring.h:882
882     inline QString::~QString() { if (!d->ref.deref()) 
free(d); }
(gdb) bt
#0  ~QString (node=0xcf6cff) at 
#1  ~QHashNode (node=0xcf6cff) at 
#2  QHash<QString, KConfigSkeletonItem*>::deleteNode2 
    at /usr/include/qt4/QtCore/qhash.h:519
#3  0x00007ffff428cc6d in QHashData::free_helper (this=0xcf5160, 
    0x7ffff47520d0 <QHash<QString, 
    at tools/qhash.cpp:271
#4  0x00007ffff474ee70 in QHash<QString, 
KConfigSkeletonItem*>::freeData (this=0xcad330, 
    __in_chrg=<value optimized out>) at 
#5  ~QHash (this=0xcad330, __in_chrg=<value optimized out>)
    at /usr/include/qt4/QtCore/qhash.h:284
#6  ~Private (this=0xcad330, __in_chrg=<value optimized out>)
    at ../../kdecore/config/kcoreconfigskeleton_p.h:40
#7  ~KCoreConfigSkeleton (this=0xcad330, __in_chrg=<value 
optimized out>)
    at ../../kdecore/config/kcoreconfigskeleton.cpp:1005
#8  0x00007ffff5e6fecc in 
sipKConfigSkeleton::~sipKConfigSkeleton() ()
   from /usr/lib/pymodules/python2.6/PyKDE4/kdeui.so
#9  0x00007ffff5e02cbc in ?? () from 
#10 0x00007ffff67a77f9 in ?? () from 
#11 0x000000000046d2d8 in subtype_dealloc (self=<KConfigSkeleton 
at remote 0x97cf30>)
    at ../Objects/typeobject.c:1019
#12 0x000000000044e577 in insertdict (mp=0x8c8270, key='a', 
hash=12416037344, value=None)
    at ../Objects/dictobject.c:459
#13 0x0000000000450a77 in PyDict_SetItem (op=
    {'a': None, 'sip': <module at remote 0x7ffff7f03b40>, 'name': 
'tilesetName', '__builtins__': <module at remote 0x7ffff7fa2868>, 
'KConfigSkeleton': <PyQt4.QtCore.pyqtWrapperType at remote 
0xc77e20>, 'value': 'I am a value', '__package__': None, 's': 
<ItemString at remote 0xc3c050>, '__name__': '__main__', 
'__doc__': None}, key='a', value=None)
    at ../Objects/dictobject.c:701
#14 0x000000000045297e in _PyModule_Clear (m=<value optimized 
    at ../Objects/moduleobject.c:138
#15 0x00000000004bb5fa in PyImport_Cleanup () at 
#16 0x00000000004c922f in Py_Finalize () at 
#17 0x000000000041a296 in Py_Main (argc=-135380864, argv=<value 
optimized out>)
    at ../Modules/main.c:596
#18 0x00007ffff69d9c4d in __libc_start_main (main=<value 
optimized out>, 
    argc=<value optimized out>, ubp_av=<value optimized out>, 
init=<value optimized out>, 
    fini=<value optimized out>, rtld_fini=<value optimized out>, 
    at libc-start.c:226
#19 0x00000000004199f9 in _start ()

Expected Results:  
value is: 'I am a value'

ii  python-qt4                                         
4.7.3-1ubuntu2~lucid1~ppa3                      Python bindings 
for Qt4

ii  python-kde4                                        
4:4.5.1-0ubuntu1~lucid1~ppa1                    Python bindings 
for the KDE 4 libraries
Comment 1 Wolfgang Rohdewald 2012-06-06 12:32:22 UTC
this bug still exists with python-kde4 4.8.3
Comment 2 Luca Beltrame 2013-01-03 14:12:23 UTC
I wasn't aware of this issue (I use API version 1 with a KConfigSkeleton subclass). I followed up on the PyQt mailing list. If a theoretical solution is envisioned (my C++ and SIP knowledge are too limited to do that by myself) I can try implementing it in PyKDE4 (assuming the bug is there and not elsewhere).
Comment 3 Wolfgang Rohdewald 2013-09-10 23:11:15 UTC
this bug still exists with python-kde 4.11.1

both with python 2.7.4 and 3.3.1
Comment 4 Wolfgang Rohdewald 2014-10-06 21:34:00 UTC
This bug still exists with python3-PyKDE4 from KDE 4.14.1.

It makes central parts of PyKDE4 unusable. For kajongg this means it cannot use PyKDE4 until this is fixed. Until then, when running under Python3, it behaves like a simple Qt application (I wrote some simple replacements). I will sooner or later stop supporting Python2, so kajongg will stop behaving like a KDE application unless PyKF5 will be implemented without this bug.

Status: confirmed again and again by myself.

For python3 the test script is shorter:

from PyKDE4.kdeui import KConfigSkeleton
a = KConfigSkeleton()
name = 'tilesetName'
value = 'I am a value'
s = a.addItemString(name, value)
Comment 5 Luca Beltrame 2014-10-08 05:39:59 UTC
The main problem is that:

a. I don't really know where to look;
b. I need to check how much Python code is inside the KConfigSkeleton SIP implementation

I'll try to take a look soon, time permitting. I added Simon to the CC, hopefully he can give some pointers.
Comment 6 Rex Dieter 2016-10-18 12:16:59 UTC
Fwiw, I cannot reproduce the issue (on fedora 24) with the test-case code posted here,
Comment 7 Rex Dieter 2016-10-18 12:18:15 UTC
The test in the original comment does crash though (using python2)
Comment 8 Wolfgang Rohdewald 2016-10-18 12:36:06 UTC
What versions does Fedora 24 use? python, sip, qt4, pyqt4, pykde
Comment 9 Rex Dieter 2016-10-18 13:17:31 UTC
$ rpm -q sip PyQt4 pykde4 qt python python3
Comment 10 Wolfgang Rohdewald 2016-10-18 14:33:10 UTC
On Kubuntu 16.10, the python3 script still exhibits this bug. python-kde 4.14.12 and 4.14.13 are identical.

python-sip 4.18.1+dfsg-1
python-qt4 4.11.4+dfsg-2
python-kde4 4.14.2-0ubuntu6
libqtg4 4.8.7+dfsg-7ubuntu1
python 2.7.12-3build1
python 3.5.2-6
Comment 11 Rex Dieter 2016-10-18 14:58:57 UTC
One thing I make sure to do in fedora, is that all sip-related bindings packages were rebuilt against sip-4.18 

Hrm, I did test with sip-4.18, not 4.18.1 as you did, I wonder if that makes a difference
Comment 12 Andrew Crouthamel 2018-11-17 05:27:00 UTC
Hello, unfortunately this bug is being closed as unmaintained, per request of einar77.