aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/libshiboken/pep384impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/libshiboken/pep384impl.h')
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.h195
1 files changed, 121 insertions, 74 deletions
diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h
index 6d297bc7d..31fd65219 100644
--- a/sources/shiboken6/libshiboken/pep384impl.h
+++ b/sources/shiboken6/libshiboken/pep384impl.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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) 2018 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
#ifndef PEP384IMPL_H
#define PEP384IMPL_H
@@ -86,42 +50,79 @@ typedef struct _typeobject {
const char *tp_name;
Py_ssize_t tp_basicsize;
void *X03; // Py_ssize_t tp_itemsize;
+#ifdef PEP384_INTERN
destructor tp_dealloc;
+#else
+ destructor X04;
+#endif
void *X05; // Py_ssize_t tp_vectorcall_offset;
void *X06; // getattrfunc tp_getattr;
void *X07; // setattrfunc tp_setattr;
void *X08; // PyAsyncMethods *tp_as_async;
+#ifdef PEP384_INTERN
reprfunc tp_repr;
+#else
+ reprfunc X09;
+#endif
void *X10; // PyNumberMethods *tp_as_number;
void *X11; // PySequenceMethods *tp_as_sequence;
void *X12; // PyMappingMethods *tp_as_mapping;
void *X13; // hashfunc tp_hash;
+#ifdef PEP384_INTERN
ternaryfunc tp_call;
- reprfunc tp_str;
+#else
+ ternaryfunc X14;
+#endif
+ reprfunc tp_str; // Only used for PEP384_INTERN and a shiboken test
getattrofunc tp_getattro;
setattrofunc tp_setattro;
void *X18; // PyBufferProcs *tp_as_buffer;
unsigned long tp_flags;
void *X20; // const char *tp_doc;
+#ifdef PEP384_INTERN
traverseproc tp_traverse;
inquiry tp_clear;
+#else
+ traverseproc X21;
+ inquiry X22;
+#endif
void *X23; // richcmpfunc tp_richcompare;
Py_ssize_t tp_weaklistoffset;
void *X25; // getiterfunc tp_iter;
+#ifdef PEP384_INTERN
iternextfunc tp_iternext;
+#else
+ iternextfunc X26;
+#endif
struct PyMethodDef *tp_methods;
struct PyMemberDef *tp_members;
struct PyGetSetDef *tp_getset;
struct _typeobject *tp_base;
+#ifdef PEP384_INTERN
PyObject *tp_dict;
descrgetfunc tp_descr_get;
descrsetfunc tp_descr_set;
+#else
+ void *X31;
+ descrgetfunc X32;
+ descrsetfunc X33;
+#endif
Py_ssize_t tp_dictoffset;
+#ifdef PEP384_INTERN
initproc tp_init;
allocfunc tp_alloc;
+#else
+ initproc X39;
+ allocfunc X40;
+#endif
newfunc tp_new;
+#ifdef PEP384_INTERN
freefunc tp_free;
inquiry tp_is_gc; /* For PyObject_IS_GC */
+#else
+ freefunc X41;
+ inquiry X42; /* For PyObject_IS_GC */
+#endif
PyObject *tp_bases;
PyObject *tp_mro; /* method resolution order */
@@ -134,14 +135,6 @@ typedef struct _typeobject {
&& (Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o)))
#endif
-// This was a macro error in the limited API from the beginning.
-// It was fixed in Python master, but did make it only in Python 3.8 .
-#define PY_ISSUE33738_SOLVED 0x03080000
-#if PY_VERSION_HEX < PY_ISSUE33738_SOLVED
-#undef PyIndex_Check
-LIBSHIBOKEN_API int PyIndex_Check(PyObject *obj);
-#endif
-
LIBSHIBOKEN_API PyObject *_PepType_Lookup(PyTypeObject *type, PyObject *name);
#else // Py_LIMITED_API
@@ -150,17 +143,21 @@ LIBSHIBOKEN_API PyObject *_PepType_Lookup(PyTypeObject *type, PyObject *name);
#endif // Py_LIMITED_API
+/// PYSIDE-939: We need the runtime version, given major << 16 + minor << 8 + micro
+LIBSHIBOKEN_API long _PepRuntimeVersion();
/*****************************************************************************
*
* PYSIDE-535: Implement a clean type extension for PyPy
*
*/
-struct SbkObjectType;
struct SbkObjectTypePrivate;
-LIBSHIBOKEN_API SbkObjectTypePrivate *PepType_SOTP(SbkObjectType *type);
-LIBSHIBOKEN_API void PepType_SOTP_delete(SbkObjectType *type);
+LIBSHIBOKEN_API SbkObjectTypePrivate *PepType_SOTP(PyTypeObject *type);
+LIBSHIBOKEN_API void PepType_SOTP_delete(PyTypeObject *type);
+
+// PYSIDE-2230: SbkObjectType needs a special init
+LIBSHIBOKEN_API void _PepPostInit_SbkObject_Type(PyTypeObject *type);
struct SbkEnumType;
struct SbkEnumTypePrivate;
@@ -169,26 +166,14 @@ LIBSHIBOKEN_API SbkEnumTypePrivate *PepType_SETP(SbkEnumType *type);
LIBSHIBOKEN_API void PepType_SETP_delete(SbkEnumType *enumType);
struct PySideQFlagsType;
-struct PySideQFlagsTypePrivate;
-
-LIBSHIBOKEN_API PySideQFlagsTypePrivate *PepType_PFTP(PySideQFlagsType *type);
-LIBSHIBOKEN_API void PepType_PFTP_delete(PySideQFlagsType *flagsType);
+struct SbkQFlagsTypePrivate;
/*****************************************************************************/
// functions used everywhere
LIBSHIBOKEN_API const char *PepType_GetNameStr(PyTypeObject *type);
-/*****************************************************************************
- *
- * RESOLVED: longobject.h
- *
- */
-#ifdef Py_LIMITED_API
-LIBSHIBOKEN_API int _PepLong_AsInt(PyObject *);
-#else
-#define _PepLong_AsInt _PyLong_AsInt
-#endif
+LIBSHIBOKEN_API PyObject *Pep_GetPartialFunction(void);
/*****************************************************************************
*
@@ -204,7 +189,6 @@ LIBSHIBOKEN_API int _PepLong_AsInt(PyObject *);
*/
LIBSHIBOKEN_API int Pep_GetFlag(const char *name);
LIBSHIBOKEN_API int Pep_GetVerboseFlag(void);
-#define Py_VerboseFlag Pep_GetVerboseFlag()
#endif
/*****************************************************************************
@@ -234,12 +218,44 @@ LIBSHIBOKEN_API int Pep_GetVerboseFlag(void);
// PyUnicode_GetSize is deprecated in favor of PyUnicode_GetLength.
#define PepUnicode_GetLength(op) PyUnicode_GetLength((PyObject *)(op))
+// Unfortunately, we cannot ask this at runtime
+// #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
+// FIXME: Python 3.10: Replace _PepUnicode_AsString by PyUnicode_AsUTF8
#ifdef Py_LIMITED_API
-LIBSHIBOKEN_API char *_PepUnicode_AsString(PyObject *);
+LIBSHIBOKEN_API const char *_PepUnicode_AsString(PyObject *);
+
+enum PepUnicode_Kind {
+#if PY_VERSION_HEX < 0x030C0000
+ PepUnicode_WCHAR_KIND = 0,
+#endif
+ PepUnicode_1BYTE_KIND = 1,
+ PepUnicode_2BYTE_KIND = 2,
+ PepUnicode_4BYTE_KIND = 4
+};
+
+LIBSHIBOKEN_API int _PepUnicode_KIND(PyObject *);
+LIBSHIBOKEN_API int _PepUnicode_IS_ASCII(PyObject *str);
+LIBSHIBOKEN_API int _PepUnicode_IS_COMPACT(PyObject *str);
+
+LIBSHIBOKEN_API void *_PepUnicode_DATA(PyObject *str);
#else
+
+enum PepUnicode_Kind {
+#if PY_VERSION_HEX < 0x030C0000
+ PepUnicode_WCHAR_KIND = PyUnicode_WCHAR_KIND,
+#endif
+ PepUnicode_1BYTE_KIND = PyUnicode_1BYTE_KIND,
+ PepUnicode_2BYTE_KIND = PyUnicode_2BYTE_KIND,
+ PepUnicode_4BYTE_KIND = PyUnicode_4BYTE_KIND
+};
+
#define _PepUnicode_AsString PyUnicode_AsUTF8
+#define _PepUnicode_KIND PyUnicode_KIND
+#define _PepUnicode_DATA PyUnicode_DATA
+#define _PepUnicode_IS_COMPACT PyUnicode_IS_COMPACT
+#define _PepUnicode_IS_ASCII PyUnicode_IS_ASCII
#endif
/*****************************************************************************
@@ -291,7 +307,7 @@ LIBSHIBOKEN_API char *_PepUnicode_AsString(PyObject *);
#ifdef Py_LIMITED_API
-typedef struct _pycfunc PyCFunctionObject;
+using PyCFunctionObject = struct _pycfunc;
#define PyCFunction_GET_FUNCTION(func) PyCFunction_GetFunction((PyObject *)func)
#define PyCFunction_GET_SELF(func) PyCFunction_GetSelf((PyObject *)func)
#define PyCFunction_GET_FLAGS(func) PyCFunction_GetFlags((PyObject *)func)
@@ -321,11 +337,8 @@ LIBSHIBOKEN_API PyObject *PyRun_String(const char *, int, PyObject *, PyObject *
// buffer functions.
// But this is no problem as we check it's validity for every version.
-#define PYTHON_BUFFER_VERSION_COMPATIBLE (PY_VERSION_HEX >= 0x03030000 && \
- PY_VERSION_HEX < 0x0309FFFF)
-#if !PYTHON_BUFFER_VERSION_COMPATIBLE
-# error Please check the buffer compatibility for this python version!
-#endif
+// PYSIDE-1960 The buffer interface is since Python 3.11 part of the stable
+// API and we do not need to check the compatibility by hand anymore.
typedef struct {
getbufferproc bf_getbuffer;
@@ -409,10 +422,13 @@ LIBSHIBOKEN_API PyObject *PyMethod_Self(PyObject *);
typedef struct _code PepCodeObject;
LIBSHIBOKEN_API int PepCode_Get(PepCodeObject *co, const char *name);
+LIBSHIBOKEN_API int PepCode_Check(PyObject *o);
# define PepCode_GET_FLAGS(o) PepCode_Get(o, "co_flags")
# define PepCode_GET_ARGCOUNT(o) PepCode_Get(o, "co_argcount")
+LIBSHIBOKEN_API PyObject *PepFunction_GetDefaults(PyObject *function);
+
/* Masks for co_flags above */
# define CO_OPTIMIZED 0x0001
# define CO_NEWLOCALS 0x0002
@@ -426,7 +442,15 @@ LIBSHIBOKEN_API int PepCode_Get(PepCodeObject *co, const char *name);
# define PepCodeObject PyCodeObject
# define PepCode_GET_FLAGS(o) ((o)->co_flags)
# define PepCode_GET_ARGCOUNT(o) ((o)->co_argcount)
+# define PepCode_Check PyCode_Check
+# ifdef PYPY_VERSION
+
+LIBSHIBOKEN_API PyObject *PepFunction_GetDefaults(PyObject *function);
+
+# else
+# define PepFunction_GetDefaults PyFunction_GetDefaults
+# endif
#endif
/*****************************************************************************
@@ -514,6 +538,10 @@ LIBSHIBOKEN_API PyObject *PyStaticMethod_New(PyObject *callable);
#define PepStaticMethod_TypePtr &PyStaticMethod_Type
#endif
+#ifdef PYPY_VERSION
+extern LIBSHIBOKEN_API PyTypeObject *PepBuiltinMethod_TypePtr;
+#endif
+
// Although not PEP specific, we resolve this similar issue, here:
#define PepMethodDescr_TypePtr &PyMethodDescr_Type
@@ -523,13 +551,18 @@ LIBSHIBOKEN_API PyObject *PyStaticMethod_New(PyObject *callable);
*
* This is not defined if Py_LIMITED_API is defined.
*/
-#if PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API)
+#ifdef Py_LIMITED_API
LIBSHIBOKEN_API PyObject *PyImport_GetModule(PyObject *name);
-#endif // PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API)
+#endif // Py_LIMITED_API
// Evaluate a script and return the variable `result`
LIBSHIBOKEN_API PyObject *PepRun_GetResult(const char *command);
+// Call PyType_Type.tp_new returning a PyType object.
+LIBSHIBOKEN_API PyTypeObject *PepType_Type_tp_new(PyTypeObject *metatype,
+ PyObject *args,
+ PyObject *kwds);
+
/*****************************************************************************
*
* Runtime support for Python 3.8 incompatibilities
@@ -545,6 +578,20 @@ extern LIBSHIBOKEN_API int PepRuntime_38_flag;
/*****************************************************************************
*
+ * Runtime support for Python 3.12 incompatibility
+ *
+ */
+
+LIBSHIBOKEN_API PyObject *PepType_GetDict(PyTypeObject *type);
+
+// This function does not exist as PyType_SetDict. But because tp_dict
+// is no longer considered to be accessible, we treat it as such.
+LIBSHIBOKEN_API int PepType_SetDict(PyTypeObject *type, PyObject *dict);
+
+LIBSHIBOKEN_API void *PepType_GetSlot(PyTypeObject *type, int aSlot);
+
+/*****************************************************************************
+ *
* Module Initialization
*
*/