mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +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)
|
||||
|
|
|
@ -142,7 +142,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
meta = _PyDict_GetItemId(mkw, &PyId_metaclass);
|
||||
meta = _PyDict_GetItemIdWithError(mkw, &PyId_metaclass);
|
||||
if (meta != NULL) {
|
||||
Py_INCREF(meta);
|
||||
if (_PyDict_DelItemId(mkw, &PyId_metaclass) < 0) {
|
||||
|
@ -154,6 +154,11 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
|
|||
/* metaclass is explicitly given, check if it's indeed a class */
|
||||
isclass = PyType_Check(meta);
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
Py_DECREF(mkw);
|
||||
Py_DECREF(bases);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (meta == NULL) {
|
||||
/* if there are no bases, use type: */
|
||||
|
@ -956,11 +961,14 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (_PyDict_GetItemId(globals, &PyId___builtins__) == NULL) {
|
||||
if (_PyDict_GetItemIdWithError(globals, &PyId___builtins__) == NULL) {
|
||||
if (_PyDict_SetItemId(globals, &PyId___builtins__,
|
||||
PyEval_GetBuiltins()) != 0)
|
||||
return NULL;
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyCode_Check(source)) {
|
||||
if (PyCode_GetNumFree((PyCodeObject *)source) > 0) {
|
||||
|
@ -1036,11 +1044,14 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
|
|||
locals->ob_type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
if (_PyDict_GetItemId(globals, &PyId___builtins__) == NULL) {
|
||||
if (_PyDict_GetItemIdWithError(globals, &PyId___builtins__) == NULL) {
|
||||
if (_PyDict_SetItemId(globals, &PyId___builtins__,
|
||||
PyEval_GetBuiltins()) != 0)
|
||||
return NULL;
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyCode_Check(source)) {
|
||||
if (PyCode_GetNumFree((PyCodeObject *)source) > 0) {
|
||||
|
|
|
@ -2090,10 +2090,12 @@ main_loop:
|
|||
|
||||
PyObject *bc;
|
||||
if (PyDict_CheckExact(f->f_builtins)) {
|
||||
bc = _PyDict_GetItemId(f->f_builtins, &PyId___build_class__);
|
||||
bc = _PyDict_GetItemIdWithError(f->f_builtins, &PyId___build_class__);
|
||||
if (bc == NULL) {
|
||||
PyErr_SetString(PyExc_NameError,
|
||||
"__build_class__ not found");
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_NameError,
|
||||
"__build_class__ not found");
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
Py_INCREF(bc);
|
||||
|
@ -2241,8 +2243,10 @@ main_loop:
|
|||
int err;
|
||||
err = PyDict_DelItem(f->f_globals, name);
|
||||
if (err != 0) {
|
||||
format_exc_check_arg(
|
||||
PyExc_NameError, NAME_ERROR_MSG, name);
|
||||
if (PyErr_ExceptionMatches(PyExc_KeyError)) {
|
||||
format_exc_check_arg(
|
||||
PyExc_NameError, NAME_ERROR_MSG, name);
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
DISPATCH();
|
||||
|
@ -2258,8 +2262,13 @@ main_loop:
|
|||
goto error;
|
||||
}
|
||||
if (PyDict_CheckExact(locals)) {
|
||||
v = PyDict_GetItem(locals, name);
|
||||
Py_XINCREF(v);
|
||||
v = PyDict_GetItemWithError(locals, name);
|
||||
if (v != NULL) {
|
||||
Py_INCREF(v);
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else {
|
||||
v = PyObject_GetItem(locals, name);
|
||||
|
@ -2270,15 +2279,22 @@ main_loop:
|
|||
}
|
||||
}
|
||||
if (v == NULL) {
|
||||
v = PyDict_GetItem(f->f_globals, name);
|
||||
Py_XINCREF(v);
|
||||
if (v == NULL) {
|
||||
v = PyDict_GetItemWithError(f->f_globals, name);
|
||||
if (v != NULL) {
|
||||
Py_INCREF(v);
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
goto error;
|
||||
}
|
||||
else {
|
||||
if (PyDict_CheckExact(f->f_builtins)) {
|
||||
v = PyDict_GetItem(f->f_builtins, name);
|
||||
v = PyDict_GetItemWithError(f->f_builtins, name);
|
||||
if (v == NULL) {
|
||||
format_exc_check_arg(
|
||||
if (!PyErr_Occurred()) {
|
||||
format_exc_check_arg(
|
||||
PyExc_NameError,
|
||||
NAME_ERROR_MSG, name);
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
Py_INCREF(v);
|
||||
|
@ -2386,8 +2402,13 @@ main_loop:
|
|||
assert(idx >= 0 && idx < PyTuple_GET_SIZE(co->co_freevars));
|
||||
name = PyTuple_GET_ITEM(co->co_freevars, idx);
|
||||
if (PyDict_CheckExact(locals)) {
|
||||
value = PyDict_GetItem(locals, name);
|
||||
Py_XINCREF(value);
|
||||
value = PyDict_GetItemWithError(locals, name);
|
||||
if (value != NULL) {
|
||||
Py_INCREF(value);
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else {
|
||||
value = PyObject_GetItem(locals, name);
|
||||
|
@ -2591,9 +2612,12 @@ main_loop:
|
|||
}
|
||||
/* check if __annotations__ in locals()... */
|
||||
if (PyDict_CheckExact(f->f_locals)) {
|
||||
ann_dict = _PyDict_GetItemId(f->f_locals,
|
||||
ann_dict = _PyDict_GetItemIdWithError(f->f_locals,
|
||||
&PyId___annotations__);
|
||||
if (ann_dict == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
goto error;
|
||||
}
|
||||
/* ...if not, create a new one */
|
||||
ann_dict = PyDict_New();
|
||||
if (ann_dict == NULL) {
|
||||
|
@ -3921,12 +3945,15 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
|
|||
continue;
|
||||
name = PyTuple_GET_ITEM(co->co_varnames, i);
|
||||
if (kwdefs != NULL) {
|
||||
PyObject *def = PyDict_GetItem(kwdefs, name);
|
||||
PyObject *def = PyDict_GetItemWithError(kwdefs, name);
|
||||
if (def) {
|
||||
Py_INCREF(def);
|
||||
SETLOCAL(i, def);
|
||||
continue;
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
missing++;
|
||||
}
|
||||
|
@ -4861,9 +4888,11 @@ import_name(PyFrameObject *f, PyObject *name, PyObject *fromlist, PyObject *leve
|
|||
PyObject *import_func, *res;
|
||||
PyObject* stack[5];
|
||||
|
||||
import_func = _PyDict_GetItemId(f->f_builtins, &PyId___import__);
|
||||
import_func = _PyDict_GetItemIdWithError(f->f_builtins, &PyId___import__);
|
||||
if (import_func == NULL) {
|
||||
PyErr_SetString(PyExc_ImportError, "__import__ not found");
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_ImportError, "__import__ not found");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -5207,10 +5236,13 @@ unicode_concatenate(PyObject *v, PyObject *w,
|
|||
PyObject *names = f->f_code->co_names;
|
||||
PyObject *name = GETITEM(names, oparg);
|
||||
PyObject *locals = f->f_locals;
|
||||
if (locals && PyDict_CheckExact(locals) &&
|
||||
PyDict_GetItem(locals, name) == v) {
|
||||
if (PyDict_DelItem(locals, name) != 0) {
|
||||
PyErr_Clear();
|
||||
if (locals && PyDict_CheckExact(locals)) {
|
||||
PyObject *w = PyDict_GetItemWithError(locals, name);
|
||||
if ((w == v && PyDict_DelItem(locals, name) != 0) ||
|
||||
(w == NULL && PyErr_Occurred()))
|
||||
{
|
||||
Py_DECREF(v);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -858,6 +858,7 @@ PyErr_Format(PyObject *exception, const char *format, ...)
|
|||
PyObject *
|
||||
PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
|
||||
{
|
||||
_Py_IDENTIFIER(__module__);
|
||||
const char *dot;
|
||||
PyObject *modulename = NULL;
|
||||
PyObject *classname = NULL;
|
||||
|
@ -877,12 +878,15 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
|
|||
if (dict == NULL)
|
||||
goto failure;
|
||||
}
|
||||
if (PyDict_GetItemString(dict, "__module__") == NULL) {
|
||||
if (_PyDict_GetItemIdWithError(dict, &PyId___module__) == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
goto failure;
|
||||
}
|
||||
modulename = PyUnicode_FromStringAndSize(name,
|
||||
(Py_ssize_t)(dot-name));
|
||||
if (modulename == NULL)
|
||||
goto failure;
|
||||
if (PyDict_SetItemString(dict, "__module__", modulename) != 0)
|
||||
if (_PyDict_SetItemId(dict, &PyId___module__, modulename) != 0)
|
||||
goto failure;
|
||||
}
|
||||
if (PyTuple_Check(base)) {
|
||||
|
|
|
@ -1763,9 +1763,13 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
|
|||
current_arg = PyTuple_GET_ITEM(args, i);
|
||||
}
|
||||
else if (nkwargs && i >= pos) {
|
||||
current_arg = PyDict_GetItemString(kwargs, kwlist[i]);
|
||||
if (current_arg)
|
||||
current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
|
||||
if (current_arg) {
|
||||
--nkwargs;
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
return cleanreturn(0, &freelist);
|
||||
}
|
||||
}
|
||||
else {
|
||||
current_arg = NULL;
|
||||
|
@ -1844,7 +1848,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
|
|||
Py_ssize_t j;
|
||||
/* make sure there are no arguments given by name and position */
|
||||
for (i = pos; i < nargs; i++) {
|
||||
current_arg = PyDict_GetItemString(kwargs, kwlist[i]);
|
||||
current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
|
||||
if (current_arg) {
|
||||
/* arg present in tuple and in dict */
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
@ -1855,6 +1859,9 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
|
|||
kwlist[i], i+1);
|
||||
return cleanreturn(0, &freelist);
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
return cleanreturn(0, &freelist);
|
||||
}
|
||||
}
|
||||
/* make sure there are no extraneous keyword arguments */
|
||||
j = 0;
|
||||
|
@ -2016,13 +2023,10 @@ parser_clear(struct _PyArg_Parser *parser)
|
|||
}
|
||||
|
||||
static PyObject*
|
||||
find_keyword(PyObject *kwargs, PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
|
||||
find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
|
||||
{
|
||||
Py_ssize_t i, nkwargs;
|
||||
|
||||
if (kwargs != NULL) {
|
||||
return PyDict_GetItem(kwargs, key);
|
||||
}
|
||||
nkwargs = PyTuple_GET_SIZE(kwnames);
|
||||
for (i=0; i < nkwargs; i++) {
|
||||
PyObject *kwname = PyTuple_GET_ITEM(kwnames, i);
|
||||
|
@ -2157,9 +2161,18 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
|
|||
}
|
||||
else if (nkwargs && i >= pos) {
|
||||
keyword = PyTuple_GET_ITEM(kwtuple, i - pos);
|
||||
current_arg = find_keyword(kwargs, kwnames, kwstack, keyword);
|
||||
if (current_arg)
|
||||
if (kwargs != NULL) {
|
||||
current_arg = PyDict_GetItemWithError(kwargs, keyword);
|
||||
if (!current_arg && PyErr_Occurred()) {
|
||||
return cleanreturn(0, &freelist);
|
||||
}
|
||||
}
|
||||
else {
|
||||
current_arg = find_keyword(kwnames, kwstack, keyword);
|
||||
}
|
||||
if (current_arg) {
|
||||
--nkwargs;
|
||||
}
|
||||
}
|
||||
else {
|
||||
current_arg = NULL;
|
||||
|
@ -2220,7 +2233,15 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
|
|||
/* make sure there are no arguments given by name and position */
|
||||
for (i = pos; i < nargs; i++) {
|
||||
keyword = PyTuple_GET_ITEM(kwtuple, i - pos);
|
||||
current_arg = find_keyword(kwargs, kwnames, kwstack, keyword);
|
||||
if (kwargs != NULL) {
|
||||
current_arg = PyDict_GetItemWithError(kwargs, keyword);
|
||||
if (!current_arg && PyErr_Occurred()) {
|
||||
return cleanreturn(0, &freelist);
|
||||
}
|
||||
}
|
||||
else {
|
||||
current_arg = find_keyword(kwnames, kwstack, keyword);
|
||||
}
|
||||
if (current_arg) {
|
||||
/* arg present in tuple and in dict */
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -359,12 +359,12 @@ PySymtable_Lookup(struct symtable *st, void *key)
|
|||
k = PyLong_FromVoidPtr(key);
|
||||
if (k == NULL)
|
||||
return NULL;
|
||||
v = PyDict_GetItem(st->st_blocks, k);
|
||||
v = PyDict_GetItemWithError(st->st_blocks, k);
|
||||
if (v) {
|
||||
assert(PySTEntry_Check(v));
|
||||
Py_INCREF(v);
|
||||
}
|
||||
else {
|
||||
else if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_KeyError,
|
||||
"unknown symbol table entry");
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ update_symbols(PyObject *symbols, PyObject *scopes,
|
|||
}
|
||||
|
||||
while ((name = PyIter_Next(itr))) {
|
||||
v = PyDict_GetItem(symbols, name);
|
||||
v = PyDict_GetItemWithError(symbols, name);
|
||||
|
||||
/* Handle symbol that already exists in this scope */
|
||||
if (v) {
|
||||
|
@ -662,6 +662,9 @@ update_symbols(PyObject *symbols, PyObject *scopes,
|
|||
Py_DECREF(name);
|
||||
continue;
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
goto error;
|
||||
}
|
||||
/* Handle global symbol */
|
||||
if (bound && !PySet_Contains(bound, name)) {
|
||||
Py_DECREF(name);
|
||||
|
@ -991,7 +994,7 @@ symtable_add_def_helper(struct symtable *st, PyObject *name, int flag, struct _s
|
|||
if (!mangled)
|
||||
return 0;
|
||||
dict = ste->ste_symbols;
|
||||
if ((o = PyDict_GetItem(dict, mangled))) {
|
||||
if ((o = PyDict_GetItemWithError(dict, mangled))) {
|
||||
val = PyLong_AS_LONG(o);
|
||||
if ((flag & DEF_PARAM) && (val & DEF_PARAM)) {
|
||||
/* Is it better to use 'mangled' or 'name' here? */
|
||||
|
@ -1002,8 +1005,13 @@ symtable_add_def_helper(struct symtable *st, PyObject *name, int flag, struct _s
|
|||
goto error;
|
||||
}
|
||||
val |= flag;
|
||||
} else
|
||||
}
|
||||
else if (PyErr_Occurred()) {
|
||||
goto error;
|
||||
}
|
||||
else {
|
||||
val = flag;
|
||||
}
|
||||
o = PyLong_FromLong(val);
|
||||
if (o == NULL)
|
||||
goto error;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue