Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Created October 8, 2016 16:18
Show Gist options
  • Save FROGGS/9421a660bd7ce4473ad9faae34e76440 to your computer and use it in GitHub Desktop.
Save FROGGS/9421a660bd7ce4473ad9faae34e76440 to your computer and use it in GitHub Desktop.
diff --git a/src/6model/reprs/CStruct.c b/src/6model/reprs/CStruct.c
index 065975d..3b11663 100644
--- a/src/6model/reprs/CStruct.c
+++ b/src/6model/reprs/CStruct.c
@@ -1,6 +1,14 @@
#include "moar.h"
#include <math.h>
+#ifndef MIN
+ #define MIN(x,y) ((x)<(y)?(x):(y))
+#endif
+
+#ifndef MAX
+ #define MAX(x,y) ((x)>(y)?(x):(y))
+#endif
+
/* This representation's function pointer table. */
static const MVMREPROps this_repr;
@@ -266,14 +274,12 @@ static void compute_allocation_strategy(MVMThreadContext *tc, MVMObject *repr_in
repr_data->struct_offsets[i] = cur_size;
cur_size += bits / 8;
- if (align > multiple_of)
- multiple_of = align;
+ if (MIN(MAX(align, bits/8), 8) > multiple_of)
+ multiple_of = MIN(MAX(align, bits/8), 8);
}
/* Finally, put computed allocation size in place; it's body size plus
* header size. Also number of markables and sentinels. */
- if (multiple_of > sizeof(void *))
- multiple_of = sizeof(void *);
repr_data->struct_size = ceil((double)cur_size / (double)multiple_of) * multiple_of;
if (repr_data->initialize_slots)
repr_data->initialize_slots[cur_init_slot] = -1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment