summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-03-07 09:21:08 (GMT)
committerGitHub <noreply@github.com>2024-03-07 09:21:08 (GMT)
commit72d3cc94cd8cae1925e7a14f297b06ac6184f916 (patch)
treedf9d7a5a97a79f97065282dd8e5a89f57ea2e18b /Python/pythonrun.c
parent882fcede83af783a834b759e4643130dc1307ee3 (diff)
downloadcpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.zip
cpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.tar.gz
cpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.tar.bz2
gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c10
1 files changed, 5 insertions, 5 deletions
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);