mirror of
https://github.com/python/cpython.git
synced 2025-09-19 07:00:59 +00:00
Issue #27454: Use PyDict_SetDefault in PyUnicode_InternInPlace
Patch by INADA Naoki.
This commit is contained in:
parent
81fb0e33d6
commit
ced8d4c6eb
1 changed files with 6 additions and 14 deletions
|
@ -15039,26 +15039,18 @@ PyUnicode_InternInPlace(PyObject **p)
|
||||||
return;
|
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
|
Py_ALLOW_RECURSION
|
||||||
t = PyDict_GetItem(interned, s);
|
t = PyDict_SetDefault(interned, s, s);
|
||||||
Py_END_ALLOW_RECURSION
|
Py_END_ALLOW_RECURSION
|
||||||
|
if (t == NULL) {
|
||||||
if (t) {
|
PyErr_Clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (t != s) {
|
||||||
Py_INCREF(t);
|
Py_INCREF(t);
|
||||||
Py_SETREF(*p, t);
|
Py_SETREF(*p, t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyThreadState_GET()->recursion_critical = 1;
|
|
||||||
if (PyDict_SetItem(interned, s, s) < 0) {
|
|
||||||
PyErr_Clear();
|
|
||||||
PyThreadState_GET()->recursion_critical = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PyThreadState_GET()->recursion_critical = 0;
|
|
||||||
/* The two references in interned are not counted by refcnt.
|
/* The two references in interned are not counted by refcnt.
|
||||||
The deallocator will take care of this */
|
The deallocator will take care of this */
|
||||||
Py_REFCNT(s) -= 2;
|
Py_REFCNT(s) -= 2;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue