From fd54a5363ce3ec40e04e00c5681b825e384fd5c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Schl=C3=BCter?= Date: Fri, 9 Nov 2007 10:33:51 +0000 Subject: [PATCH] - Allow persistent zent_ptr_stacks (patch by Andrey Hristov) --- Zend/zend_ptr_stack.c | 14 ++++++++++---- Zend/zend_ptr_stack.h | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Zend/zend_ptr_stack.c b/Zend/zend_ptr_stack.c index 6c24096fd4..b03b9fcca8 100644 --- a/Zend/zend_ptr_stack.c +++ b/Zend/zend_ptr_stack.c @@ -25,14 +25,20 @@ # include #endif -ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack) /* {{{ */ +ZEND_API void zend_ptr_stack_init_ex(zend_ptr_stack *stack, zend_bool persistent) /* {{{ */ { - stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE); + stack->top_element = stack->elements = (void **) pemalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE, persistent); stack->max = PTR_STACK_BLOCK_SIZE; stack->top = 0; } /* }}} */ +ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack) /* {{{ */ +{ + zend_ptr_stack_init_ex(stack, 0); +} +/* }}} */ + ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count, ...) /* {{{ */ { va_list ptr; @@ -70,7 +76,7 @@ ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count, ...) /* {{{ ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack) /* {{{ */ { if (stack->elements) { - efree(stack->elements); + pefree(stack->elements, stack->persistent); } } /* }}} */ @@ -92,7 +98,7 @@ ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *), int i = stack->top; while (--i >= 0) { - efree(stack->elements[i]); + pefree(stack->elements[i], stack->persistent); } } stack->top = 0; diff --git a/Zend/zend_ptr_stack.h b/Zend/zend_ptr_stack.h index 452ff635c6..2d3e209ebd 100644 --- a/Zend/zend_ptr_stack.h +++ b/Zend/zend_ptr_stack.h @@ -26,6 +26,7 @@ typedef struct _zend_ptr_stack { int top, max; void **elements; void **top_element; + zend_bool persistent; } zend_ptr_stack; @@ -33,6 +34,7 @@ typedef struct _zend_ptr_stack { BEGIN_EXTERN_C() ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack); +ZEND_API void zend_ptr_stack_init_ex(zend_ptr_stack *stack, zend_bool persistent); ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count, ...); ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count, ...); ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack); @@ -46,7 +48,7 @@ END_EXTERN_C() /* we need to allocate more memory */ \ stack->max *= 2; \ stack->max += count; \ - stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max))); \ + stack->elements = (void **) perealloc(stack->elements, (sizeof(void *) * (stack->max)), stack->persistent); \ stack->top_element = stack->elements+stack->top; \ } -- 2.40.0