Skip to content

Commit

Permalink
pythongh-111789: Use PyDict_GetItemRef() in Python/codecs.c (pythongh…
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored and Glyphack committed Jan 27, 2024
1 parent 0716aa5 commit 80eb439
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Python/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,14 @@ PyObject *_PyCodec_Lookup(const char *encoding)
PyUnicode_InternInPlace(&v);

/* First, try to lookup the name in the registry dictionary */
PyObject *result = PyDict_GetItemWithError(interp->codec_search_cache, v);
PyObject *result;
if (PyDict_GetItemRef(interp->codec_search_cache, v, &result) < 0) {
goto onError;
}
if (result != NULL) {
Py_INCREF(result);
Py_DECREF(v);
return result;
}
else if (PyErr_Occurred()) {
goto onError;
}

/* Next, scan the search functions in order of registration */
const Py_ssize_t len = PyList_Size(interp->codec_search_path);
Expand Down

0 comments on commit 80eb439

Please sign in to comment.