aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/pysideqenum.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/libpyside/pysideqenum.cpp')
-rw-r--r--sources/pyside6/libpyside/pysideqenum.cpp87
1 files changed, 13 insertions, 74 deletions
diff --git a/sources/pyside6/libpyside/pysideqenum.cpp b/sources/pyside6/libpyside/pysideqenum.cpp
index 07a548cb6..c0479160f 100644
--- a/sources/pyside6/libpyside/pysideqenum.cpp
+++ b/sources/pyside6/libpyside/pysideqenum.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
#include <shiboken.h>
@@ -53,7 +17,7 @@ extern "C" {
using namespace Shiboken;
-static PyObject *analyzePyEnum(PyObject *pyenum, PyObject *container = nullptr)
+static PyObject *analyzePyEnum(PyObject *pyenum)
{
/*
* This is the straight-forward implementation of QEnum/QFlag. It does no
@@ -99,7 +63,7 @@ static PyObject *analyzePyEnum(PyObject *pyenum, PyObject *container = nullptr)
AutoDecRef value(PyObject_GetAttr(member, Shiboken::PyName::value()));
if (value.isNull())
return nullptr;
- if (!PyInt_Check(value)) { // int/long cheating
+ if (!PyLong_Check(value)) {
PyErr_Format(PyExc_TypeError,
"QEnum expected an int value as '%.200s', got '%.200s'",
Shiboken::String::toCString(key), Py_TYPE(value)->tp_name);
@@ -113,9 +77,9 @@ static Py_ssize_t get_lineno()
{
PyObject *frame = reinterpret_cast<PyObject *>(PyEval_GetFrame()); // borrowed ref
AutoDecRef ob_lineno(PyObject_GetAttr(frame, Shiboken::PyName::f_lineno()));
- if (ob_lineno.isNull() || !PyInt_Check(ob_lineno)) // int/long cheating
+ if (ob_lineno.isNull() || !PyLong_Check(ob_lineno))
return -1;
- return PyInt_AsSsize_t(ob_lineno); // int/long cheating
+ return PyLong_AsSsize_t(ob_lineno);
}
static bool is_module_code()
@@ -133,7 +97,7 @@ static bool is_module_code()
} // extern "C"
-namespace PySide { namespace QEnum {
+namespace PySide::QEnum {
static std::map<int, PyObject *> enumCollector;
@@ -147,38 +111,14 @@ int isFlag(PyObject *obType)
* The function is called in MetaObjectBuilderPrivate::parsePythonType
* again to obtain the flag value.
*/
- if (!PyType_Check(obType)) {
- PyErr_Format(PyExc_TypeError, "a class argument was expected, not a '%.200s' instance",
- Py_TYPE(obType)->tp_name);
- return -1;
- };
- auto *type = reinterpret_cast<PyTypeObject *>(obType);
- PyObject *mro = type->tp_mro;
- Py_ssize_t i, n = PyTuple_GET_SIZE(mro);
- bool right_module = false;
- bool have_enum = false;
- bool have_flag = false;
- bool have_members = PyObject_HasAttr(obType, PyMagicName::members());
- for (i = 0; i < n; i++) {
- obType = PyTuple_GET_ITEM(mro, i);
- type = reinterpret_cast<PyTypeObject *>(obType);
- AutoDecRef mod(PyObject_GetAttr(obType, PyMagicName::module()));
- QByteArray cmod = String::toCString(mod);
- QByteArray cname = type->tp_name;
- if (cmod == "enum") {
- right_module = true;
- if (cname == "Enum")
- have_enum = true;
- else if (cname == "Flag")
- have_flag = true;
- }
- }
- if (!right_module || !(have_enum || have_flag) || !have_members) {
+ int res = enumIsFlag(obType);
+ if (res < 0) {
+ auto *type = reinterpret_cast<PyTypeObject *>(obType);
PyErr_Format(PyExc_TypeError, "type %.200s does not inherit from 'Enum' or 'Flag'",
type->tp_name);
return -1;
}
- return bool(have_flag);
+ return bool(res);
}
PyObject *QEnumMacro(PyObject *pyenum, bool flag)
@@ -223,7 +163,7 @@ std::vector<PyObject *> resolveDelayedQEnums(PyTypeObject *containerType)
{
/*
* This is the internal interface of 'QEnum'.
- * It is called at the end of the meta class call 'SbkObjectTypeTpNew' via
+ * It is called at the end of the meta class call 'SbkObjectType_tp_new' via
* MetaObjectBuilderPrivate::parsePythonType and resolves the collected
* Python Enum arguments. The result is then registered.
*/
@@ -251,8 +191,7 @@ std::vector<PyObject *> resolveDelayedQEnums(PyTypeObject *containerType)
return result;
}
-} // namespace Enum
-} // namespace Shiboken
+} // namespace Shiboken::Enum
//
///////////////////////////////////////////////////////////////