pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:56:   #include <stdio.h>   #include <unistd.h>      void Pike_error(char * msg) {    fprintf(stderr, "ERROR: %s\n", msg);    _exit(1);   }   #endif      static inline void ba_realloc(struct block_allocator * a) { -  int i; +  unsigned int i;    a->pages = realloc(a->pages, BA_BYTES(a));       if (!a->pages) {    Pike_error("no mem");    }       //fprintf(stderr, "realloc to size %u\n", a->allocated);      #ifndef BA_SEGREGATE    memset((void*)BA_PAGE(a, a->num_pages+1), 0, BA_BYTES(a) - a->ba_page_size*a->num_pages);
pike.git/src/block_allocator.c:78:    memset((void*)BA_PAGE(a, a->num_pages+1), 0, BA_BYTES(a) - sizeof(struct ba_page)*a->num_pages);   #endif    a->htable = (uint16_t*) BA_PAGE(a, (a->allocated)+1);    for (i = 0; i < a->num_pages; i++) {    ba_htable_insert(a, BA_LASTBLOCK(a, BA_PAGE(a, i+1)), i+1);    }   }      void ba_init(struct block_allocator * a,    uint32_t block_size, uint32_t blocks) { -  uint32_t page_size = a->block_size * a->blocks; +  uint32_t page_size = block_size * blocks;       if (blocks > 0xfffe) {    Pike_error("number of blocks cannot exceed 2^16-1\n");    }       a->first = a->last = 0;    a->last_free = 0;       if ((page_size & (page_size - 1)) == 0)    a->magnitude = (uint16_t)ctz32(page_size);
pike.git/src/block_allocator.c:107:    // we start with management structures for 16 pages    a->allocated = 16;    a->pages = NULL;   #ifndef BA_SEGREGATE    a->ba_page_size = BA_SPAGE_SIZE(a);   #endif    ba_realloc(a);   }      void ba_free_all(struct block_allocator * a) { -  int i; +  unsigned int i;       for (i = 0; i < a->num_pages; i++) { -  free(BA_PAGE(a, i)->data); +  free(BA_PAGE(a, i+1)->data);    }    a->num_pages = 0;    a->first = a->last = 0;   }      void ba_count_all(struct block_allocator * a, size_t *num, size_t *size) { -  int i; +  unsigned int i;    size_t n = 0;       *size = BA_BYTES(a) + a->num_pages * BA_PAGESIZE(a);    for (i = 0; i < a->num_pages; i++) { -  n += BA_PAGE(a, i)->blocks_used; +  n += BA_PAGE(a, i+1)->blocks_used;    }       *num = n;   }      void ba_destroy(struct block_allocator * a) {    ba_free_all(a);    free(a->pages);    a->pages = NULL;   }
pike.git/src/block_allocator.c:472:    p->first = t+1;   #endif   }      static inline void ba_remove_page(struct block_allocator * a,    uint16_t n) {    ba_page tmp, p;       p = BA_PAGE(a, n);    +  /*    fprintf(stderr, "removing page %4u\t(%p .. %p) -> %X (%X) (of %u).\n", n,    p->data, BA_LASTBLOCK(a, p), hash1(a, BA_LASTBLOCK(a,p)),    hash1(a, BA_LASTBLOCK(a,p)) & BA_HASH_MASK(a),    a->num_pages); -  +  */       ba_htable_delete(a, BA_LASTBLOCK(a, p), n);       free(p->data);    p->data = NULL;       if (a->num_pages != n) {    tmp = BA_PAGE(a, a->num_pages);    ba_htable_replace(a, BA_LASTBLOCK(a, tmp), a->num_pages, n); -  +  /*    fprintf(stderr, "replacing with page %u\t(%p .. %p) -> %X (%X)\n",    a->num_pages,    tmp->data, BA_LASTBLOCK(a, tmp), hash1(a, BA_LASTBLOCK(a,tmp)),    hash1(a, BA_LASTBLOCK(a,tmp)) & BA_HASH_MASK(a)    ); -  +  */    *p = *tmp;    }       if (a->last_free == n)    a->last_free = 0;    else if (a->last_free == a->num_pages)    a->last_free = n;       if (p->prev) {    tmp = BA_PAGE(a, p->prev);