Mailing List Archive

[3.12] gh-117968: Make the test for closed file more safe in the C API tests (GH-118230) (GH-118266)
https://github.com/python/cpython/commit/33d1cfffe150c667aa64c52e1bdd929e227e6212
commit: 33d1cfffe150c667aa64c52e1bdd929e227e6212
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
committer: serhiy-storchaka <storchaka@gmail.com>
date: 2024-04-25T05:16:43Z
summary:

[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 546cbcfa0eeeb533950bd49e30423f3d3bbd5ebe)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

files:
M Modules/_testcapi/run.c

diff --git a/Modules/_testcapi/run.c b/Modules/_testcapi/run.c
index baf728c2b632ad..16c7b756c38ba3 100644
--- a/Modules/_testcapi/run.c
+++ b/Modules/_testcapi/run.c
@@ -75,8 +75,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);

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-leave@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: list-python-checkins@lists.gossamer-threads.com