Browse Source

Align new allocations on __BIGGEST_ALIGNMENT__ instead of __SIZEOF_POINTER__ which is not reliable

Caleb James DeLisle 5 years ago
parent
commit
436d59060d
2 changed files with 10 additions and 2 deletions
  1. 9 0
      memory/Allocator_pvt.h
  2. 1 2
      memory/BufferAllocator.c

+ 9 - 0
memory/Allocator_pvt.h

@@ -17,6 +17,7 @@
 
 #include "memory/Allocator.h"
 #include "util/Identity.h"
+#include "util/Assert.h"
 
 #include <stdint.h>
 
@@ -43,9 +44,17 @@ struct Allocator_Allocation_pvt {
     struct Allocator_Allocation pub;
     struct Allocator_Allocation_pvt* next;
 #ifdef Allocator_USE_CANARIES
+    #if __SIZEOF_POINTER__ == 4
+        char* _pad0;
+        char* _pad1;
+    #elif __SIZEOF_POINTER__ == 8
+        char* _pad;
+    #endif
     unsigned long beginCanary;
 #endif
 };
+Assert_compileTime(!(sizeof(struct Allocator_Allocation_pvt) % __BIGGEST_ALIGNMENT__));
+
 
 /** Singly linked list of allocators. */
 struct Allocator_List;

+ 1 - 2
memory/BufferAllocator.c

@@ -27,8 +27,7 @@ struct BufferAllocator_pvt;
  *            ancestors is freed, not just the root.
  */
 
-/* Define alignment as the size of a pointer which is usually 4 or 8 bytes. */
-#define ALIGNMENT sizeof(char*)
+#define ALIGNMENT __BIGGEST_ALIGNMENT__
 
 /** Internal state for Allocator. */
 struct BufferAllocator_pvt