Hi,
I'd like to use the zend_stack stuff for stacked handlers in the new
apache_hooks sapi stuff, but right now, it emalloc's everything, which
is unacceptable for my usage. I could write my own stack implementation
just for the sapi stuf, but thats seems less productive than making
zend_stack more universally useable.
I've added a persistent attribute to the struct so that it behaves more
like zend_hash, added a zend_stack_init_ex which allows setting of this
flag, and #define'd zend_stack_init to do a non-persistent
zend_stack_init_ex. Patches are attached.
If this is somehow undesireable, please let me know and I will just
reimplement stacks for sapi.
George
Index: Zend/zend_stack.c
===================================================================
RCS file: /repository/Zend/zend_stack.c,v
retrieving revision 1.11
diff -u -3 -r1.11 zend_stack.c
--- Zend/zend_stack.c 6 Jan 2002 15:21:09 -0000 1.11
+++ Zend/zend_stack.c 27 Aug 2002 15:15:37 -0000
@@ -21,10 +21,11 @@
#include "zend.h"
#include "zend_stack.h"
-ZEND_API int zend_stack_init(zend_stack *stack)
+ZEND_API int zend_stack_init_ex(zend_stack *stack, int persistent)
{
stack->top = 0;
- stack->elements = (void **) emalloc(sizeof(void **) * STACK_BLOCK_SIZE);
+ stack->persistent = persistent;
+ stack->elements = (void **) pemalloc(sizeof(void **) * STACK_BLOCK_SIZE,
+persistent);
if (!stack->elements) {
return FAILURE;
} else {
@@ -36,13 +37,13 @@
ZEND_API int zend_stack_push(zend_stack *stack, void *element, int size)
{
if (stack->top >= stack->max) { /* we need to allocate more memory */
- stack->elements = (void **) erealloc(stack->elements,
- (sizeof(void **) * (stack->max +=
STACK_BLOCK_SIZE)));
+ stack->elements = (void **) perealloc(stack->elements,
+ (sizeof(void **) * (stack->max +=
+STACK_BLOCK_SIZE)), stack->persistent);
if (!stack->elements) {
return FAILURE;
}
}
- stack->elements[stack->top] = (void *) emalloc(size);
+ stack->elements[stack->top] = (void *) pemalloc(size, stack->persistent);
memcpy(stack->elements[stack->top], element, size);
return stack->top++;
}
@@ -63,7 +64,7 @@
ZEND_API int zend_stack_del_top(zend_stack *stack)
{
if (stack->top > 0) {
- efree(stack->elements[--stack->top]);
+ pefree(stack->elements[--stack->top], stack->persistent);
}
return SUCCESS;
}
@@ -96,11 +97,11 @@
register int i;
for (i = 0; i < stack->top; i++) {
- efree(stack->elements[i]);
+ pefree(stack->elements[i], stack->persistent);
}
if (stack->elements) {
- efree(stack->elements);
+ pefree(stack->elements, stack->persistent);
}
return SUCCESS;
}
Index: Zend/zend_stack.h
===================================================================
RCS file: /repository/Zend/zend_stack.h,v
retrieving revision 1.13
diff -u -3 -r1.13 zend_stack.h
--- Zend/zend_stack.h 6 Jan 2002 15:21:09 -0000 1.13
+++ Zend/zend_stack.h 27 Aug 2002 15:15:37 -0000
@@ -22,14 +22,14 @@
#define ZEND_STACK_H
typedef struct _zend_stack {
- int top, max;
+ int top, max, persistent;
void **elements;
} zend_stack;
#define STACK_BLOCK_SIZE 64
-
-ZEND_API int zend_stack_init(zend_stack *stack);
+#define zend_stack_init(a) zend_stack_init_ex(a, 0);
+ZEND_API int zend_stack_init_ex(zend_stack *stack, int persistent);
ZEND_API int zend_stack_push(zend_stack *stack, void *element, int size);
ZEND_API int zend_stack_top(zend_stack *stack, void **element);
ZEND_API int zend_stack_del_top(zend_stack *stack);
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php