summaryrefslogtreecommitdiffstats
path: root/Python/pyarena.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-04-13 19:16:13 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-04-13 19:16:13 (GMT)
commitda690411234dbd0438b7b1090750c547c92c5194 (patch)
tree0515f64aa73f7a14ff43a93f7e7c7fdc1184f649 /Python/pyarena.c
parentf33dea29619d755db9608265a28fabea9690145a (diff)
downloadcpython-da690411234dbd0438b7b1090750c547c92c5194.zip
cpython-da690411234dbd0438b7b1090750c547c92c5194.tar.gz
cpython-da690411234dbd0438b7b1090750c547c92c5194.tar.bz2
Force 8-alignment of memory blocks, as needed on
64-bit machines that require pointers to be aligned (e.g. IA64)
Diffstat (limited to 'Python/pyarena.c')
-rw-r--r--Python/pyarena.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/pyarena.c b/Python/pyarena.c
index f27de86..c5491e9 100644
--- a/Python/pyarena.c
+++ b/Python/pyarena.c
@@ -12,6 +12,11 @@
*/
#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
@@ -82,7 +87,8 @@ block_new(size_t size)
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;
}
@@ -100,6 +106,7 @@ block_alloc(block *b, size_t size)
{
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