]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117968: Make the test for closed file more safe in the C API tests (GH-118230)
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 25 Apr 2024 05:00:42 +0000 (08:00 +0300)
committerGitHub <noreply@github.com>
Thu, 25 Apr 2024 05:00:42 +0000 (08:00 +0300)
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.

Modules/_testcapi/run.c

index fa3251c4b5b31009415206549bf98e7bd8dc4685..4fd98b82d762ff46d103cf137cd4f8052d71eb22 100644 (file)
@@ -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);