summaryrefslogtreecommitdiffstats
path: root/Python/codecs.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-02-25 15:59:46 (GMT)
committerGitHub <noreply@github.com>2019-02-25 15:59:46 (GMT)
commita24107b04c1277e3c1105f98aff5bfa3a98b33a0 (patch)
tree55aa5a700e08e3ba27b0361df2b1043be5c4701a /Python/codecs.c
parenta180b007d96fe68b32f11dec720fbd0cd5b6758a (diff)
downloadcpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.zip
cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.gz
cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.bz2
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
Diffstat (limited to 'Python/codecs.c')
-rw-r--r--Python/codecs.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index ff2142d..d4b34f8 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;
}