summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-01-23 13:42:33 -0800
committerJoshua Haberman <jhaberman@gmail.com>2019-01-23 13:42:33 -0800
commitf4532ab273173d96605ff22a7e47387023651625 (patch)
tree1e33d8c7e74250503b5cfaa86e097e2803222309 /upb
parent315c167bedbe33386e0bffd537d1f28eb259c986 (diff)
Properly align the arena.
Diffstat (limited to 'upb')
-rw-r--r--upb/msg.c2
-rw-r--r--upb/upb.c8
2 files changed, 8 insertions, 2 deletions
diff --git a/upb/msg.c b/upb/msg.c
index 20401f9..b46d41c 100644
--- a/upb/msg.c
+++ b/upb/msg.c
@@ -17,8 +17,6 @@ bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) {
/** upb_msgval ****************************************************************/
-#define upb_alignof(t) offsetof(struct { char c; t x; }, x)
-
/* These functions will generate real memcpy() calls on ARM sadly, because
* the compiler assumes they might not be aligned. */
diff --git a/upb/upb.c b/upb/upb.c
index 9f80639..0cf5b50 100644
--- a/upb/upb.c
+++ b/upb/upb.c
@@ -177,11 +177,17 @@ static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize,
/* Public Arena API ***********************************************************/
+#define upb_alignof(type) offsetof (struct { char c; type member; }, member)
+
upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc) {
const size_t first_block_overhead = sizeof(upb_arena) + sizeof(mem_block);
upb_arena *a;
bool owned = false;
+ /* Round block size down to alignof(*a) since we will allocate the arena
+ * itself at the end. */
+ n &= ~(upb_alignof(upb_arena) - 1);
+
if (n < first_block_overhead) {
/* We need to malloc the initial block. */
n = first_block_overhead + 256;
@@ -208,6 +214,8 @@ upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc) {
return a;
}
+#undef upb_alignof
+
void upb_arena_free(upb_arena *a) {
cleanup_ent *ent = a->cleanup_head;
mem_block *block = a->block_head;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback