Browse Source

Deal with machines where __BIGGEST_ALIGMENT__ is bigger than sizeof(struct Allocator_Allocation_pvt)

Caleb James DeLisle 5 years ago
parent
commit
40d53a658b
2 changed files with 15 additions and 2 deletions
  1. 1 0
      memory/Allocator.h
  2. 14 2
      memory/Allocator_pvt.h

+ 1 - 0
memory/Allocator.h

@@ -112,6 +112,7 @@ struct Allocator_Allocation
 {
     unsigned long size;
 };
+#define Allocator_Allocation_SIZE __SIZEOF_LONG__
 
 /**
  * Get a child of a given allocator.

+ 14 - 2
memory/Allocator_pvt.h

@@ -40,14 +40,26 @@ struct Allocator_OnFreeJob_pvt {
 };
 
 struct Allocator_Allocation_pvt;
+#define Allocator_Allocation_pvt_SIZE_NOPAD ( \
+    Allocator_Allocation_SIZE + \
+    __SIZEOF_POINTER__ + \
+    __SIZEOF_LONG__ + \
+    __SIZEOF_POINTER__ \
+)
 struct Allocator_Allocation_pvt {
     struct Allocator_Allocation pub;
     struct Allocator_Allocation_pvt* next;
+    #if Allocator_Allocation_pvt_SIZE_NOPAD < __BIGGEST_ALIGNMENT__
+        uint8_t _pad[__BIGGEST_ALIGNMENT__ - Allocator_Allocation_pvt_SIZE_NOPAD];
+        #define Allocator_Allocation_pvt_SIZE __BIGGEST_ALIGNMENT__
+    #else
+        #define Allocator_Allocation_pvt_SIZE Allocator_Allocation_pvt_SIZE_NOPAD
+    #endif
     long lineNum;
     const char* fileName;
 };
-Assert_compileTime(!(sizeof(struct Allocator_Allocation_pvt) % __BIGGEST_ALIGNMENT__));
-
+Assert_compileTime(sizeof(struct Allocator_Allocation_pvt) == Allocator_Allocation_pvt_SIZE);
+Assert_compileTime(!(Allocator_Allocation_pvt_SIZE % __BIGGEST_ALIGNMENT__));
 
 /** Singly linked list of allocators. */
 struct Allocator_List;