From 6b12d4f726b9578d5c878fa765d5c167c9d71618 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Wed, 25 Jan 2017 14:58:35 -0500 Subject: Minor rewrite of block allocator to improve clarity. --- node.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'node.c') diff --git a/node.c b/node.c index 97f65fa3..f1f80177 100644 --- a/node.c +++ b/node.c @@ -1001,32 +1001,33 @@ void init_btowc_cache() #define BLOCKCHUNK 100 -BLOCK nextfree[BLOCK_MAX] = { - { 0, NULL}, /* invalid */ - { sizeof(NODE), NULL }, - { sizeof(BUCKET), NULL }, +struct block_header nextfree[BLOCK_MAX] = { + { NULL, 0}, /* invalid */ + { NULL, sizeof(NODE) }, + { NULL, sizeof(BUCKET) }, }; /* more_blocks --- get more blocks of memory and add to the free list; - size of a block must be >= sizeof(BLOCK) + size of a block must be >= sizeof(struct block_item) */ void * more_blocks(int id) { - BLOCK *freep, *np, *next; + struct block_item *freep, *np, *next; char *p, *endp; size_t size; size = nextfree[id].size; - emalloc(freep, BLOCK *, BLOCKCHUNK * size, "more_blocks"); + assert(size >= sizeof(struct block_item)); + emalloc(freep, struct block_item *, BLOCKCHUNK * size, "more_blocks"); p = (char *) freep; endp = p + BLOCKCHUNK * size; for (np = freep; ; np = next) { - next = (BLOCK *) (p += size); + next = (struct block_item *) (p += size); if (p >= endp) { np->freep = NULL; break; -- cgit v1.2.3