mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +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
|
@ -431,9 +431,13 @@ PyImport_Cleanup(void)
|
|||
for (p = sys_files; *p != NULL; p+=2) {
|
||||
if (Py_VerboseFlag)
|
||||
PySys_WriteStderr("# restore sys.%s\n", *p);
|
||||
value = PyDict_GetItemString(interp->sysdict, *(p+1));
|
||||
if (value == NULL)
|
||||
value = _PyDict_GetItemStringWithError(interp->sysdict, *(p+1));
|
||||
if (value == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_WriteUnraisable(NULL);
|
||||
}
|
||||
value = Py_None;
|
||||
}
|
||||
if (PyDict_SetItemString(interp->sysdict, *p, value) < 0) {
|
||||
PyErr_WriteUnraisable(NULL);
|
||||
}
|
||||
|
@ -718,7 +722,7 @@ _PyImport_FindExtensionObjectEx(PyObject *name, PyObject *filename,
|
|||
key = PyTuple_Pack(2, filename, name);
|
||||
if (key == NULL)
|
||||
return NULL;
|
||||
def = (PyModuleDef *)PyDict_GetItem(extensions, key);
|
||||
def = (PyModuleDef *)PyDict_GetItemWithError(extensions, key);
|
||||
Py_DECREF(key);
|
||||
if (def == NULL)
|
||||
return NULL;
|
||||
|
@ -927,6 +931,7 @@ error:
|
|||
static PyObject *
|
||||
module_dict_for_exec(PyObject *name)
|
||||
{
|
||||
_Py_IDENTIFIER(__builtins__);
|
||||
PyObject *m, *d = NULL;
|
||||
|
||||
m = PyImport_AddModuleObject(name);
|
||||
|
@ -935,9 +940,11 @@ module_dict_for_exec(PyObject *name)
|
|||
/* If the module is being reloaded, we get the old module back
|
||||
and re-use its dict to exec the new code. */
|
||||
d = PyModule_GetDict(m);
|
||||
if (PyDict_GetItemString(d, "__builtins__") == NULL) {
|
||||
if (PyDict_SetItemString(d, "__builtins__",
|
||||
PyEval_GetBuiltins()) != 0) {
|
||||
if (_PyDict_GetItemIdWithError(d, &PyId___builtins__) == NULL) {
|
||||
if (PyErr_Occurred() ||
|
||||
_PyDict_SetItemId(d, &PyId___builtins__,
|
||||
PyEval_GetBuiltins()) != 0)
|
||||
{
|
||||
remove_module(name);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1107,8 +1114,8 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks,
|
|||
if (nhooks < 0)
|
||||
return NULL; /* Shouldn't happen */
|
||||
|
||||
importer = PyDict_GetItem(path_importer_cache, p);
|
||||
if (importer != NULL)
|
||||
importer = PyDict_GetItemWithError(path_importer_cache, p);
|
||||
if (importer != NULL || PyErr_Occurred())
|
||||
return importer;
|
||||
|
||||
/* set path_importer_cache[p] to None to avoid recursion */
|
||||
|
@ -1496,11 +1503,17 @@ resolve_name(PyObject *name, PyObject *globals, int level)
|
|||
PyErr_SetString(PyExc_TypeError, "globals must be a dict");
|
||||
goto error;
|
||||
}
|
||||
package = _PyDict_GetItemId(globals, &PyId___package__);
|
||||
package = _PyDict_GetItemIdWithError(globals, &PyId___package__);
|
||||
if (package == Py_None) {
|
||||
package = NULL;
|
||||
}
|
||||
spec = _PyDict_GetItemId(globals, &PyId___spec__);
|
||||
else if (package == NULL && PyErr_Occurred()) {
|
||||
goto error;
|
||||
}
|
||||
spec = _PyDict_GetItemIdWithError(globals, &PyId___spec__);
|
||||
if (spec == NULL && PyErr_Occurred()) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (package != NULL) {
|
||||
Py_INCREF(package);
|
||||
|
@ -1546,9 +1559,11 @@ resolve_name(PyObject *name, PyObject *globals, int level)
|
|||
goto error;
|
||||
}
|
||||
|
||||
package = _PyDict_GetItemId(globals, &PyId___name__);
|
||||
package = _PyDict_GetItemIdWithError(globals, &PyId___name__);
|
||||
if (package == NULL) {
|
||||
PyErr_SetString(PyExc_KeyError, "'__name__' not in globals");
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_KeyError, "'__name__' not in globals");
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -1558,10 +1573,10 @@ resolve_name(PyObject *name, PyObject *globals, int level)
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (_PyDict_GetItemId(globals, &PyId___path__) == NULL) {
|
||||
if (_PyDict_GetItemIdWithError(globals, &PyId___path__) == NULL) {
|
||||
Py_ssize_t dot;
|
||||
|
||||
if (PyUnicode_READY(package) < 0) {
|
||||
if (PyErr_Occurred() || PyUnicode_READY(package) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue