Changeset 28 for trunk

Show
Ignore:
Timestamp:
06/10/06 22:27:11 (3 years ago)
Author:
scott
Message:

Tiny bug fix

  • When apool_expand was called on a pool that currently contains items it overwrites the existing items in the stack.
Location:
trunk/libapool
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/libapool/apool.c

    r27 r28  
    22#include <stdio.h> 
    33#include "apool.h" 
    4  
    5 #define apool_double(pool) apool_expand(pool, pool->blocks) 
    64 
    75void apool_expand (apool *pool, size_t blocks) { 
     
    1816    pool->blocks += blocks; 
    1917    pool->stack = calloc(pool->blocks, sizeof(void *)); 
    20     pool->pos += (int) blocks; 
    2118 
    2219    /* Use the ram in reverse order */ 
    2320    ram += (blocks - 1) * blocksize; 
    24     for (size_t i = 0; i < blocks; ram -= blocksize) { 
     21    for (size_t i = pool->pos; i < pool->pos + blocks; ram -= blocksize) { 
    2522        pool->stack[i++] = ram; 
    2623    } 
     24 
     25    pool->pos += (int) blocks; 
    2726} 
    2827 
     
    6261 
    6362void * apool_alloc (apool *pool) { 
    64     if (pool->pos == 0) { 
    65         apool_double(pool); 
    66     } 
     63    if (apool_empty(pool)) apool_double(pool); 
    6764 
    6865    return pool->stack[--pool->pos]; 
  • trunk/libapool/apool.h

    r27 r28  
    1414} apool; 
    1515 
     16#define apool_double(pool) apool_expand(pool, pool->blocks) 
     17#define apool_empty(pool) pool->pos == 0 
     18 
    1619extern apool * apool_new (size_t blocks, size_t blocksize); 
    1720extern void apool_expand (apool *pool, size_t blocks); 
    18 extern void apool_dobule (apool *pool); 
    1921extern void apool_destroy (apool *pool); 
    2022extern void * apool_alloc (apool *pool); 
    2123extern void apool_free (apool *pool, void * chunk); 
    22  
  • trunk/libapool/test.c

    r26 r28  
    1818    alist_push(list, "baz"); 
    1919 
    20     for (int i = 0; i < 1000; i++) { 
    21         alist_unshift(list, "hahah"); 
    22         printf("%s\n", alist_pop(list)); 
     20    for (int i = 0; i < 100000000; i++) { 
     21        alist_push(list, "hahah"); 
     22        alist_shift(list); 
    2323    } 
    2424