diff options
author | Christian Tismer <tismer@stackless.com> | 2022-04-01 17:57:49 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2022-04-04 09:52:04 +0200 |
commit | ee11074ac2d391981e4def026b03604d4732c9f6 (patch) | |
tree | 3a3620698beee56a23975ec80d8c2aa46966f262 /sources | |
parent | 15c46c0f590d3b4eb4606378ccc8e311ee44f4c0 (diff) |
Support a Python 3.10 build in 5.15 without limited API
The original patch worked with limited API, only.
This one adds the missing _Py_Mangle function as in
PySide 6.X and modernizes and fixes the modern embedding
support.
A remaining problem is building with debug Python 3.10 .
There are many refcount errors which need to be found
again, because they all were solved in PySide 6.X .
With the same limited quality of the solution for 5.15 and
the limited API, this is a fix, the debug problem comes later.
Task-number: PYSIDE-1749
Fixes: PYSIDE-1775
Change-Id: I18a9b6756e49850c5d2d2e65b65e1ae934154905
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources')
-rw-r--r-- | sources/shiboken2/libshiboken/embed/signature_bootstrap.py | 42 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/pep384impl.cpp | 4 |
2 files changed, 24 insertions, 22 deletions
diff --git a/sources/shiboken2/libshiboken/embed/signature_bootstrap.py b/sources/shiboken2/libshiboken/embed/signature_bootstrap.py index b461ea229..508dd3fae 100644 --- a/sources/shiboken2/libshiboken/embed/signature_bootstrap.py +++ b/sources/shiboken2/libshiboken/embed/signature_bootstrap.py @@ -44,6 +44,11 @@ recursion_trap = 0 # Python 2 is not able to import when the extension import is still active. # Phase 1 simply defines the functions, which will be used in Phase 2. +import sys +if sys.version_info[0] >= 3: + from importlib.machinery import ModuleSpec + + def bootstrap(): import sys import os @@ -186,31 +191,28 @@ class EmbeddableZipImporter(object): return None self.zfile = zip_file - self._path2mod = {_.filename : p2m(_.filename) for _ in zip_file.filelist} - self._mod2path = {_[1] : _[0] for _ in self._path2mod.items()} + self._mod2path = {p2m(_.filename) : _.filename for _ in zip_file.filelist} - def find_module(self, fullname, path): - return self if self._mod2path.get(fullname) else None + def find_spec(self, fullname, path, target=None): + path = self._mod2path.get(fullname) + return ModuleSpec(fullname, self) if path else None - def load_module(self, fullname): - import importlib - import sys + def create_module(self, spec): + return None - filename = self._mod2path.get(fullname) - if filename not in self._path2mod: - raise ImportError(fullname) - module_spec = importlib.machinery.ModuleSpec(fullname, None) - new_module = importlib.util.module_from_spec(module_spec) + def exec_module(self, module): + fullname = module.__spec__.name + filename = self._mod2path[fullname] with self.zfile.open(filename, "r") as f: # "rb" not for zipfile - exec(f.read(), new_module.__dict__) - new_module.__file__ = filename - new_module.__loader__ = self + codeob = compile(f.read(), filename, "exec") + exec(codeob, module.__dict__) + module.__file__ = filename + module.__loader__ = self if filename.endswith("/__init__.py"): - new_module.__path__ = [] - new_module.__package__ = fullname + module.__path__ = [] + module.__package__ = fullname else: - new_module.__package__ = fullname.rpartition('.')[0] - sys.modules[fullname] = new_module - return new_module + module.__package__ = fullname.rpartition('.')[0] + sys.modules[fullname] = module # eof diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp index 629d5d84c..5b95b35ac 100644 --- a/sources/shiboken2/libshiboken/pep384impl.cpp +++ b/sources/shiboken2/libshiboken/pep384impl.cpp @@ -733,7 +733,7 @@ _Pep_PrivateMangle(PyObject *self, PyObject *name) #endif // IS_PY2 Shiboken::AutoDecRef privateobj(PyObject_GetAttr( reinterpret_cast<PyObject *>(Py_TYPE(self)), Shiboken::PyMagicName::name())); -#ifndef Py_LIMITED_API +#ifdef IS_PY2 return _Py_Mangle(privateobj, name); #else // PYSIDE-1436: _Py_Mangle is no longer exposed; implement it always. @@ -771,7 +771,7 @@ _Pep_PrivateMangle(PyObject *self, PyObject *name) if (amount > big_stack) free(resbuf); return result; -#endif // else Py_LIMITED_API +#endif // else IS_PY2 } /***************************************************************************** |