8000 unix: remove custome file.c code and use extmod's VFS-POSIX version instead by dpgeorge · Pull Request #5769 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

unix: remove custome file.c code and use extmod's VFS-POSIX version instead #5769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions extmod/vfs_posix_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "py/stream.h"
#include "extmod/vfs_posix.h"

#if MICROPY_VFS_POSIX
#if MICROPY_VFS_POSIX || MICROPY_VFS_POSIX_FILE

#include <fcntl.h>

Expand Down Expand Up @@ -157,7 +157,9 @@ STATIC mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t
return size;
}
#endif
MP_THREAD_GIL_EXIT();
mp_int_t r = write(o->fd, buf, size);
MP_THREAD_GIL_ENTER();
while (r == -1 && errno == EINTR) {
if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) {
mp_obj_t obj = MP_STATE_VM(mp_pending_exception);
Expand All @@ -184,6 +186,13 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_
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;
}
Expand All @@ -208,6 +217,8 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_
o->fd = -1;
#endif
return 0;
case MP_STREAM_GET_FILENO:
return o->fd;
default:
*errcode = EINVAL;
return MP_STREAM_ERROR;
Expand Down Expand Up @@ -272,4 +283,4 @@ const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_textio}, STDIN_FILEN
const mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_textio}, STDOUT_FILENO};
const mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_textio}, STDERR_FILENO};

#endif // MICROPY_VFS_POSIX
#endif // MICROPY_VFS_POSIX || MICROPY_VFS_POSIX_FILE
1 change: 0 additions & 1 deletion ports/unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ SRC_C = \
unix_mphal.c \
mpthreadport.c \
input.c \
file.c \
modmachine.c \
modos.c \
moduos_vfs.c \
Expand Down
40 changes: 0 additions & 40 deletions ports/unix/fdfile.h

This file was deleted.

Loading
0