diff options
Diffstat (limited to 'sources/shiboken2')
-rw-r--r-- | sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp | 20 | ||||
-rw-r--r-- | sources/shiboken2/doc/typesystem_specifying_types.rst | 13 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/basewrapper.cpp | 16 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/sbkenum.cpp | 13 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp | 5 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/sbkstring.cpp | 19 | ||||
-rw-r--r-- | sources/shiboken2/shiboken_version.py | 2 | ||||
-rw-r--r-- | sources/shiboken2/shibokenmodule/CMakeLists.txt | 8 | ||||
-rw-r--r-- | sources/shiboken2/shibokenmodule/Shiboken.pyi | 54 | ||||
-rw-r--r-- | sources/shiboken2/shibokenmodule/py.typed.in | 1 |
10 files changed, 130 insertions, 21 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp index b73670909..ebe3b995a 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp @@ -784,18 +784,22 @@ static bool cStringStartsWith(const char *str, const QByteArray &prefix) return std::strncmp(prefix.constData(), str, int(prefix.size())) == 0; } +#ifdef Q_OS_UNIX +static bool cStringContains(const char *str, const char *prefix) +{ + return std::strstr(str, prefix) != nullptr; +} +#endif + bool BuilderPrivate::visitHeader(const char *cFileName) const { // Resolve OpenGL typedefs although the header is considered a system header. const char *baseName = cBaseName(cFileName); if (cCompareFileName(baseName, "gl.h")) return true; -#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) - if (cStringStartsWith(cFileName, "/usr/include/stdint.h")) - return true; -#endif #ifdef Q_OS_LINUX - if (cStringStartsWith(cFileName, "/usr/include/stdlib.h") + if (cStringStartsWith(cFileName, "/usr/include/stdint.h") + || cStringStartsWith(cFileName, "/usr/include/stdlib.h") || cStringStartsWith(cFileName, "/usr/include/sys/types.h")) { return true; } @@ -804,9 +808,9 @@ bool BuilderPrivate::visitHeader(const char *cFileName) const // Parse the following system headers to get the correct typdefs for types like // int32_t, which are used in the macOS implementation of OpenGL framework. if (cCompareFileName(baseName, "gltypes.h") - || cStringStartsWith(cFileName, "/usr/include/_types") - || cStringStartsWith(cFileName, "/usr/include/_types") - || cStringStartsWith(cFileName, "/usr/include/sys/_types")) { + || cStringContains(cFileName, "/usr/include/stdint.h") + || cStringContains(cFileName, "/usr/include/_types") + || cStringContains(cFileName, "/usr/include/sys/_types")) { return true; } #endif // Q_OS_MACOS diff --git a/sources/shiboken2/doc/typesystem_specifying_types.rst b/sources/shiboken2/doc/typesystem_specifying_types.rst index 221519541..e43b878ba 100644 --- a/sources/shiboken2/doc/typesystem_specifying_types.rst +++ b/sources/shiboken2/doc/typesystem_specifying_types.rst @@ -81,14 +81,17 @@ rejection <typesystem> <rejection class="..." function-name="..." + argument-type="..." field-name="..." /> </typesystem> - The **class** attribute is the C++ class name of the class to reject. Use the - *optional* **function-name** or **field-name** attributes to reject a particular - function or field. Note that the **field-name** and **function-name** cannot - be specified at the same time. To remove all occurrences of a given field or - function, set the class attribute to \*. + The **class** attribute is the C++ class name of the class to reject. Use + the *optional* **function-name**, **argument-type**, or **field-name** + attributes to reject a particular function, function with arguments of a + particular type, or a field. Note that the **field-name** and + **function-name**/**argument-type** cannot be specified at the same time. + To remove all occurrences of a given field or function, set the class + attribute to \*. .. _primitive-type: diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index afca7fa08..1919f2825 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -376,8 +376,9 @@ SbkObjectType *SbkObject_TypeF(void) { static PyTypeObject *type = nullptr; if (!type) { - type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(&SbkObject_Type_spec)); - Py_TYPE(type) = SbkObjectType_TypeF(); + auto *obj = SbkType_FromSpec(&SbkObject_Type_spec); + type = reinterpret_cast<PyTypeObject *>(obj); + obj->ob_type = SbkObjectType_TypeF(); Py_INCREF(Py_TYPE(type)); type->tp_weaklistoffset = offsetof(SbkObject, weakreflist); type->tp_dictoffset = offsetof(SbkObject, ob_dict); @@ -521,7 +522,11 @@ void SbkObjectTypeDealloc(PyObject *pyObj) PyObject_GC_UnTrack(pyObj); #ifndef Py_LIMITED_API +# if PY_VERSION_HEX >= 0x030A0000 + Py_TRASHCAN_BEGIN(pyObj, 1); +# else Py_TRASHCAN_SAFE_BEGIN(pyObj); +# endif #endif if (sotp) { if (sotp->user_data && sotp->d_func) { @@ -536,7 +541,11 @@ void SbkObjectTypeDealloc(PyObject *pyObj) sotp = nullptr; } #ifndef Py_LIMITED_API +# if PY_VERSION_HEX >= 0x030A0000 + Py_TRASHCAN_END; +# else Py_TRASHCAN_SAFE_END(pyObj); +# endif #endif if (PepRuntime_38_flag) { // PYSIDE-939: Handling references correctly. @@ -1161,7 +1170,7 @@ introduceWrapperType(PyObject *enclosingObject, typeSpec->slots[0].pfunc = reinterpret_cast<void *>(baseType ? baseType : SbkObject_TypeF()); PyObject *heaptype = SbkType_FromSpecWithBases(typeSpec, baseTypes); - Py_TYPE(heaptype) = SbkObjectType_TypeF(); + heaptype->ob_type = SbkObjectType_TypeF(); Py_INCREF(Py_TYPE(heaptype)); auto *type = reinterpret_cast<SbkObjectType *>(heaptype); #if PY_VERSION_HEX < 0x03000000 @@ -1526,6 +1535,7 @@ bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr) bool isValid(PyObject *pyObj) { if (!pyObj || pyObj == Py_None + || PyType_Check(pyObj) != 0 || Py_TYPE(Py_TYPE(pyObj)) != SbkObjectType_TypeF()) { return true; } diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index 7dc73dfbc..38e702296 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -330,13 +330,21 @@ void SbkEnumTypeDealloc(PyObject *pyObj) PyObject_GC_UnTrack(pyObj); #ifndef Py_LIMITED_API +# if PY_VERSION_HEX >= 0x030A0000 + Py_TRASHCAN_BEGIN(pyObj, 1); +# else Py_TRASHCAN_SAFE_BEGIN(pyObj); +# endif #endif if (PepType_SETP(sbkType)->converter) { Shiboken::Conversions::deleteConverter(PepType_SETP(sbkType)->converter); } #ifndef Py_LIMITED_API +# if PY_VERSION_HEX >= 0x030A0000 + Py_TRASHCAN_END; +# else Py_TRASHCAN_SAFE_END(pyObj); +# endif #endif if (PepRuntime_38_flag) { // PYSIDE-939: Handling references correctly. @@ -752,9 +760,10 @@ newTypeWithName(const char *name, static auto basetype = SbkEnum_TypeF(); Py_INCREF(basetype); PyTuple_SetItem(bases, 0, reinterpret_cast<PyObject *>(basetype)); - auto *type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpecWithBases(&newspec, bases)); + auto *obj = SbkType_FromSpecWithBases(&newspec, bases); + auto *type = reinterpret_cast<PyTypeObject *>(obj); PyErr_Print(); - Py_TYPE(type) = SbkEnumType_TypeF(); + obj->ob_type = SbkEnumType_TypeF(); auto *enumType = reinterpret_cast<SbkEnumType *>(type); PepType_SETP(enumType)->cppName = cppName; diff --git a/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp b/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp index 996968fa1..cc25b349d 100644 --- a/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp +++ b/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp @@ -116,8 +116,13 @@ std::ostream &operator<<(std::ostream &str, PyArrayObject *o) str << " NPY_ARRAY_NOTSWAPPED"; if ((flags & NPY_ARRAY_WRITEABLE) != 0) str << " NPY_ARRAY_WRITEABLE"; +#if NPY_VERSION >= 0x00000010 // NPY_1_23_API_VERSION + if ((flags & NPY_ARRAY_WRITEBACKIFCOPY) != 0) + str << " NPY_ARRAY_WRITEBACKIFCOPY"; +#else if ((flags & NPY_ARRAY_UPDATEIFCOPY) != 0) str << " NPY_ARRAY_UPDATEIFCOPY"; +#endif } else { str << '0'; } diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp index 077fb531b..0f83aeef0 100644 --- a/sources/shiboken2/libshiboken/sbkstring.cpp +++ b/sources/shiboken2/libshiboken/sbkstring.cpp @@ -41,8 +41,14 @@ #include "sbkstaticstrings_p.h" #include "autodecref.h" -#include <vector> -#include <unordered_set> +#if PY_VERSION_HEX >= 0x03000000 +# define USE_INTERN_STRINGS +#endif + +#ifndef USE_INTERN_STRINGS +# include <vector> +# include <unordered_set> +#endif namespace Shiboken { @@ -233,6 +239,13 @@ Py_ssize_t len(PyObject *str) // PyObject *attr = PyObject_GetAttr(obj, name()); // +#ifdef USE_INTERN_STRINGS +PyObject *createStaticString(const char *str) +{ + return PyUnicode_InternFromString(str); +} +#else + using StaticStrings = std::unordered_set<PyObject *>; static void finalizeStaticStrings(); // forward @@ -283,6 +296,8 @@ PyObject *createStaticString(const char *str) return result; } +#endif // !USE_INTERN_STRINGS + /////////////////////////////////////////////////////////////////////// // // PYSIDE-1019: Helper function for snake_case vs. camelCase names diff --git a/sources/shiboken2/shiboken_version.py b/sources/shiboken2/shiboken_version.py index 80dd16ae0..88792a380 100644 --- a/sources/shiboken2/shiboken_version.py +++ b/sources/shiboken2/shiboken_version.py @@ -39,7 +39,7 @@ major_version = "5" minor_version = "15" -patch_version = "10" +patch_version = "11" # For example: "a", "b", "rc" # (which means "alpha", "beta", "release candidate"). diff --git a/sources/shiboken2/shibokenmodule/CMakeLists.txt b/sources/shiboken2/shibokenmodule/CMakeLists.txt index 9b2b58528..c861caf29 100644 --- a/sources/shiboken2/shibokenmodule/CMakeLists.txt +++ b/sources/shiboken2/shibokenmodule/CMakeLists.txt @@ -41,6 +41,14 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/_config.py" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in" "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Shiboken.pyi" + "${CMAKE_CURRENT_BINARY_DIR}/Shiboken.pyi" @ONLY) +# typing support for mypy +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/py.typed.in" + "${CMAKE_CURRENT_BINARY_DIR}/py.typed" @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Shiboken.pyi" + "${CMAKE_CURRENT_BINARY_DIR}/py.typed" + DESTINATION "${PYTHON_SITE_PACKAGES}/shiboken2") # Variable from enclosing scope. foreach(item IN LISTS shiboken_python_files) diff --git a/sources/shiboken2/shibokenmodule/Shiboken.pyi b/sources/shiboken2/shibokenmodule/Shiboken.pyi new file mode 100644 index 000000000..93556ba40 --- /dev/null +++ b/sources/shiboken2/shibokenmodule/Shiboken.pyi @@ -0,0 +1,54 @@ +############################################################################# +## +## Copyright (C) 2022 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of Qt for Python. +## +## $QT_BEGIN_LICENSE:COMM$ +## +## 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. +## +## $QT_END_LICENSE$ +## +############################################################################# + +from __future__ import annotations + +""" +This file contains the exact signatures for all functions in module +Shiboken, except for defaults which are replaced by "...". +""" + +# Module `Shiboken` + +from shiboken2 import Shiboken + + +class Object(object): + + def __init__(self) -> None: ... + + +class VoidPtr(object): ... + + +def _unpickle_enum(arg__1: object, arg__2: object) -> object: ... +def createdByPython(arg__1: Shiboken.Object) -> bool: ... +def delete(arg__1: Shiboken.Object) -> None: ... +def dump(arg__1: object) -> str: ... +def getAllValidWrappers() -> Shiboken.Object: ... +def getCppPointer(arg__1: Shiboken.Object) -> Shiboken.Object: ... +def invalidate(arg__1: Shiboken.Object) -> None: ... +def isValid(arg__1: object) -> bool: ... +def ownedByPython(arg__1: Shiboken.Object) -> bool: ... +def wrapInstance(arg__1: int, arg__2: type) -> Shiboken.Object: ... + + +# eof diff --git a/sources/shiboken2/shibokenmodule/py.typed.in b/sources/shiboken2/shibokenmodule/py.typed.in new file mode 100644 index 000000000..0e76a07dc --- /dev/null +++ b/sources/shiboken2/shibokenmodule/py.typed.in @@ -0,0 +1 @@ +# this is a marker file for mypy |