Ticket #59358: python2_qstring.diff

File python2_qstring.diff, 1006 bytes (added by jwhowarth, 5 years ago)

python2_qstring.diff patch to eliminate crashes seen under pymol with py27-pyqt5 and python27.

  • qpy/QtCore/qpycore_qstring.cpp

    From: Dmitry Shachnev <mitya57@debian.org>
    Date: Mon, 2 Sep 2019 15:51:37 +0300
    Subject: Fixes for building against Python v2
    
    Origin: upstream, changesets e5dd514fdba6 and 81b34c9373b6.
    ---
     qpy/QtCore/qpycore_qstring.cpp | 14 +++++++++++++-
     1 file changed, 13 insertions(+), 1 deletion(-)
    
    diff --git qpy/QtCore/qpycore_qstring.cpp qpy/QtCore/qpycore_qstring.cpp
    index 2d04e3a..4a188ce 100644
    PyObject *qpycore_PyObject_FromQString(const QString &qstr) 
    158158}
    159159
    160160
    161 // Convert a Python Unicode object to a QString.
     161// Convert a Python string object to a QString.
    162162QString qpycore_PyObject_AsQString(PyObject *obj)
    163163{
     164#if PY_MAJOR_VERSION < 3
     165    if (PyString_Check(obj))
     166    {
     167        const char *obj_s = PyString_AsString(obj);
     168
     169        if (!obj_s)
     170            return QString();
     171
     172        return QString::fromUtf8(obj_s);
     173    }
     174#endif
     175
    164176#if defined(PYQT_PEP_393)
    165177    int char_size;
    166178    Py_ssize_t len;