8000 bpo-32381: Rewrite PyErr_ProgramText() (GH-23700) · python/cpython@815506d · GitHub
[go: up one dir, main page]

Skip to content

Commit 815506d

Browse files
authored
bpo-32381: Rewrite PyErr_ProgramText() (GH-23700)
PyErr_ProgramText() now calls PyErr_ProgramTextObject().
1 parent 6d3dfee commit 815506d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Python/errors.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,13 +1697,18 @@ err_programtext(PyThreadState *tstate, FILE *fp, int lineno)
16971697
PyObject *
16981698
PyErr_ProgramText(const char *filename, int lineno)
16991699
{
1700-
FILE *fp;
1701-
if (filename == NULL || *filename == '\0' || lineno <= 0) {
1700+
if (filename == NULL) {
17021701
return NULL;
17031702
}
1704-
PyThreadState *tstate = _PyThreadState_GET();
1705-
fp = _Py_fopen(filename, "r" PY_STDIOTEXTMODE);
1706-
return err_programtext(tstate, fp, lineno);
1703+
1704+
PyObject *filename_obj = PyUnicode_DecodeFSDefault(filename);
1705+
if (filename_obj == NULL) {
1706+
PyErr_Clear();
1707+
return NULL;
1708+
}
1709+
PyObject *res = PyErr_ProgramTextObject(filename_obj, lineno);
1710+
Py_DECREF(filename_obj);
1711+
return res;
17071712
}
17081713

17091714
PyObject *

0 commit comments

Comments
 (0)
0