# 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);
}
ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack)
{
if (stack->elements) {
- efree(stack->elements);
+ pefree(stack->elements, stack->persistent);
}
}
int i = stack->top;
while (--i >= 0) {
- efree(stack->elements[i]);
+ pefree(stack->elements[i], stack->persistent);
}
}
stack->top = 0;
int top, max;
void **elements;
void **top_element;
+ zend_bool persistent;
} 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);
/* 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; \
}