Skip to content

Commit 2c81b9b

Browse files
committed
py/modio: io.BufferedWriter: Describe flushing policy.
1 parent 063e6e7 commit 2c81b9b

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

py/modio.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ STATIC mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t si
6969
return org_size;
7070
}
7171

72+
// Buffer flushing policy here is to flush entire buffer all the time.
73+
// This allows e.g. to have a block device as backing storage and write
74+
// entire block to it. memcpy below is not ideal and could be optimized
75+
// in some cases. But the way it is now it at least ensures that buffer
76+
// is word-aligned, to guard against obscure cases when it matters, e.g.
77+
// https://github.com/micropython/micropython/issues/1863
7278
memcpy(self->buf + self->len, buf, rem);
7379
buf = (byte*)buf + rem;
7480
size -= rem;

0 commit comments

Comments
 (0)