summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/Python-ast.c18
-rw-r--r--Python/bltinmodule.c5
-rw-r--r--Python/bytecodes.c14
-rw-r--r--Python/executor_cases.c.h14
-rw-r--r--Python/generated_cases.c.h14
-rw-r--r--Python/pythonrun.c10
6 files changed, 36 insertions, 39 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 4638749..7b591dd 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -5223,20 +5223,20 @@ ast_type_reduce(PyObject *self, PyObject *unused)
if (!name) {
goto cleanup;
}
- PyObject *value = PyDict_GetItemWithError(remaining_dict, name);
+ PyObject *value;
+ int rc = PyDict_Pop(remaining_dict, name, &value);
+ Py_DECREF(name);
+ if (rc < 0) {
+ goto cleanup;
+ }
if (!value) {
- if (PyErr_Occurred()) {
- goto cleanup;
- }
break;
}
- if (PyList_Append(positional_args, value) < 0) {
+ rc = PyList_Append(positional_args, value);
+ Py_DECREF(value);
+ if (rc < 0) {
goto cleanup;
}
- if (PyDict_DelItem(remaining_dict, name) < 0) {
- goto cleanup;
- }
- Py_DECREF(name);
}
PyObject *args_tuple = PyList_AsTuple(positional_args);
if (!args_tuple) {
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index b007496..f66a8c0 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -140,13 +140,10 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
goto error;
}
- if (PyDict_GetItemRef(mkw, &_Py_ID(metaclass), &meta) < 0) {
+ if (PyDict_Pop(mkw, &_Py_ID(metaclass), &meta) < 0) {
goto error;
}
if (meta != NULL) {
- if (PyDict_DelItem(mkw, &_Py_ID(metaclass)) < 0) {
- goto error;
- }
/* metaclass is explicitly given, check if it's indeed a class */
isclass = PyType_Check(meta);
}
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index bf0583d..3276a4a 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -1307,14 +1307,14 @@ dummy_func(
inst(DELETE_GLOBAL, (--)) {
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
- int err;
- err = PyDict_DelItem(GLOBALS(), name);
+ int err = PyDict_Pop(GLOBALS(), name, NULL);
// Can't use ERROR_IF here.
- if (err != 0) {
- if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
- _PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
- NAME_ERROR_MSG, name);
- }
+ if (err < 0) {
+ GOTO_ERROR(error);
+ }
+ if (err == 0) {
+ _PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
+ NAME_ERROR_MSG, name);
GOTO_ERROR(error);
}
}
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index 4420c40..2e7b970 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -1167,14 +1167,14 @@
case _DELETE_GLOBAL: {
oparg = CURRENT_OPARG();
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
- int err;
- err = PyDict_DelItem(GLOBALS(), name);
+ int err = PyDict_Pop(GLOBALS(), name, NULL);
// Can't use ERROR_IF here.
- if (err != 0) {
- if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
- _PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
- NAME_ERROR_MSG, name);
- }
+ if (err < 0) {
+ GOTO_ERROR(error);
+ }
+ if (err == 0) {
+ _PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
+ NAME_ERROR_MSG, name);
GOTO_ERROR(error);
}
break;
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 6e8ca82..54c4861 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -2368,14 +2368,14 @@
next_instr += 1;
INSTRUCTION_STATS(DELETE_GLOBAL);
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
- int err;
- err = PyDict_DelItem(GLOBALS(), name);
+ int err = PyDict_Pop(GLOBALS(), name, NULL);
// Can't use ERROR_IF here.
- if (err != 0) {
- if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
- _PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
- NAME_ERROR_MSG, name);
- }
+ if (err < 0) {
+ GOTO_ERROR(error);
+ }
+ if (err == 0) {
+ _PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
+ NAME_ERROR_MSG, name);
GOTO_ERROR(error);
}
DISPATCH();
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index f87c53f..2970248 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -452,7 +452,7 @@ _PyRun_SimpleFileObject(FILE *fp, PyObject *filename, int closeit,
v = run_pyc_file(pyc_fp, dict, dict, flags);
} else {
/* When running from stdin, leave __main__.__loader__ alone */
- if (PyUnicode_CompareWithASCIIString(filename, "<stdin>") != 0 &&
+ if ((!PyUnicode_Check(filename) || !PyUnicode_EqualToUTF8(filename, "<stdin>")) &&
set_main_loader(dict, filename, "SourceFileLoader") < 0) {
fprintf(stderr, "python: failed to set __main__.__loader__\n");
ret = -1;
@@ -472,11 +472,11 @@ _PyRun_SimpleFileObject(FILE *fp, PyObject *filename, int closeit,
done:
if (set_file_name) {
- if (PyDict_DelItemString(dict, "__file__")) {
- PyErr_Clear();
+ if (PyDict_PopString(dict, "__file__", NULL) < 0) {
+ PyErr_Print();
}
- if (PyDict_DelItemString(dict, "__cached__")) {
- PyErr_Clear();
+ if (PyDict_PopString(dict, "__cached__", NULL) < 0) {
+ PyErr_Print();
}
}
Py_XDECREF(main_module);