From 1355cf42f23a39d3b887d2771d8bc7f3669d211c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 19 Apr 2014 01:25:49 +0300 Subject: modstruct: Fix .calcsize() to account for struct type/alignment. --- py/modstruct.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'py/modstruct.c') diff --git a/py/modstruct.c b/py/modstruct.c index cd2516b24..0be194fee 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -37,12 +37,14 @@ STATIC uint calcsize_items(const char *fmt) { STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) { const char *fmt = mp_obj_str_get_str(fmt_in); char fmt_type = get_fmt_type(&fmt); - (void)fmt_type; machine_uint_t size; for (size = 0; *fmt; fmt++) { - int sz = mp_binary_get_size(*fmt); + uint align; + int sz = mp_binary_get_size(fmt_type, *fmt, &align); // TODO assert(sz != -1); + // Apply alignment + size = (size + align - 1) & ~(align - 1); size += sz; } return MP_OBJ_NEW_SMALL_INT(size); -- cgit v1.2.3