mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 03:30:14 +01:00
py/stream: Add mp_stream_close() helper function.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user