mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[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 546cbcfa0e
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
c784b3e8fc
commit
33d1cfffe1
1 changed files with 4 additions and 2 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue