[Python-checkins] GH-90699: fix ref counting of static immortal strings (gh-94850)
miss-islington
webhook-mailer at python.org
Wed Jul 20 02:56:56 EDT 2022
https://github.com/python/cpython/commit/84d58ad17baec0dda8a5ffd8d925343391e45b3e
commit: 84d58ad17baec0dda8a5ffd8d925343391e45b3e
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-07-19T23:56:47-07:00
summary:
GH-90699: fix ref counting of static immortal strings (gh-94850)
(cherry picked from commit 1834133e66d95a143c9df5f068b3109927aefd65)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
files:
A Misc/NEWS.d/next/Core and Builtins/2022-07-14-10-07-53.gh-issue-90699.x3aG9m.rst
M Modules/_io/textio.c
M Objects/boolobject.c
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-07-14-10-07-53.gh-issue-90699.x3aG9m.rst b/Misc/NEWS.d/next/Core and Builtins/2022-07-14-10-07-53.gh-issue-90699.x3aG9m.rst
new file mode 100644
index 0000000000000..795f4df987eb9
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-07-14-10-07-53.gh-issue-90699.x3aG9m.rst
@@ -0,0 +1 @@
+Fix reference counting bug in :meth:`bool.__repr__`. Patch by Kumar Aditya.
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 89094d66f3834..3369694653fd9 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -2244,7 +2244,7 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
Py_CLEAR(chunks);
}
if (line == NULL) {
- line = &_Py_STR(empty);
+ line = Py_NewRef(&_Py_STR(empty));
}
return line;
diff --git a/Objects/boolobject.c b/Objects/boolobject.c
index ff7218760ab36..8a20e368d4a42 100644
--- a/Objects/boolobject.c
+++ b/Objects/boolobject.c
@@ -9,7 +9,8 @@
static PyObject *
bool_repr(PyObject *self)
{
- return self == Py_True ? &_Py_ID(True) : &_Py_ID(False);
+ PyObject *res = self == Py_True ? &_Py_ID(True) : &_Py_ID(False);
+ return Py_NewRef(res);
}
/* Function to return a bool from a C long */
More information about the Python-checkins
mailing list