From 4def28e7f9da33aa047f8d201ce2298364f6db42 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 20 Sep 2019 11:13:31 +0200 Subject: libpyside: Use new static strings Initial-patch-by: Christian Tismer Task-number: PYSIDE-1087 Change-Id: I5b4f0e70bc9b79dd4a4a545e97722ceba778ee53 Reviewed-by: Christian Tismer --- sources/pyside2/libpyside/CMakeLists.txt | 2 + sources/pyside2/libpyside/pyside.cpp | 7 ++- sources/pyside2/libpyside/pysidesignal.cpp | 13 +++-- sources/pyside2/libpyside/pysidestaticstrings.cpp | 59 +++++++++++++++++++++++ sources/pyside2/libpyside/pysidestaticstrings.h | 56 +++++++++++++++++++++ sources/pyside2/libpyside/signalmanager.cpp | 5 +- 6 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 sources/pyside2/libpyside/pysidestaticstrings.cpp create mode 100644 sources/pyside2/libpyside/pysidestaticstrings.h diff --git a/sources/pyside2/libpyside/CMakeLists.txt b/sources/pyside2/libpyside/CMakeLists.txt index 7b8adfc84..7493a453a 100644 --- a/sources/pyside2/libpyside/CMakeLists.txt +++ b/sources/pyside2/libpyside/CMakeLists.txt @@ -53,6 +53,7 @@ set(libpyside_SRC pysideqflags.cpp pysideweakref.cpp pyside.cpp + pysidestaticstrings.cpp ${DESTROYLISTENER_MOC} ) @@ -130,6 +131,7 @@ set(libpyside_HEADERS pysidemacros.h signalmanager.h pyside.h + pysidestaticstrings.h pysidemetafunction.h pysidesignal.h pysideproperty.h diff --git a/sources/pyside2/libpyside/pyside.cpp b/sources/pyside2/libpyside/pyside.cpp index ffa837a01..2419b2e16 100644 --- a/sources/pyside2/libpyside/pyside.cpp +++ b/sources/pyside2/libpyside/pyside.cpp @@ -45,6 +45,7 @@ #include "pysideproperty.h" #include "pysidesignal.h" #include "pysidesignal_p.h" +#include "pysidestaticstrings.h" #include "pysideslot_p.h" #include "pysidemetafunction_p.h" #include "pysidemetafunction.h" @@ -57,6 +58,7 @@ #include #include #include +#include #include #include @@ -234,7 +236,8 @@ void initDynamicMetaObject(SbkObjectType *type, const QMetaObject *base, std::si if (!converter) return; Shiboken::AutoDecRef pyMetaObject(Shiboken::Conversions::pointerToPython(converter, metaObjectPtr)); - PyObject_SetAttrString(reinterpret_cast(type), "staticMetaObject", pyMetaObject); + PyObject_SetAttr(reinterpret_cast(type), + PySide::PyName::qtStaticMetaObject(), pyMetaObject); } TypeUserData *retrieveTypeUserData(SbkObjectType *sbkTypeObj) @@ -540,7 +543,7 @@ bool registerInternalQtConf() // Querying __file__ should be done only for modules that have finished their initialization. // Thus querying for the top-level PySide2 package works for us whenever any Qt-wrapped module // is loaded. - PyObject *pysideInitFilePath = PyObject_GetAttrString(pysideModule, "__file__"); + PyObject *pysideInitFilePath = PyObject_GetAttr(pysideModule, Shiboken::PyMagicName::file()); Py_DECREF(pysideModule); if (!pysideInitFilePath) return false; diff --git a/sources/pyside2/libpyside/pysidesignal.cpp b/sources/pyside2/libpyside/pysidesignal.cpp index a09c17a24..ed1dcb729 100644 --- a/sources/pyside2/libpyside/pysidesignal.cpp +++ b/sources/pyside2/libpyside/pysidesignal.cpp @@ -40,6 +40,7 @@ #include #include "pysidesignal.h" #include "pysidesignal_p.h" +#include "pysidestaticstrings.h" #include "signalmanager.h" #include @@ -412,7 +413,8 @@ PyObject *signalInstanceConnect(PyObject *self, PyObject *args, PyObject *kwds) if (match) { Shiboken::AutoDecRef tupleArgs(PyList_AsTuple(pyArgs)); - Shiboken::AutoDecRef pyMethod(PyObject_GetAttrString(source->d->source, "connect")); + Shiboken::AutoDecRef pyMethod(PyObject_GetAttr(source->d->source, + PySide::PyName::qtConnect())); if (pyMethod.isNull()) { // PYSIDE-79: check if pyMethod exists. PyErr_SetString(PyExc_RuntimeError, "method 'connect' vanished!"); return 0; @@ -465,7 +467,8 @@ PyObject *signalInstanceEmit(PyObject *self, PyObject *args) for (Py_ssize_t i = 0, max = PyTuple_Size(args); i < max; i++) PyList_Append(pyArgs, PyTuple_GetItem(args, i)); - Shiboken::AutoDecRef pyMethod(PyObject_GetAttrString(source->d->source, "emit")); + Shiboken::AutoDecRef pyMethod(PyObject_GetAttr(source->d->source, + PySide::PyName::qtEmit())); Shiboken::AutoDecRef tupleArgs(PyList_AsTuple(pyArgs)); return PyObject_CallObject(pyMethod, tupleArgs); @@ -530,7 +533,8 @@ PyObject *signalInstanceDisconnect(PyObject *self, PyObject *args) if (match) { Shiboken::AutoDecRef tupleArgs(PyList_AsTuple(pyArgs)); - Shiboken::AutoDecRef pyMethod(PyObject_GetAttrString(source->d->source, "disconnect")); + Shiboken::AutoDecRef pyMethod(PyObject_GetAttr(source->d->source, + PySide::PyName::qtDisconnect())); PyObject *result = PyObject_CallObject(pyMethod, tupleArgs); if (!result || result == Py_True) return result; @@ -756,7 +760,8 @@ void instanceInitialize(PySideSignalInstance *self, PyObject *name, PySideSignal bool connect(PyObject *source, const char *signal, PyObject *callback) { - Shiboken::AutoDecRef pyMethod(PyObject_GetAttrString(source, "connect")); + Shiboken::AutoDecRef pyMethod(PyObject_GetAttr(source, + PySide::PyName::qtConnect())); if (pyMethod.isNull()) return false; diff --git a/sources/pyside2/libpyside/pysidestaticstrings.cpp b/sources/pyside2/libpyside/pysidestaticstrings.cpp new file mode 100644 index 000000000..82e233621 --- /dev/null +++ b/sources/pyside2/libpyside/pysidestaticstrings.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "pysidestaticstrings.h" +#include + +#define STATIC_STRING_IMPL(funcName, value) \ +PyObject *funcName() \ +{ \ + static PyObject *const s = Shiboken::String::createStaticString(value); \ + return s; \ +} + +namespace PySide +{ +namespace PyName +{ +STATIC_STRING_IMPL(qtStaticMetaObject, "staticMetaObject") +STATIC_STRING_IMPL(qtConnect, "connect") +STATIC_STRING_IMPL(qtDisconnect, "disconnect") +STATIC_STRING_IMPL(qtEmit, "emit") +} // namespace PyName +} // namespace PySide diff --git a/sources/pyside2/libpyside/pysidestaticstrings.h b/sources/pyside2/libpyside/pysidestaticstrings.h new file mode 100644 index 000000000..1d5700c51 --- /dev/null +++ b/sources/pyside2/libpyside/pysidestaticstrings.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PYSIDESTRINGS_H +#define PYSIDESTRINGS_H + +#include + +namespace PySide +{ +namespace PyName +{ +PyObject *qtStaticMetaObject(); +PyObject *qtConnect(); +PyObject *qtDisconnect(); +PyObject *qtEmit(); +} // namespace PyName +} // namespace PySide + +#endif // PYSIDESTRINGS_H diff --git a/sources/pyside2/libpyside/signalmanager.cpp b/sources/pyside2/libpyside/signalmanager.cpp index c13b5280f..c21a3e565 100644 --- a/sources/pyside2/libpyside/signalmanager.cpp +++ b/sources/pyside2/libpyside/signalmanager.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -169,7 +170,7 @@ QDataStream &operator<<(QDataStream &out, const PyObjectWrapper &myObj) Shiboken::GilState gil; if (!reduce_func) { Shiboken::AutoDecRef pickleModule(PyImport_ImportModule("pickle")); - reduce_func = PyObject_GetAttrString(pickleModule, "dumps"); + reduce_func = PyObject_GetAttr(pickleModule, Shiboken::PyName::dumps()); } Shiboken::AutoDecRef repr(PyObject_CallFunctionObjArgs(reduce_func, (PyObject *)myObj, NULL)); if (repr.object()) { @@ -200,7 +201,7 @@ QDataStream &operator>>(QDataStream &in, PyObjectWrapper &myObj) Shiboken::GilState gil; if (!eval_func) { Shiboken::AutoDecRef pickleModule(PyImport_ImportModule("pickle")); - eval_func = PyObject_GetAttrString(pickleModule, "loads"); + eval_func = PyObject_GetAttr(pickleModule, Shiboken::PyName::loads()); } QByteArray repr; -- cgit v1.2.3