py/stream: Add mp_stream_close() helper function.
This commit is contained in:
parent
f9dc644017
commit
497660fcda
@ -31,6 +31,7 @@
|
||||
#include "py/nlr.h"
|
||||
#include "py/objstr.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#if MICROPY_STREAMS_NON_BLOCK
|
||||
#include <errno.h>
|
||||
@ -104,6 +105,13 @@ const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) {
|
||||
return stream_p;
|
||||
}
|
||||
|
||||
mp_obj_t mp_stream_close(mp_obj_t stream) {
|
||||
// TODO: Still consider using ioctl for close
|
||||
mp_obj_t dest[2];
|
||||
mp_load_method(stream, MP_QSTR_close, dest);
|
||||
return mp_call_method_n_kw(0, 0, dest);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte flags) {
|
||||
const mp_stream_p_t *stream_p = mp_get_stream_raise(args[0], MP_STREAM_OP_READ);
|
||||
|
||||
|
@ -65,6 +65,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_stream_ioctl_obj);
|
||||
#define MP_STREAM_OP_IOCTL (4)
|
||||
|
||||
const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags);
|
||||
mp_obj_t mp_stream_close(mp_obj_t stream);
|
||||
|
||||
// Iterator which uses mp_stream_unbuffered_readline_obj
|
||||
mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self);
|
||||
|
Loading…
Reference in New Issue
Block a user