pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/b3ab94acd308591bbdf264f1722fedc7ee25d6fa

aa60c69660fa.css" /> gh-135878: Fix crash in `types.SimpleNamespace.__repr__` (#135889) · python/cpython@b3ab94a · GitHub
Skip to content

Commit b3ab94a

Browse files
gh-135878: Fix crash in types.SimpleNamespace.__repr__ (#135889)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent e5f03b9 commit b3ab94a

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixes a crash of :class:`types.SimpleNamespace` on :term:`free threading` builds,
2+
when several threads were calling its :meth:`~object.__repr__` method at the
3+
same time.

Objects/namespaceobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ namespace_repr(PyObject *ns)
124124
if (PyUnicode_Check(key) && PyUnicode_GET_LENGTH(key) > 0) {
125125
PyObject *value, *item;
126126

127-
value = PyDict_GetItemWithError(d, key);
128-
if (value != NULL) {
127+
int has_key = PyDict_GetItemRef(d, key, &value);
128+
if (has_key == 1) {
129129
item = PyUnicode_FromFormat("%U=%R", key, value);
130+
Py_DECREF(value);
130131
if (item == NULL) {
131132
loop_error = 1;
132133
}
@@ -135,7 +136,7 @@ namespace_repr(PyObject *ns)
135136
Py_DECREF(item);
136137
}
137138
}
138-
else if (PyErr_Occurred()) {
139+
else if (has_key < 0) {
139140
loop_error = 1;
140141
}
141142
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy