]> granicus.if.org Git - php/commitdiff
- MFH: Allow persistent zent_ptr_stacks (patch by Andrey Hristov)
authorJohannes Schlüter <johannes@php.net>
Fri, 9 Nov 2007 10:34:27 +0000 (10:34 +0000)
committerJohannes Schlüter <johannes@php.net>
Fri, 9 Nov 2007 10:34:27 +0000 (10:34 +0000)
Zend/zend_ptr_stack.c
Zend/zend_ptr_stack.h

index 36cb21c58be625746b6fccf7c4e637e97b8d0f44..d2bbbe0e6978c349a57fd842581a110c5608e3e8 100644 (file)
 # include <stdarg.h>
 #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;
+       stack->persistent = persistent;
+}
+
+ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
+{
+       zend_ptr_stack_init_ex(stack, 0);
 }
 
 
@@ -71,7 +77,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);
        }
 }
 
@@ -93,7 +99,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;
index ff308119a722ccafd718a00800799168fc66441e..187e03dd0544f092ee4dcad32dc43b2f325cb945 100644 (file)
@@ -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;        \
        }