pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:88:   #else    p = xalloc(n);   #endif    }    ba_clear_page(a, p, &a->l);    PIKE_MEM_NA_RANGE((char*)p + l.doffset, n - l.doffset);    return p;   }      static void ba_free_empty_pages(struct block_allocator * a) { -  int i = a->size - 1; +  int i;       for (i = a->size - 1; i >= 0; i--) {    struct ba_page * p = a->pages[i];    if (p->h.used) break;   #ifdef DEBUG_MALLOC    system_free(p);   #else    free(p);   #endif    a->pages[i] = NULL;    }    -  +  if (a->size != i+1) {    a->size = i+1;    a->alloc = a->last_free = MAXIMUM(0, i);    } -  + }      PMOD_EXPORT 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 (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.git/src/block_allocator.c:157:   #endif    a->pages[i] = NULL;    }    }    a->alloc = a->last_free = a->size = 0;    PIKE_MEMPOOL_DESTROY(a);   }      PMOD_EXPORT void ba_free_all(struct block_allocator * a) {    int i; -  struct ba_layout l; +        if (!a->l.offset) return;    if (!a->size) return;    -  l = ba_get_layout(a, 0); -  +     for (i = 0; i < a->size; i++) { -  struct ba_page * page = a->pages[i]; -  ba_clear_page(a, page, &l); -  ba_double_layout(&l); +  free(a->pages[i]); +  a->pages[i] = NULL;    } -  +  a->size = 0;    a->alloc = 0;    a->last_free = 0;   }      PMOD_EXPORT size_t ba_count(const struct block_allocator * a) {    size_t c = 0;    unsigned int i;    for (i = 0; i < a->size; i++) {    c += a->pages[i]->h.used;    }