opstack cleanup.

This commit is contained in:
Enno Rehling 2005-06-12 02:59:23 +00:00
parent b2404889d8
commit ddac39dcfa
1 changed files with 11 additions and 5 deletions

View File

@ -35,6 +35,7 @@ variant
opstack_pop(opstack ** stackp)
{
opstack * stack = *stackp;
assert(stack);
assert(stack->top>stack->begin);
return *(--stack->top);
@ -46,13 +47,13 @@ opstack_push(opstack ** stackp, variant data)
opstack * stack = *stackp;
if (stack==NULL) {
stack = (opstack*)malloc(sizeof(opstack));
stack->size = 4;
stack->size = 1;
stack->begin = malloc(sizeof(variant) * stack->size);
stack->top = stack->begin;
*stackp = stack;
}
if (stack->top - stack->begin == stack->size) {
int pos = stack->top - stack->begin;
size_t pos = stack->top - stack->begin;
stack->size += stack->size;
stack->begin = realloc(stack->begin, sizeof(variant) * stack->size);
stack->top = stack->begin + pos;
@ -352,6 +353,8 @@ translate(const char* format, const void * userdata, const char* vars, variant a
char symbol[32];
char *oc = symbol;
opstack * stack = NULL;
const char * rv;
brelease();
free_variables();
@ -369,7 +372,10 @@ translate(const char* format, const void * userdata, const char* vars, variant a
}
if (parse(&stack, format, userdata)==NULL) return NULL;
return (const char*)opop(&stack).v;
rv = (const char*)opop(&stack).v;
free(stack->begin);
free(stack);
return rv;
}
static void