diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-10-28 20:34:11 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-10-28 20:34:11 +0000 |
commit | ef9875b11a33dbd25e92bc6b4cf692c18c9ba0ce (patch) | |
tree | 1f2fd4e4d9e585da35937b42fbda5f854af04728 /contrib/tools/python3/patches/124938.patch | |
parent | 37ae9cc90160b53eb0e22021c47b3996a01cd656 (diff) | |
parent | e3c8507a3d1cb090278f211232ddfde3bedc54d4 (diff) | |
download | ydb-ef9875b11a33dbd25e92bc6b4cf692c18c9ba0ce.tar.gz |
Merge branch 'rightlib' into mergelibs-241028-2033
Diffstat (limited to 'contrib/tools/python3/patches/124938.patch')
-rw-r--r-- | contrib/tools/python3/patches/124938.patch | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/contrib/tools/python3/patches/124938.patch b/contrib/tools/python3/patches/124938.patch new file mode 100644 index 0000000000..218691a926 --- /dev/null +++ b/contrib/tools/python3/patches/124938.patch @@ -0,0 +1,81 @@ +From 3e07c20277cda90941953426f7bddc71d009388a Mon Sep 17 00:00:00 2001 +From: "Miss Islington (bot)" + <31488909+miss-islington@users.noreply.github.com> +Date: Tue, 16 Jul 2024 15:42:49 +0200 +Subject: [PATCH] [3.12] gh-113993: For string interning, do not rely on (or + assert) _Py_IsImmortal (GH-121358) (GH-121851) + +gh-113993: For string interning, do not rely on (or assert) _Py_IsImmortal (GH-121358) + +Older stable ABI extensions are allowed to make immortal objects mortal. +Instead, use `_PyUnicode_STATE` (`interned` and `statically_allocated`). +(cherry picked from commit 956270d08d5c23f59937e2f29f8e0b7f63d68afd) + +Co-authored-by: Petr Viktorin <encukou@gmail.com> +--- + ...024-07-04-13-23-27.gh-issue-113601.K3RLqp.rst | 2 ++ + Objects/unicodeobject.c | 16 ++++++++++------ + 2 files changed, 12 insertions(+), 6 deletions(-) + create mode 100644 Misc/NEWS.d/next/C API/2024-07-04-13-23-27.gh-issue-113601.K3RLqp.rst + +diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c +index 815747e1b1ed9c..7bd4b221c83cf7 100644 +--- a/Objects/unicodeobject.c ++++ b/Objects/unicodeobject.c +@@ -257,7 +257,8 @@ _PyUnicode_InternedSize_Immortal(void) + // value, to help detect bugs in optimizations. + + while (PyDict_Next(dict, &pos, &key, &value)) { +- if (_Py_IsImmortal(key)) { ++ assert(PyUnicode_CHECK_INTERNED(key) != SSTATE_INTERNED_IMMORTAL_STATIC); ++ if (PyUnicode_CHECK_INTERNED(key) == SSTATE_INTERNED_IMMORTAL) { + count++; + } + } +@@ -691,10 +692,14 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) + + /* Check interning state */ + #ifdef Py_DEBUG ++ // Note that we do not check `_Py_IsImmortal(op)`, since stable ABI ++ // extensions can make immortal strings mortal (but with a high enough ++ // refcount). ++ // The other way is extremely unlikely (worth a potential failed assertion ++ // in a debug build), so we do check `!_Py_IsImmortal(op)`. + switch (PyUnicode_CHECK_INTERNED(op)) { + case SSTATE_NOT_INTERNED: + if (ascii->state.statically_allocated) { +- CHECK(_Py_IsImmortal(op)); + // This state is for two exceptions: + // - strings are currently checked before they're interned + // - the 256 one-latin1-character strings +@@ -710,11 +715,9 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) + break; + case SSTATE_INTERNED_IMMORTAL: + CHECK(!ascii->state.statically_allocated); +- CHECK(_Py_IsImmortal(op)); + break; + case SSTATE_INTERNED_IMMORTAL_STATIC: + CHECK(ascii->state.statically_allocated); +- CHECK(_Py_IsImmortal(op)); + break; + default: + Py_UNREACHABLE(); +@@ -1899,7 +1902,8 @@ unicode_write_cstr(PyObject *unicode, Py_ssize_t index, + static PyObject* + get_latin1_char(Py_UCS1 ch) + { +- return Py_NewRef(LATIN1(ch)); ++ PyObject *o = LATIN1(ch); ++ return o; + } + + static PyObject* +@@ -15015,7 +15019,7 @@ intern_common(PyInterpreterState *interp, PyObject *s /* stolen */, + { + PyObject *r = (PyObject *)_Py_hashtable_get(INTERNED_STRINGS, s); + if (r != NULL) { +- assert(_Py_IsImmortal(r)); ++ assert(_PyUnicode_STATE(r).statically_allocated); + assert(r != s); // r must be statically_allocated; s is not + Py_DECREF(s); + return Py_NewRef(r); |