mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
This commit is contained in:
parent
a180b007d9
commit
a24107b04c
31 changed files with 538 additions and 242 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue