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:
Sam Gross 2024-02-07 13:43:18 -05:00 committed by GitHub
parent fedbf77191
commit ef3ceab09d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 32 additions and 25 deletions

View file

@ -691,11 +691,10 @@ _parse_object_unicode(PyScannerObject *s, PyObject *memo, PyObject *pystr, Py_ss
key = scanstring_unicode(pystr, idx + 1, s->strict, &next_idx);
if (key == NULL)
goto bail;
memokey = PyDict_SetDefault(memo, key, key);
if (memokey == NULL) {
if (PyDict_SetDefaultRef(memo, key, key, &memokey) < 0) {
goto bail;
}
Py_SETREF(key, Py_NewRef(memokey));
Py_SETREF(key, memokey);
idx = next_idx;
/* skip whitespace between key and : delimiter, read :, skip whitespace */