aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-10-21 10:48:46 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-11-10 11:49:14 +0000
commitf97461f7440add879ebdc0d57c4fd1e3f41d48a4 (patch)
treee1b9d4ba5f2cbc50dc6f8abc04a2481f25e426b3
parente3627da4a5dd93974867036b3f28d30c790d3b07 (diff)
_PepUnicode_AsString: Fix a broken promise
This function was optimized in an incompatible way. It does not work when the string argument is short-lived. But: It was found that the equivalent function without Limited API does not survive short-lived arguments, either. So the broken promise was still there, but in a different way than assumed ;-) Fortunately, the replacement function PyUnicode_AsUTF8 is part of the Limited API since Python 3.10 and we can avoid this hack. Unfortunately, there is no way to know which runtime-version this will be, and we must wait until Python 3.10 becomes the minimum version :( Change-Id: Id2b1ea3212984a69bef8d71a578825978c59947e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit a8004df5a920e02a783d896af33bb83619492b02) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.cpp11
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.h3
-rw-r--r--sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py13
3 files changed, 16 insertions, 11 deletions
diff --git a/sources/shiboken6/libshiboken/pep384impl.cpp b/sources/shiboken6/libshiboken/pep384impl.cpp
index 0b9e901f9..3a9a60f74 100644
--- a/sources/shiboken6/libshiboken/pep384impl.cpp
+++ b/sources/shiboken6/libshiboken/pep384impl.cpp
@@ -345,11 +345,12 @@ static const char *utf8FastPath(PyObject *str)
const char *_PepUnicode_AsString(PyObject *str)
{
/*
- * We need to keep the string alive but cannot borrow the Python object.
- * Ugly easy way out: We re-code as an interned bytes string. This
- * produces a pseudo-leak as long as there are new strings.
- * Typically, this function is used for name strings, and the dict size
- * will not grow so much.
+ * This function is the surrogate for PyUnicode_AsUTF8, which keeps the data
+ * in the unicode object as long as that object exists.
+ *
+ * The function does too much if not optimized by utf8, because it keeps the
+ * string alive, unconditionally.
+ * We should not rely on this behavior and think of PyUnicode_AsUTF8, only.
*/
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h
index 05743fbba..07cdb3a6f 100644
--- a/sources/shiboken6/libshiboken/pep384impl.h
+++ b/sources/shiboken6/libshiboken/pep384impl.h
@@ -193,6 +193,9 @@ 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 *);
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py
index dc62aa724..be82a4f92 100644
--- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py
+++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py
@@ -69,18 +69,19 @@ def _get_flag_enum_option():
flag = getattr(sys, sysname)
if not isinstance(flag, int):
flag = True
+ p = f"\n *** Python is at version {'.'.join(map(str, pyminver))} now."
# PYSIDE-1797: Emit a warning when we may remove pep384_issue33738.cpp
if pyminver and pyminver >= (3, 8):
- warnings.warn(f"\n *** Python is at version {'.'.join(map(str, pyminver))} now. "
- f"The file pep384_issue33738.cpp should be removed ASAP! ***")
+ warnings.warn(f"{p} The file pep384_issue33738.cpp should be removed ASAP! ***")
+ # _PepUnicode_AsString: Fix a broken promise
+ if pyminver and pyminver >= (3, 10):
+ warnings.warn(f"{p} _PepUnicode_AsString can now be replaced by PyUnicode_AsUTF8! ***")
# PYSIDE-1960: Emit a warning when we may remove pep384_issue33738.cpp
if pyminver and pyminver >= (3, 11):
- warnings.warn(f"\n *** Python is at version {'.'.join(map(str, pyminver))} now. "
- f"The files bufferprocs_py37.(cpp|h) should be removed ASAP! ***")
+ warnings.warn(f"{p} The files bufferprocs_py37.(cpp|h) should be removed ASAP! ***")
# PYSIDE-1735: Emit a warning when we should maybe evict forgiveness mode
if ver[:2] >= (7, 0):
- warnings.warn(f"\n *** PySide is at version {'.'.join(map(str, ver[:2]))} now. "
- f"Please drop the forgiving Enum behavior in `mangled_type_getattro` ***")
+ warnings.warn(f"{p} Please drop Enum forgiveness mode in `mangled_type_getattro` ***")
# normalize the sys attribute
setattr(sys, sysname, flag)
os.environ[envname] = str(flag)