diff options
author | Christian Tismer <tismer@stackless.com> | 2022-07-03 09:21:06 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-07-07 18:30:00 +0000 |
commit | 5d053862fbfe41752fb61d9de03bbfaa2bca145b (patch) | |
tree | 5f43def1e77b95112cb9904f10f44db43a9953be | |
parent | b29df93b5d968faa07a5aa93e326936ebcf2aab1 (diff) |
Shiboken: Move the shibokensupport initialization into the module
Importing shibokensupport is now possible inside the Shiboken import.
That is a prerequisite to re-order the signature initialization,
which is again mandatory for the new PyEnum forgiveness feature.
This allows to remove much initialization code and makes the
Shiboken startup less vulnerable.
Task-number: PYSIDE-1735
Change-Id: Iaed4275d7e204fb242b1466cd6d2c09ad10002b5
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit 06448ba29c2e568f64132b81ce56ec2b063e456c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/pyside6/PySide6/__init__.py.in | 20 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.cpp | 18 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.h | 2 | ||||
-rw-r--r-- | sources/shiboken6/shibokenmodule/__init__.py.in | 3 | ||||
-rw-r--r-- | sources/shiboken6/shibokenmodule/typesystem_shiboken.xml | 4 |
5 files changed, 16 insertions, 31 deletions
diff --git a/sources/pyside6/PySide6/__init__.py.in b/sources/pyside6/PySide6/__init__.py.in index 8f6c47b87..d0a4ecc37 100644 --- a/sources/pyside6/PySide6/__init__.py.in +++ b/sources/pyside6/PySide6/__init__.py.in @@ -68,26 +68,6 @@ def _setupQtDirectories(): file=sys.stderr) raise - # Trigger signature initialization. - try: - # PYSIDE-829: Avoid non-existent attributes in compiled code (Nuitka). - # We now use an explicit function instead of touching a signature. - _init_pyside_extension() - except (AttributeError, NameError): - stars = 79 * "*" - fname = Shiboken.__file__ - print(dedent(f'''\ - {stars} - PySide6/__init__.py: The `signature` module was not initialized. - This libshiboken module was loaded from - - "{fname}". - - Please make sure that this is the real Shiboken binary and not just a folder. - {stars} - '''), file=sys.stderr) - raise - if sys.platform == 'win32': # PATH has to contain the package directory, otherwise plugins # won't be able to find their required Qt libraries (e.g. the diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index c84473311..74ed68faa 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -57,6 +57,7 @@ #include <algorithm> #include "threadstatesaver.h" #include "signature.h" +#include "signature_p.h" #include "voidptr.h" #include <iostream> @@ -756,14 +757,21 @@ void init() } // PYSIDE-1415: Publish Shiboken objects. -void initSignature(PyObject *module) +// PYSIDE-1735: Initialize the whole Shiboken startup. +void initShibokenSupport(PyObject *module) { - auto *type = SbkObject_TypeF(); - if (InitSignatureStrings(type, SbkObject_SignatureStrings) < 0) - return; - Py_INCREF(SbkObject_TypeF()); PyModule_AddObject(module, "Object", reinterpret_cast<PyObject *>(SbkObject_TypeF())); + + // PYSIDE-1735: When the initialization was moved into Shiboken import, this + // Py_INCREF became necessary. No idea why. + Py_INCREF(module); + init_module_1(); + init_module_2(); + + auto *type = SbkObject_TypeF(); + if (InitSignatureStrings(type, SbkObject_SignatureStrings) < 0) + Py_FatalError("Error in initShibokenSupport"); } // setErrorAboutWrongArguments now gets overload info from the signature module. diff --git a/sources/shiboken6/libshiboken/basewrapper.h b/sources/shiboken6/libshiboken/basewrapper.h index 682321653..815a85e51 100644 --- a/sources/shiboken6/libshiboken/basewrapper.h +++ b/sources/shiboken6/libshiboken/basewrapper.h @@ -155,7 +155,7 @@ namespace Shiboken LIBSHIBOKEN_API void init(); /// PYSIDE-1415: Publish Shiboken objects. -LIBSHIBOKEN_API void initSignature(PyObject *module); +LIBSHIBOKEN_API void initShibokenSupport(PyObject *module); /// Delete the class T allocated on \p cptr. template<typename T> diff --git a/sources/shiboken6/shibokenmodule/__init__.py.in b/sources/shiboken6/shibokenmodule/__init__.py.in index 5508403a9..c859160bc 100644 --- a/sources/shiboken6/shibokenmodule/__init__.py.in +++ b/sources/shiboken6/shibokenmodule/__init__.py.in @@ -25,6 +25,3 @@ import functools import typing from shiboken6.Shiboken import * - -# Trigger signature initialization via __builtins__. -_init_pyside_extension() diff --git a/sources/shiboken6/shibokenmodule/typesystem_shiboken.xml b/sources/shiboken6/shibokenmodule/typesystem_shiboken.xml index 1bee3f543..5bc361644 100644 --- a/sources/shiboken6/shibokenmodule/typesystem_shiboken.xml +++ b/sources/shiboken6/shibokenmodule/typesystem_shiboken.xml @@ -125,8 +125,8 @@ PyTuple_SET_ITEM(version, 4, PyLong_FromLong(SHIBOKEN_SERIAL)); PyModule_AddObject(module, "__version_info__", version); PyModule_AddStringConstant(module, "__version__", SHIBOKEN_VERSION); - - Shiboken::initSignature(module); VoidPtr::addVoidPtrToModule(module); + + Shiboken::initShibokenSupport(module); </inject-code> </typesystem> |