mirror of
https://github.com/python/cpython.git
synced 2025-08-24 02:35:59 +00:00
gh-112066: Use PyDict_SetDefaultRef
in place of PyDict_SetDefault
. (#112211)
This changes a number of internal usages of `PyDict_SetDefault` to use `PyDict_SetDefaultRef`. Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
parent
fedbf77191
commit
ef3ceab09d
6 changed files with 32 additions and 25 deletions
|
@ -14894,16 +14894,18 @@ _PyUnicode_InternInPlace(PyInterpreterState *interp, PyObject **p)
|
|||
PyObject *interned = get_interned_dict(interp);
|
||||
assert(interned != NULL);
|
||||
|
||||
PyObject *t = PyDict_SetDefault(interned, s, s);
|
||||
if (t == NULL) {
|
||||
PyObject *t;
|
||||
int res = PyDict_SetDefaultRef(interned, s, s, &t);
|
||||
if (res < 0) {
|
||||
PyErr_Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (t != s) {
|
||||
Py_SETREF(*p, Py_NewRef(t));
|
||||
else if (res == 1) {
|
||||
// value was already present (not inserted)
|
||||
Py_SETREF(*p, t);
|
||||
return;
|
||||
}
|
||||
Py_DECREF(t);
|
||||
|
||||
if (_Py_IsImmortal(s)) {
|
||||
// XXX Restrict this to the main interpreter?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue