diff options
Diffstat (limited to 'sources/shiboken6/libshiboken/pep384impl.h')
-rw-r--r-- | sources/shiboken6/libshiboken/pep384impl.h | 109 |
1 files changed, 80 insertions, 29 deletions
diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h index a1ccad81f..ec58aac81 100644 --- a/sources/shiboken6/libshiboken/pep384impl.h +++ b/sources/shiboken6/libshiboken/pep384impl.h @@ -4,11 +4,6 @@ #ifndef PEP384IMPL_H #define PEP384IMPL_H -// PYSIDE-1436: Adapt to Python 3.10 -#if PY_VERSION_HEX < 0x030900A4 -# define Py_SET_REFCNT(obj, refcnt) ((Py_REFCNT(obj) = (refcnt)), (void)0) -#endif - extern "C" { @@ -55,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 */ @@ -103,24 +135,16 @@ 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 into Python 3.8 . - -// PYSIDE-1797: This must be a runtime decision. -// Remove that when the minimum Python version is 3.8, -// because the macro PepIndex_Check bug was fixed then. -/// FIXME: Remove PepIndex_Check and pep384_issue33738.cpp when Python 3.7 is gone. -LIBSHIBOKEN_API int PepIndex_Check(PyObject *obj); - LIBSHIBOKEN_API PyObject *_PepType_Lookup(PyTypeObject *type, PyObject *name); #else // Py_LIMITED_API -#define PepIndex_Check(obj) PyIndex_Check(obj) #define _PepType_Lookup(type, name) _PyType_Lookup(type, 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 @@ -139,16 +163,15 @@ 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); +LIBSHIBOKEN_API PyObject *Pep_GetPartialFunction(void); + /***************************************************************************** * * RESOLVED: pydebug.h @@ -163,7 +186,6 @@ LIBSHIBOKEN_API const char *PepType_GetNameStr(PyTypeObject *type); */ LIBSHIBOKEN_API int Pep_GetFlag(const char *name); LIBSHIBOKEN_API int Pep_GetVerboseFlag(void); -#define Py_VerboseFlag Pep_GetVerboseFlag() #endif /***************************************************************************** @@ -193,12 +215,17 @@ 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 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 @@ -213,7 +240,9 @@ 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 @@ -275,7 +304,7 @@ enum PepUnicode_Kind { #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) @@ -305,11 +334,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 < 0x030AFFFF) -#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; @@ -393,10 +419,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 @@ -410,7 +439,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 /***************************************************************************** @@ -511,9 +548,9 @@ extern LIBSHIBOKEN_API PyTypeObject *PepBuiltinMethod_TypePtr; * * 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); @@ -538,6 +575,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 * */ |