diff options
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r-- | Python/_warnings.c | 21 |
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) |