Skip to content

Commit 33d1cff

Browse files
[3.12] gh-117968: Make the test for closed file more safe in the C API tests (GH-118230) (GH-118266)
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 (Linux, Windows, macOS), where we already tested that it works. (cherry picked from commit 546cbcf) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent c784b3e commit 33d1cff

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Modules/_testcapi/run.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ run_fileexflags(PyObject *mod, PyObject *pos_args)
7575

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

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

0 commit comments

Comments
 (0)