unix/file: Don't raise OSError(EINVAL) on sys.stdin/out/err.flush().

sys.stdout.flush() is needed on CPython to flush the output, and the change
in this commit makes such an expression also work on MicroPython (although
MicroPython doesn't actual need to do any flushing).
This commit is contained in:
Damien George 2020-03-04 12:39:55 +11:00
parent 9c07c973c1
commit 3e0b46b9af
1 changed files with 7 additions and 0 deletions

View File

@ -126,6 +126,13 @@ STATIC mp_uint_t fdfile_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i
int ret = fsync(o->fd);
MP_THREAD_GIL_ENTER();
if (ret == -1) {
if (errno == EINVAL
&& (o->fd == STDIN_FILENO || o->fd == STDOUT_FILENO || o->fd == STDERR_FILENO)) {
// fsync(stdin/stdout/stderr) may fail with EINVAL, but don't propagate that
// error out. Because data is not buffered by us, and stdin/out/err.flush()
// should just be a no-op.
return 0;
}
*errcode = errno;
return MP_STREAM_ERROR;
}