diff options
author | Sam Gross <colesbury@gmail.com> | 2024-02-07 18:43:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-07 18:43:18 (GMT) |
commit | ef3ceab09d2d0959c343c662461123d5b0e0b64b (patch) | |
tree | 7c7be8598454fca38217703987b9f60e66e4a952 /Objects/unicodeobject.c | |
parent | fedbf77191ea9d6515b39f958cc9e588d23517c9 (diff) | |
download | cpython-ef3ceab09d2d0959c343c662461123d5b0e0b64b.zip cpython-ef3ceab09d2d0959c343c662461123d5b0e0b64b.tar.gz cpython-ef3ceab09d2d0959c343c662461123d5b0e0b64b.tar.bz2 |
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>
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b236ddb..0a569a9 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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? |