summaryrefslogtreecommitdiff
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-02-25 17:59:46 +0200
committerGitHub <noreply@github.com>2019-02-25 17:59:46 +0200
commita24107b04c1277e3c1105f98aff5bfa3a98b33a0 (patch)
tree55aa5a700e08e3ba27b0361df2b1043be5c4701a /Python/_warnings.c
parenta180b007d96fe68b32f11dec720fbd0cd5b6758a (diff)
downloadcpython-git-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.gz
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 7eedd1374c..33b4615115 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -252,7 +252,7 @@ already_warned(PyObject *registry, PyObject *key, int should_set)
if (key == NULL)
return -1;
- version_obj = _PyDict_GetItemId(registry, &PyId_version);
+ version_obj = _PyDict_GetItemIdWithError(registry, &PyId_version);
if (version_obj == NULL
|| !PyLong_CheckExact(version_obj)
|| PyLong_AsLong(version_obj) != _PyRuntime.warnings.filters_version)
@@ -271,12 +271,15 @@ already_warned(PyObject *registry, PyObject *key, int should_set)
Py_DECREF(version_obj);
}
else {
- already_warned = PyDict_GetItem(registry, key);
+ already_warned = PyDict_GetItemWithError(registry, key);
if (already_warned != NULL) {
int rc = PyObject_IsTrue(already_warned);
if (rc != 0)
return rc;
}
+ else if (PyErr_Occurred()) {
+ return -1;
+ }
}
/* This warning wasn't found in the registry, set it. */
@@ -672,6 +675,8 @@ static int
setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
PyObject **module, PyObject **registry)
{
+ _Py_IDENTIFIER(__warningregistry__);
+ _Py_IDENTIFIER(__name__);
PyObject *globals;
/* Setup globals, filename and lineno. */
@@ -706,15 +711,18 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
/* Setup registry. */
assert(globals != NULL);
assert(PyDict_Check(globals));
- *registry = PyDict_GetItemString(globals, "__warningregistry__");
+ *registry = _PyDict_GetItemIdWithError(globals, &PyId___warningregistry__);
if (*registry == NULL) {
int rc;
+ if (PyErr_Occurred()) {
+ return 0;
+ }
*registry = PyDict_New();
if (*registry == NULL)
return 0;
- rc = PyDict_SetItemString(globals, "__warningregistry__", *registry);
+ rc = _PyDict_SetItemId(globals, &PyId___warningregistry__, *registry);
if (rc < 0)
goto handle_error;
}
@@ -722,10 +730,13 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
Py_INCREF(*registry);
/* Setup module. */
- *module = PyDict_GetItemString(globals, "__name__");
+ *module = _PyDict_GetItemIdWithError(globals, &PyId___name__);
if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) {
Py_INCREF(*module);
}
+ else if (PyErr_Occurred()) {
+ goto handle_error;
+ }
else {
*module = PyUnicode_FromString("<string>");
if (*module == NULL)