extmod/uos_dupterm: Use native C stream methods on dupterm object.

This patch changes dupterm to call the native C stream methods on the
connected stream objects, instead of calling the Python readinto/write
methods.  This is much more efficient for native stream objects like UART
and webrepl and doesn't require allocating a special dupterm array.

This change is a minor breaking change from the user's perspective because
dupterm no longer accepts pure user stream objects to duplicate on.  But
with the recent addition of uio.IOBase it is possible to still create such
classes just by inheriting from uio.IOBase, for example:

    import uio, uos

    class MyStream(uio.IOBase):
        def write(self, buf):
            # existing write implementation
        def readinto(self, buf):
            # existing readinto implementation

    uos.dupterm(MyStream())
This commit is contained in:
Damien George
2018-06-12 15:06:11 +10:00
parent 5042d98514
commit 035906419d
3 changed files with 16 additions and 28 deletions

View File

@@ -171,7 +171,6 @@ typedef struct _mp_state_vm_t {
#if MICROPY_PY_OS_DUPTERM
mp_obj_t dupterm_objs[MICROPY_PY_OS_DUPTERM];
mp_obj_t dupterm_arr_obj;
#endif
#if MICROPY_PY_LWIP_SLIP