summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-12-08 22:51:26 (GMT)
committerGitHub <noreply@github.com>2020-12-08 22:51:26 (GMT)
commit815506d852daabc40e14ff0987c1142c0205fbe7 (patch)
treeaadbd8f5afea0c937ecf861be5781ecd6bfc6b79 /Python
parent6d3dfee271b6e4afbfb060c269b034b871e2d1b3 (diff)
downloadcpython-815506d852daabc40e14ff0987c1142c0205fbe7.zip
cpython-815506d852daabc40e14ff0987c1142c0205fbe7.tar.gz
cpython-815506d852daabc40e14ff0987c1142c0205fbe7.tar.bz2
bpo-32381: Rewrite PyErr_ProgramText() (GH-23700)
PyErr_ProgramText() now calls PyErr_ProgramTextObject().
Diffstat (limited to 'Python')
-rw-r--r--Python/errors.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 213108f..9bac7ba 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -1697,13 +1697,18 @@ after_loop:
PyObject *
PyErr_ProgramText(const char *filename, int lineno)
{
- FILE *fp;
- if (filename == NULL || *filename == '\0' || lineno <= 0) {
+ if (filename == NULL) {
return NULL;
}
- PyThreadState *tstate = _PyThreadState_GET();
- fp = _Py_fopen(filename, "r" PY_STDIOTEXTMODE);
- return err_programtext(tstate, fp, lineno);
+
+ PyObject *filename_obj = PyUnicode_DecodeFSDefault(filename);
+ if (filename_obj == NULL) {
+ PyErr_Clear();
+ return NULL;
+ }
+ PyObject *res = PyErr_ProgramTextObject(filename_obj, lineno);
+ Py_DECREF(filename_obj);
+ return res;
}
PyObject *