From a24107b04c1277e3c1105f98aff5bfa3a98b33a0 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 25 Feb 2019 17:59:46 +0200 Subject: bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112) --- Python/codecs.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'Python/codecs.c') diff --git a/Python/codecs.c b/Python/codecs.c index ff2142df40..d4b34f8397 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -120,12 +120,16 @@ PyObject *_PyCodec_Lookup(const char *encoding) PyUnicode_InternInPlace(&v); /* First, try to lookup the name in the registry dictionary */ - result = PyDict_GetItem(interp->codec_search_cache, v); + result = PyDict_GetItemWithError(interp->codec_search_cache, v); if (result != NULL) { Py_INCREF(result); Py_DECREF(v); return result; } + else if (PyErr_Occurred()) { + Py_DECREF(v); + return NULL; + } /* Next, scan the search functions in order of registration */ args = PyTuple_New(1); @@ -648,11 +652,13 @@ PyObject *PyCodec_LookupError(const char *name) if (name==NULL) name = "strict"; - handler = PyDict_GetItemString(interp->codec_error_registry, name); - if (!handler) - PyErr_Format(PyExc_LookupError, "unknown error handler name '%.400s'", name); - else + handler = _PyDict_GetItemStringWithError(interp->codec_error_registry, name); + if (handler) { Py_INCREF(handler); + } + else if (!PyErr_Occurred()) { + PyErr_Format(PyExc_LookupError, "unknown error handler name '%.400s'", name); + } return handler; } -- cgit v1.2.1