From 2c81b9be28dccf973b7c3a7d791ba79ebad6b206 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 25 Mar 2016 14:59:30 +0200 Subject: [PATCH] py/modio: io.BufferedWriter: Describe flushing policy. --- py/modio.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/py/modio.c b/py/modio.c index d41e9592bf..96805d2911 100644 --- a/py/modio.c +++ b/py/modio.c @@ -69,6 +69,12 @@ STATIC mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t si return org_size; } + // Buffer flushing policy here is to flush entire buffer all the time. + // This allows e.g. to have a block device as backing storage and write + // entire block to it. memcpy below is not ideal and could be optimized + // in some cases. But the way it is now it at least ensures that buffer + // is word-aligned, to guard against obscure cases when it matters, e.g. + // https://github.com/micropython/micropython/issues/1863 memcpy(self->buf + self->len, buf, rem); buf = (byte*)buf + rem; size -= rem;