/* statistical data */
unsigned long e_created; /* extents created */
unsigned long e_freed; /* extents detroyed */
- uint64 n_allocated; /* calls to alloc */
- uint64 n_freed; /* calls to free */
- uint64 b_allocated; /* cum. bytes allocated */
- uint64 b_freed; /* cum. bytes freed */
+ int64 n_allocated; /* calls to alloc */
+ int64 n_freed; /* calls to free */
+ int64 b_allocated; /* cum. bytes allocated */
+ int64 b_freed; /* cum. bytes freed */
};
struct pool_extent
struct pool_extent *next;
};
-#define MINALIGN (sizeof (void *))
+struct align_test {
+ void *foo;
+ int64 bar;
+};
+
+#define MINALIGN offsetof(struct align_test, bar)
+
+/* Temporarily cast a void* var into a char* var when adding an offset (to
+ * keep some compilers from complaining about the pointer arithmetic). */
+#define PTR_ADD(b,o) ( (void*) ((char*)(b) + (o)) )
alloc_pool_t
pool_create(size_t size, size_t quantum,
{
struct alloc_pool *pool = (struct alloc_pool *) p;
if (!pool)
- {
- char *msg;
- if (asprintf(&msg, "pool_alloc(%s) on NULL pool", bomb) > 0)
- bomb = msg;
- goto bomb;
- }
+ return NULL;
if (!len)
len = pool->quantum;
if (pool->flags & POOL_APPEND)
{
- pool->live = start + free;
+ pool->live = PTR_ADD(start, free);
}
else if (!(pool->live = (struct pool_extent *) malloc(sizeof (struct pool_extent))))
{
goto bomb;
}
if (pool->flags & POOL_QALIGN && pool->quantum > 1
- && (sqew = (size_t)(start + free) % pool->quantum))
+ && (sqew = (size_t)PTR_ADD(start, free) % pool->quantum))
{
bound += sqew;
free -= sqew;
pool->live->free -= len;
- return pool->live->start + pool->live->free;
+ return PTR_ADD(pool->live->start, pool->live->free);
bomb:
if (pool->bomb)
cur = pool->live;
if (cur
&& addr >= cur->start
- && addr < cur->start + pool->size)
+ && addr < PTR_ADD(cur->start, pool->size))
{
- if (addr == cur->start + cur->free)
+ if (addr == PTR_ADD(cur->start, cur->free))
{
if (pool->flags & POOL_CLEAR)
memset(addr, 0, len);
cur->free = pool->size;
cur->bound = 0;
if (pool->flags & POOL_QALIGN && pool->quantum > 1
- && (sqew = (size_t)(cur->start + cur->free) % pool->quantum))
+ && (sqew = (size_t)PTR_ADD(cur->start, cur->free) % pool->quantum))
{
cur->bound += sqew;
cur->free -= sqew;
for (prev = NULL, cur = pool->free; cur; prev = cur, cur = cur->next)
{
if (addr >= cur->start
- && addr < cur->start + pool->size)
+ && addr < PTR_ADD(cur->start, pool->size))
break;
}
if (!cur)