static inline void * alloc_checked() { int pos = rand() % OBJECTS_MAX; if (ptrs[pos]) { assert(ptrs[pos][0] == pos); free_checked(ptrs[pos]); ptrs[pos] = 0; } if (! allocating) return NULL; fail_unless(mempool_used(&pool) == used); used += objsize; ptrs[pos] = mempool_alloc_nothrow(&pool); ptrs[pos][0] = pos; ptrs[pos][objsize/sizeof(int)-1] = pos; return ptrs[pos]; }
static inline void * alloc_checked() { int pos = rand() % OBJECTS_MAX; int size = rand() % OBJSIZE_MAX; if (size < OBJSIZE_MIN || size > OBJSIZE_MAX) size = OBJSIZE_MIN; if (ptrs[pos]) { assert(ptrs[pos][0] == pos); free_checked(ptrs[pos]); } if (! allocating) return NULL; ptrs[pos] = smalloc_nothrow(&alloc, size); ptrs[pos][0] = pos; ptrs[pos][1] = size; ptrs[pos][size/sizeof(int)-1] = pos; // printf("size: %d\n", size); return ptrs[pos]; }