Skip to content

gh-117968: Make the test for closed file more safe in the C API tests #118230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Modules/_testcapi/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ run_fileexflags(PyObject *mod, PyObject *pos_args)

result = PyRun_FileExFlags(fp, filename, start, globals, locals, closeit, pflags);

#if !defined(__wasi__)
/* The behavior of fileno() after fclose() is undefined. */
#if defined(__linux__) || defined(MS_WINDOWS) || defined(__APPLE__)
/* The behavior of fileno() after fclose() is undefined, but it is
* the only practical way to check whether the file was closed.
* Only test this on the known platforms. */
if (closeit && result && fileno(fp) >= 0) {
PyErr_SetString(PyExc_AssertionError, "File was not closed after excution");
Py_DECREF(result);
Expand Down
Loading