pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:72:   static struct ba_page * ba_alloc_page(struct block_allocator * a, int i) {    struct ba_layout l = ba_get_layout(a, i);    size_t n = l.offset + l.block_size + l.doffset;    struct ba_page * p;       /*    * note that i is always positive, so this only    * happens if ba_get_layout overflows    */    if (a->l.offset > l.offset || n < l.offset) { -  Pike_error("Overflow.\n"); +  Pike_error(msg_out_of_mem_2, a->l.offset);    }       if (l.alignment) {    p = xalloc_aligned(n, l.alignment);    } else {   #ifdef DEBUG_MALLOC    /* In debug malloc mode, calling xalloc from the block alloc may result    * in a deadlock, since xalloc will call ba_alloc, which in turn may call xalloc.    */    p = system_malloc(n);
pike.git/src/block_allocator.c:122:    a->alloc = a->last_free = MAXIMUM(0, i);    }   }      static void ba_low_init_aligned(struct block_allocator * a) {    unsigned INT32 block_size = MAXIMUM(a->l.block_size, sizeof(struct ba_block_header));       PIKE_MEMPOOL_CREATE(a);       if (a->l.alignment) { + #if PIKE_DEBUG    if (a->l.alignment & (a->l.alignment - 1))    Pike_fatal("Block allocator a->l.alignment is not a power of 2.\n");    if (block_size & (a->l.alignment-1))    Pike_fatal("Block allocator block size is not aligned.\n"); -  + #endif    a->l.doffset = PIKE_ALIGNTO(sizeof(struct ba_page), a->l.alignment);    } else {    a->l.doffset = sizeof(struct ba_page);    }       if (a->l.blocks & (a->l.blocks - 1)) {    unsigned INT32 tmp = round_up32(a->l.blocks);    if (tmp) a->l.blocks = tmp;    } else if (!a->l.blocks) a->l.blocks = 1;    a->l.block_size = block_size;
pike.git/src/block_allocator.c:226:    for (i = a->size - 1; i >= 0; i--) {    struct ba_page * p = a->pages[i];       if (p->h.first) {    a->alloc = i;    return;    }    }       if (a->size == (sizeof(a->pages)/sizeof(a->pages[0]))) { -  Pike_error("Out of memory.\n"); +  Pike_error(msg_out_of_mem_2, a->l.offset);    }    a->pages[a->size] = ba_alloc_page(a, a->size);    a->alloc = a->size;    a->size++;   }      ATTRIBUTE((malloc))   PMOD_EXPORT void * ba_alloc(struct block_allocator * a) {    struct ba_page * p = a->pages[a->alloc];    struct ba_block_header * ptr;
pike.git/src/block_allocator.c:328:    if (i+1 == a->size) {    ba_free_empty_pages(a);    } else {    ba_clear_page(a, p, &l);    }    }    } else {   #ifdef PIKE_DEBUG    print_allocator(a);   #endif -  Pike_fatal("ptr %p not in any page.\n", ptr); +  Pike_error("Trying to free unknown block %p.\n", ptr);    }    PIKE_MEMPOOL_FREE(a, ptr, a->l.block_size);   }      #ifdef PIKE_DEBUG   static void print_allocator(const struct block_allocator * a) {    int i;    struct ba_layout l;       for (i = a->size-1, l = ba_get_layout(a, i); i >= 0; ba_half_layout(&l), i--) {