[PyQt] Fwd: [Kde-bindings] problem with sip api 2 for QString

Hans-Peter Jansen hpj at urpla.net
Thu Jan 3 14:01:48 GMT 2013


Dear Phil,

wishing you a successful and pleasable 2013.

You might want to look into the attached issue. It looks like it is a sip issue, althrough  
I wouldn't exclude PyKDE wrapper issues here...

Cheers,
Pete


----------  Weitergeleitete Nachricht  ----------

Betreff: [Kde-bindings] problem with sip api 2 for QString
Datum: Freitag, 28. Dezember 2012, 15:03:17
Von: Wolfgang Rohdewald <wolfgang at rohdewald.de>
An: KDE bindings for other programming languages <kde-bindings at kde.org>

Hi,

could somebody please have a look at bug 253123?
https://bugs.kde.org/show_bug.cgi?id=253123

without this being fixed I will never be able to port the kde game kajongg to
the new API. I want to change to the new API before trying the port to python3.

re-tested again today:

the full test script is:

#!/usr/bin/env python3
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():', s.value())  # --------- this prints random garbage, accessing a freed object

doing something similar with addItemInt works.

it seems the code generated by sip frees the string value object when it should not (by calling
sipReleaseType)

I know nothing about sip, so I have no idea how to fix this. That bug was always there
since I reported it in oct 2010, now I get it with pykde4-4.9.4 with both python 2.7.3 and
python 3.2 - so it really is version independent.

valgrind says 
==6835== Invalid read of size 8
==6835==    at 0x99C74CB: QString::toUcs4() const (in /usr/lib/x86_64-linux-gnu/libQtCore.so.4.8.3)
==6835==    by 0xF1B698F: ??? (in /usr/lib/python3/dist-packages/PyQt4/QtCore.cpython-32mu.so)
==6835==    by 0x79CFB38: sip_api_convert_from_type (in /usr/lib/python3/dist-packages/sip.cpython-32mu.so)
==6835==    by 0x1061B01B: meth_KCoreConfigSkeleton_ItemString_value (sipkdecorepart6.cpp:12455)
==6835==  Address 0x112f4800 is 0 bytes inside a block of size 8 free'd
==6835==    at 0x4C2A44B: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6835==    by 0xF0FB872: ??? (in /usr/lib/python3/dist-packages/PyQt4/QtCore.cpython-32mu.so)
==6835==    by 0x106361F4: meth_KCoreConfigSkeleton_addItemString (sipkdecorepart6.cpp:13726)

extracts from sipkdecorepart6.cpp (generated on kubuntu with apt-get --compile source python-kde4):

extern "C" {static PyObject *meth_KCoreConfigSkeleton_ItemString_value(PyObject *, PyObject *);}
static PyObject *meth_KCoreConfigSkeleton_ItemString_value(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        KCoreConfigSkeleton::ItemString *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_KCoreConfigSkeleton_ItemString, &sipCpp))
        {
            QString *sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = &sipCpp->value();   ----------------------- this is line 12455
            Py_END_ALLOW_THREADS

            return sipConvertFromType(sipRes,sipType_QString,NULL);
        }
    }

extern "C" {static PyObject *meth_KCoreConfigSkeleton_addItemString(PyObject *, PyObject *);}
static PyObject *meth_KCoreConfigSkeleton_addItemString(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        const QString * a0;
        int a0State = 0;
        QString * a1;
        int a1State = 0;
        const QString& a2def = QLatin1String("");
        const QString * a2 = &a2def;
        int a2State = 0;
        const QString& a3def = QString();
        const QString * a3 = &a3def;
        int a3State = 0;
        KCoreConfigSkeleton *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BJ1J1|J1J1", &sipSelf, sipType_KCoreConfigSkeleton, &sipCpp, sipType_QString,&a0, &a0State, sipType_QString,&a1, &a1State, sipType_QString,&a2, &a2State, sipType_QString,&a3, &a3State))
        {
            KCoreConfigSkeleton::ItemString *sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->addItemString(*a0,*a1,*a2,*a3);
            Py_END_ALLOW_THREADS
            sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State);
            sipReleaseType(a1,sipType_QString,a1State);  ----------------------------------- this is line 13726
            sipReleaseType(const_cast<QString *>(a2),sipType_QString,a2State);
            sipReleaseType(const_cast<QString *>(a3),sipType_QString,a3State);

            return sipConvertFromType(sipRes,sipType_KCoreConfigSkeleton_ItemString,NULL);
        }


-- 
Wolfgang
_______________________________________________
Kde-bindings mailing list
Kde-bindings at kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings
-------------------------------------------------------------


More information about the PyQt mailing list