Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 111 lines (90 sloc) 2.992 kb
573b460 andigutmans Zend Library
andigutmans authored
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
d2c9e80 andigutmans - Update copyright year
andigutmans authored
5 | Copyright (c) 1998-2001 Zend Technologies Ltd. (http://www.zend.com) |
573b460 andigutmans Zend Library
andigutmans authored
6 +----------------------------------------------------------------------+
5e55e47 Zeev Suraski It's official now...
zsuraski authored
7 | This source file is subject to version 0.92 of the Zend license, |
b5b1117 Zeev Suraski License update
zsuraski authored
8 | that is bundled with this package in the file LICENSE, and is |
9 | available at through the world-wide-web at |
5e55e47 Zeev Suraski It's official now...
zsuraski authored
10 | http://www.zend.com/license/0_92.txt. |
b5b1117 Zeev Suraski License update
zsuraski authored
11 | If you did not receive a copy of the Zend license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@zend.com so we can mail you a copy immediately. |
573b460 andigutmans Zend Library
andigutmans authored
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 +----------------------------------------------------------------------+
18 */
19
b5b1117 Zeev Suraski License update
zsuraski authored
20
573b460 andigutmans Zend Library
andigutmans authored
21 #include "zend.h"
22 #include "zend_ptr_stack.h"
009025e * header file cleanup
Stig S. Bakken authored
23 #ifdef HAVE_STDARG_H
24 # include <stdarg.h>
e9e7bc6 andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
25 #endif
573b460 andigutmans Zend Library
andigutmans authored
26
27 ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
28 {
e9e7bc6 andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
29 stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE);
30 stack->max = PTR_STACK_BLOCK_SIZE;
573b460 andigutmans Zend Library
andigutmans authored
31 stack->top = 0;
32 }
33
34
7f27821 Zeev Suraski inline functions cannot accept varargs
zsuraski authored
35 ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count, ...)
e9e7bc6 andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
36 {
37 va_list ptr;
38 void *elem;
39
40 if (stack->top+count > stack->max) { /* we need to allocate more memory */
41 stack->max *= 2;
42 stack->max += count;
43 stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max)));
44 stack->top_element = stack->elements+stack->top;
45 }
46 va_start(ptr, count);
47 while (count>0) {
48 elem = va_arg(ptr, void *);
49 stack->top++;
50 *(stack->top_element++) = elem;
51 count--;
52 }
53 va_end(ptr);
54 }
55
56
7f27821 Zeev Suraski inline functions cannot accept varargs
zsuraski authored
57 ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count, ...)
e9e7bc6 andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
58 {
59 va_list ptr;
60 void **elem;
61
62 va_start(ptr, count);
63 while (count>0) {
64 elem = va_arg(ptr, void **);
447eb3b andigutmans - Damn that's more like it.
andigutmans authored
65 *elem = *(--stack->top_element);
e9e7bc6 andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
66 stack->top--;
67 count--;
68 }
69 va_end(ptr);
70 }
573b460 andigutmans Zend Library
andigutmans authored
71
72
73
74 ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack)
75 {
76 if (stack->elements) {
77 efree(stack->elements);
78 }
79 }
80
81
82 ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *))
83 {
84 int i = stack->top;
85
86 while (--i >= 0) {
87 func(stack->elements[i]);
88 }
89 }
90
91
34c2b0a Zeev Suraski - Add restore_error_handler()
zsuraski authored
92 ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *), zend_bool free_elements)
573b460 andigutmans Zend Library
andigutmans authored
93 {
94 zend_ptr_stack_apply(stack, func);
34c2b0a Zeev Suraski - Add restore_error_handler()
zsuraski authored
95 if (free_elements) {
96 int i = stack->top;
97
98 while (--i >= 0) {
99 efree(stack->elements[i]);
100 }
101 }
573b460 andigutmans Zend Library
andigutmans authored
102 stack->top = 0;
3fcc651 andigutmans * Optimize argument_stack top lookup
andigutmans authored
103 stack->top_element = stack->elements;
573b460 andigutmans Zend Library
andigutmans authored
104 }
39a7f4c Zeev Suraski This patch is a go. Not fully optimized yet, but working properly.
zsuraski authored
105
106
34c2b0a Zeev Suraski - Add restore_error_handler()
zsuraski authored
107 ZEND_API int zend_ptr_stack_num_elements(zend_ptr_stack *stack)
108 {
109 return stack->top;
110 }
Something went wrong with that request. Please try again.