*/
#define DEFAULT_BLOCK_SIZE 8192
+#define ALIGNMENT 8
+#define ALIGNMENT_SHIFT 3
+#define ALIGNMENT_MASK (ALIGNMENT - 1)
+#define ROUNDUP(x) (((x) + ALIGNMENT_MASK) & ~ALIGNMENT_MASK)
+
typedef struct _block {
/* Total number of bytes owned by this block available to pass out.
* Read-only after initialization. The first such byte starts at
b->ab_size = size;
b->ab_mem = (void *)(b + 1);
b->ab_next = NULL;
- b->ab_offset = 0;
+ b->ab_offset = ROUNDUP((Py_uintptr_t)(b->ab_mem)) -
+ (Py_uintptr_t)(b->ab_mem);
return b;
}
{
void *p;
assert(b);
+ size = ROUNDUP(size);
if (b->ab_offset + size > b->ab_size) {
/* If we need to allocate more memory than will fit in
the default block, allocate a one-off block that is