# HG changeset patch # User Timo Sirainen # Date 1034196547 -10800 # Node ID e90b95f6d962563376ac39abf626fb7600511b6c # Parent ec0b16ee7ef9719020c723261a8003ea2fadbd52 s/t_try_grow/t_try_realloc/ diff -r ec0b16ee7ef9 -r e90b95f6d962 src/lib/data-stack.c --- a/src/lib/data-stack.c Wed Oct 09 21:08:26 2002 +0300 +++ b/src/lib/data-stack.c Wed Oct 09 23:49:07 2002 +0300 @@ -202,7 +202,7 @@ always properly */ size = MEM_ALIGN(size); - /* used for t_try_grow() */ + /* used for t_try_realloc() */ current_frame_block->last_alloc_size[frame_pos] = size; if (current_block->left >= size) { @@ -247,7 +247,7 @@ return mem; } -int t_try_grow(void *mem, size_t size) +int t_try_realloc(void *mem, size_t size) { size_t last_alloc_size; @@ -367,8 +367,8 @@ frame = malloc(sizeof(StackFrame)); frame->allocs = NULL; - frame->next = current_frame_block; - current_frame_block = frame; + frame->next = current_frame; + current_frame = frame; return stack_counter++; } @@ -377,8 +377,8 @@ StackFrame *frame; FrameAlloc *alloc; - frame = current_frame_block; - current_frame_block = frame->next; + frame = current_frame; + current_frame = frame->next; while (frame->allocs != NULL) { alloc = frame->allocs; @@ -425,7 +425,7 @@ return mem; } -int t_try_grow(void *mem, size_t size) +int t_try_realloc(void *mem, size_t size) { void *new_mem; @@ -457,7 +457,7 @@ i_assert(buffer_mem != NULL); - mem = buffer_mem; + mem = realloc(buffer_mem, size); buffer_mem = NULL; add_alloc(mem); @@ -466,7 +466,7 @@ void data_stack_init(void) { stack_counter = 0; - current_frame_block = NULL; + current_frame = NULL; buffer_mem = NULL; t_push(); diff -r ec0b16ee7ef9 -r e90b95f6d962 src/lib/data-stack.h --- a/src/lib/data-stack.h Wed Oct 09 21:08:26 2002 +0300 +++ b/src/lib/data-stack.h Wed Oct 09 23:49:07 2002 +0300 @@ -49,13 +49,16 @@ You probably should never use this function directly, rather create functions that return 'const xxx*' types and use t_malloc() internally in them. This is a lot safer, since usually compiler - warns if you try to place them in xxx*. See strfuncs.c for examples. */ + warns if you try to place them in xxx*. See strfuncs.c for examples. + + t_malloc() calls never fail, but return NULL if size == 0. If there's + not enough memory left, i_panic() will be called. */ void *t_malloc(size_t size); void *t_malloc0(size_t size); /* Try growing allocated memory. Returns TRUE if successful. Works only for last allocated memory in current stack frame. */ -int t_try_grow(void *mem, size_t size); +int t_try_realloc(void *mem, size_t size); #define t_new(type, count) \ ((type *) t_malloc0(sizeof(type) * (count))) diff -r ec0b16ee7ef9 -r e90b95f6d962 src/lib/mempool.h --- a/src/lib/mempool.h Wed Oct 09 21:08:26 2002 +0300 +++ b/src/lib/mempool.h Wed Oct 09 23:49:07 2002 +0300 @@ -31,6 +31,9 @@ /* system_pool uses calloc() + realloc() + free() */ extern Pool system_pool; +/* memory allocated from data_stack is valid only until next t_pop() call. */ +extern Pool data_stack_pool; + /* If allocfree is FALSE, p_free() has no effect. Note that `size' specifies the initial malloc()ed block size, part of it is used internally. */ Pool pool_create(const char *name, size_t size, int allocfree); diff -r ec0b16ee7ef9 -r e90b95f6d962 src/lib/temp-string.c --- a/src/lib/temp-string.c Wed Oct 09 21:08:26 2002 +0300 +++ b/src/lib/temp-string.c Wed Oct 09 23:49:07 2002 +0300 @@ -64,7 +64,7 @@ if (size > rstr->alloc_size) { rstr->alloc_size = nearest_power(size); - if (!t_try_grow(rstr->str, rstr->alloc_size)) { + if (!t_try_realloc(rstr->str, rstr->alloc_size)) { str = t_malloc(rstr->alloc_size); memcpy(str, rstr->str, rstr->len+1); rstr->str = str;