diff options
Diffstat (limited to 'upb')
-rw-r--r-- | upb/msg.c | 2 | ||||
-rw-r--r-- | upb/upb.c | 8 |
2 files changed, 8 insertions, 2 deletions
@@ -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. */ @@ -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; |