aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/libshiboken/signature/signature_extend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/libshiboken/signature/signature_extend.cpp')
-rw-r--r--sources/shiboken6/libshiboken/signature/signature_extend.cpp140
1 files changed, 33 insertions, 107 deletions
diff --git a/sources/shiboken6/libshiboken/signature/signature_extend.cpp b/sources/shiboken6/libshiboken/signature/signature_extend.cpp
index 528c7c87a..7292f8216 100644
--- a/sources/shiboken6/libshiboken/signature/signature_extend.cpp
+++ b/sources/shiboken6/libshiboken/signature/signature_extend.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 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$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
////////////////////////////////////////////////////////////////////////////
//
@@ -48,12 +12,14 @@
// PyMethodDescr_Type
// PyCFunction_Type
// PyStaticMethod_Type
-// PyType_Type
+// (*) PyType_Type
// PyWrapperDescr_Type
//
-// Their `tp_getset` fields are modified so support the `__signature__`
+// Their `tp_getset` fields are modified to support the `__signature__`
// attribute and additions to the `__doc__` attribute.
//
+// PYSIDE-535: PyType_Type patching is removed,
+// Shiboken.ObjectType and Shiboken.EnumMeta have new getsets, instead.
#include "autodecref.h"
#include "sbkstring.h"
@@ -89,27 +55,29 @@ static PyObject *_get_written_signature(signaturefunc sf, PyObject *ob, PyObject
return ret;
}
+#ifdef PYPY_VERSION
+PyObject *pyside_bm_get___signature__(PyObject *func, PyObject *modifier)
+{
+ return _get_written_signature(GetSignature_Method, func, modifier);
+}
+#endif
+
PyObject *pyside_cf_get___signature__(PyObject *func, PyObject *modifier)
{
- init_module_2();
return _get_written_signature(GetSignature_Function, func, modifier);
}
PyObject *pyside_sm_get___signature__(PyObject *sm, PyObject *modifier)
{
- init_module_2();
AutoDecRef func(PyObject_GetAttr(sm, PyMagicName::func()));
- if (Py_TYPE(func) == PepFunction_TypePtr)
- return PyObject_GetAttr(func, PyMagicName::signature());
return _get_written_signature(GetSignature_Function, func, modifier);
}
PyObject *pyside_md_get___signature__(PyObject *ob_md, PyObject *modifier)
{
- init_module_2();
AutoDecRef func(name_key_to_func(ob_md));
if (func.object() == Py_None)
- return Py_None;
+ Py_RETURN_NONE;
if (func.isNull())
Py_FatalError("missing mapping in MethodDescriptor");
return pyside_cf_get___signature__(func, modifier);
@@ -117,13 +85,11 @@ PyObject *pyside_md_get___signature__(PyObject *ob_md, PyObject *modifier)
PyObject *pyside_wd_get___signature__(PyObject *ob, PyObject *modifier)
{
- init_module_2();
return _get_written_signature(GetSignature_Wrapper, ob, modifier);
}
PyObject *pyside_tp_get___signature__(PyObject *obtype_mod, PyObject *modifier)
{
- init_module_2();
return _get_written_signature(GetSignature_TypeMod, obtype_mod, modifier);
}
@@ -153,29 +119,29 @@ static int handle_doc_in_progress = 0;
static PyObject *handle_doc(PyObject *ob, PyObject *old_descr)
{
- init_module_1();
- init_module_2();
AutoDecRef ob_type_mod(GetClassOrModOf(ob));
const char *name;
- if (PyModule_Check(ob_type_mod))
- name = PyModule_GetName(ob_type_mod);
+ bool isModule = PyModule_Check(ob_type_mod.object());
+ if (isModule)
+ name = PyModule_GetName(ob_type_mod.object());
else
name = reinterpret_cast<PyTypeObject *>(ob_type_mod.object())->tp_name;
+ PyObject *res{};
+
if (handle_doc_in_progress || name == nullptr
- || strncmp(name, "PySide6.", 8) != 0)
- return PyObject_CallMethodObjArgs(old_descr,
- PyMagicName::get(),
- ob, nullptr);
- handle_doc_in_progress++;
- PyObject *res = PyObject_CallFunction(
- pyside_globals->make_helptext_func,
- "(O)", ob);
- handle_doc_in_progress--;
- if (res == nullptr) {
- PyErr_Print();
- Py_FatalError("handle_doc did not receive a result");
+ || (isModule && strncmp(name, "PySide6.", 8) != 0)) {
+ res = PyObject_CallMethodObjArgs(old_descr, PyMagicName::get(), ob, nullptr);
+ } else {
+ handle_doc_in_progress++;
+ res = PyObject_CallFunction(pyside_globals->make_helptext_func, "(O)", ob);
+ handle_doc_in_progress--;
}
- return res;
+
+ if (res)
+ return res;
+
+ PyErr_Clear();
+ Py_RETURN_NONE;
}
static PyObject *pyside_cf_get___doc__(PyObject *cf)
@@ -203,66 +169,29 @@ static PyObject *pyside_wd_get___doc__(PyObject *wd)
return handle_doc(wd, old_wd_doc_descr);
}
-// the default setter for all objects
-static int pyside_set___signature__(PyObject *op, PyObject *value)
-{
- // By this additional check, this function refuses write access.
- // We consider both nullptr and Py_None as not been written.
- AutoDecRef has_val(get_signature_intern(op, nullptr));
- if (!(has_val.isNull() || has_val == Py_None)) {
- PyErr_Format(PyExc_AttributeError,
- "Attribute '__signature__' of '%.50s' object is not writable",
- Py_TYPE(op)->tp_name);
- return -1;
- }
- int ret = value == nullptr ? PyDict_DelItem(pyside_globals->value_dict, op)
- : PyDict_SetItem(pyside_globals->value_dict, op, value);
- Py_XINCREF(value);
- return ret;
-}
-
+// PYSIDE-535: We cannot patch types easily in PyPy.
+// Let's use the `get_signature` function, instead.
static PyGetSetDef new_PyCFunction_getsets[] = {
{const_cast<char *>("__doc__"), reinterpret_cast<getter>(pyside_cf_get___doc__),
nullptr, nullptr, nullptr},
- {const_cast<char *>("__signature__"), reinterpret_cast<getter>(pyside_cf_get___signature__),
- reinterpret_cast<setter>(pyside_set___signature__),
- nullptr, nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr}
};
static PyGetSetDef new_PyStaticMethod_getsets[] = {
{const_cast<char *>("__doc__"), reinterpret_cast<getter>(pyside_sm_get___doc__),
nullptr, nullptr, nullptr},
- {const_cast<char *>("__signature__"), reinterpret_cast<getter>(pyside_sm_get___signature__),
- reinterpret_cast<setter>(pyside_set___signature__),
- nullptr, nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr}
};
static PyGetSetDef new_PyMethodDescr_getsets[] = {
{const_cast<char *>("__doc__"), reinterpret_cast<getter>(pyside_md_get___doc__),
nullptr, nullptr, nullptr},
- {const_cast<char *>("__signature__"), reinterpret_cast<getter>(pyside_md_get___signature__),
- reinterpret_cast<setter>(pyside_set___signature__),
- nullptr, nullptr},
- {nullptr, nullptr, nullptr, nullptr, nullptr}
-};
-
-static PyGetSetDef new_PyType_getsets[] = {
- {const_cast<char *>("__doc__"), reinterpret_cast<getter>(pyside_tp_get___doc__),
- nullptr, nullptr, nullptr},
- {const_cast<char *>("__signature__"), reinterpret_cast<getter>(pyside_tp_get___signature__),
- reinterpret_cast<setter>(pyside_set___signature__),
- nullptr, nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr}
};
static PyGetSetDef new_PyWrapperDescr_getsets[] = {
{const_cast<char *>("__doc__"), reinterpret_cast<getter>(pyside_wd_get___doc__),
nullptr, nullptr, nullptr},
- {const_cast<char *>("__signature__"), reinterpret_cast<getter>(pyside_wd_get___signature__),
- reinterpret_cast<setter>(pyside_set___signature__),
- nullptr, nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr}
};
@@ -282,8 +211,6 @@ int PySide_PatchTypes(void)
auto cf_doc = &old_cf_doc_descr;
auto sm_gs = new_PyStaticMethod_getsets;
auto sm_doc = &old_sm_doc_descr;
- auto tp_gs = new_PyType_getsets;
- auto tp_doc = &old_tp_doc_descr;
auto wd_gs = new_PyWrapperDescr_getsets;
auto wd_doc = &old_wd_doc_descr;
@@ -292,7 +219,6 @@ int PySide_PatchTypes(void)
|| add_more_getsets(PepMethodDescr_TypePtr, md_gs, md_doc) < 0
|| add_more_getsets(&PyCFunction_Type, cf_gs, cf_doc) < 0
|| add_more_getsets(PepStaticMethod_TypePtr, sm_gs, sm_doc) < 0
- || add_more_getsets(&PyType_Type, tp_gs, tp_doc) < 0
|| add_more_getsets(Py_TYPE(wrap_descr), wd_gs, wd_doc) < 0
)
return -1;