8000 py/stream: Implement generic flush() method, in terms of C-level ioctl. · sparkfun/circuitpython@a60b026 · GitHub
[go: up one dir, main page]

Skip to content

Commit a60b026

Browse files
committed
py/stream: Implement generic flush() method, in terms of C-level ioctl.
1 parent ade3680 commit a60b026

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

py/stream.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,17 @@ STATIC mp_obj_t stream_tell(mp_obj_t self) {
477477
}
478478
MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_tell_obj, stream_tell);
479479

480+
STATIC mp_obj_t stream_flush(mp_obj_t self) {
481+
const mp_stream_p_t *stream_p = mp_get_stream_raise(self, MP_STREAM_OP_IOCTL);
482+
int error;
483+
mp_uint_t res = stream_p->ioctl(self, MP_STREAM_FLUSH, 0, &error);
484+
if (res == MP_STREAM_ERROR) {
485+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error)));
486+
}
487+
return mp_const_none;
488+
}
489+
MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_flush_obj, stream_flush);
490+
480491
STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) {
481492
const mp_stream_p_t *stream_p = mp_get_stream_raise(args[0], MP_STREAM_OP_IOCTL);
482493

py/stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_stream_write_obj);
5858
MP_DECLARE_CONST_FUN_OBJ(mp_stream_write1_obj);
5959
MP_DECLARE_CONST_FUN_OBJ(mp_stream_seek_obj);
6060
MP_DECLARE_CONST_FUN_OBJ(mp_stream_tell_obj);
61+
MP_DECLARE_CONST_FUN_OBJ(mp_stream_flush_obj);
6162
MP_DECLARE_CONST_FUN_OBJ(mp_stream_ioctl_obj);
6263

6364
// these are for mp_get_stream_raise and can be or'd together

0 commit comments

Comments
 (0)
0