summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-07-25 01:40:39 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-07-25 01:40:39 (GMT)
commitced8d4c6ebc23598a9c14736dbc69533c80a78f7 (patch)
tree395deb58c71a454dbde6a1c928d6cd28eb99f0ba /Objects/unicodeobject.c
parent81fb0e33d6f869146934e760cd18044214ec825d (diff)
downloadcpython-ced8d4c6ebc23598a9c14736dbc69533c80a78f7.zip
cpython-ced8d4c6ebc23598a9c14736dbc69533c80a78f7.tar.gz
cpython-ced8d4c6ebc23598a9c14736dbc69533c80a78f7.tar.bz2
Issue #27454: Use PyDict_SetDefault in PyUnicode_InternInPlace
Patch by INADA Naoki.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index db6a51c..0932f35 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -15039,26 +15039,18 @@ PyUnicode_InternInPlace(PyObject **p)
return;
}
}
- /* It might be that the GetItem call fails even
- though the key is present in the dictionary,
- namely when this happens during a stack overflow. */
Py_ALLOW_RECURSION
- t = PyDict_GetItem(interned, s);
+ t = PyDict_SetDefault(interned, s, s);
Py_END_ALLOW_RECURSION
-
- if (t) {
- Py_INCREF(t);
- Py_SETREF(*p, t);
+ if (t == NULL) {
+ PyErr_Clear();
return;
}
-
- PyThreadState_GET()->recursion_critical = 1;
- if (PyDict_SetItem(interned, s, s) < 0) {
- PyErr_Clear();
- PyThreadState_GET()->recursion_critical = 0;
+ if (t != s) {
+ Py_INCREF(t);
+ Py_SETREF(*p, t);
return;
}
- PyThreadState_GET()->recursion_critical = 0;
/* The two references in interned are not counted by refcnt.
The deallocator will take care of this */
Py_REFCNT(s) -= 2;