summaryrefslogtreecommitdiff
path: root/py/stream.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-03-07 17:48:53 +1100
committerDamien George <damien.p.george@gmail.com>2018-04-10 13:41:32 +1000
commitcf31d384f1d2ca09f817f154892eaa6860c10144 (patch)
tree27b6dacefc471a394636e86ac787f6dd29f4a809 /py/stream.h
parent8f11d0b532bd0203c875ad9e3e4efd8a7014ca15 (diff)
py/stream: Switch stream close operation from method to ioctl.
This patch moves the implementation of stream closure from a dedicated method to the ioctl of the stream protocol, for each type that implements closing. The benefits of this are: 1. Rounds out the stream ioctl function, which already includes flush, seek and poll (among other things). 2. Makes calling mp_stream_close() on an object slightly more efficient because it now no longer needs to lookup the close method and call it, rather it just delegates straight to the ioctl function (if it exists). 3. Reduces code size and allows future types that implement the stream protocol to be smaller because they don't need a dedicated close method. Code size reduction is around 200 bytes smaller for x86 archs and around 30 bytes smaller for the bare-metal archs.
Diffstat (limited to 'py/stream.h')
-rw-r--r--py/stream.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/py/stream.h b/py/stream.h
index fbe3d7d85..a7d8d08f1 100644
--- a/py/stream.h
+++ b/py/stream.h
@@ -35,7 +35,7 @@
#define MP_STREAM_FLUSH (1)
#define MP_STREAM_SEEK (2)
#define MP_STREAM_POLL (3)
-//#define MP_STREAM_CLOSE (4) // Not yet implemented
+#define MP_STREAM_CLOSE (4)
#define MP_STREAM_TIMEOUT (5) // Get/set timeout (single op)
#define MP_STREAM_GET_OPTS (6) // Get stream options
#define MP_STREAM_SET_OPTS (7) // Set stream options
@@ -69,6 +69,7 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_unbuffered_readline_obj);
MP_DECLARE_CONST_FUN_OBJ_1(mp_stream_unbuffered_readlines_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_write_obj);
MP_DECLARE_CONST_FUN_OBJ_2(mp_stream_write1_obj);
+MP_DECLARE_CONST_FUN_OBJ_1(mp_stream_close_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_seek_obj);
MP_DECLARE_CONST_FUN_OBJ_1(mp_stream_tell_obj);
MP_DECLARE_CONST_FUN_OBJ_1(mp_stream_flush_obj);