summaryrefslogtreecommitdiff
path: root/py/modstruct.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-19 01:25:49 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-19 03:21:06 +0300
commit1355cf42f23a39d3b887d2771d8bc7f3669d211c (patch)
tree7ece51437958e6b7ab052e834a31e7ea68c3a023 /py/modstruct.c
parent5695e07256413fab8b280a939c264b06f7f5793f (diff)
modstruct: Fix .calcsize() to account for struct type/alignment.
Diffstat (limited to 'py/modstruct.c')
-rw-r--r--py/modstruct.c6
1 files changed, 4 insertions, 2 deletions
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);