This source file includes following definitions.
- zend_ptr_stack_3_push
- zend_ptr_stack_2_push
- zend_ptr_stack_3_pop
- zend_ptr_stack_2_pop
- zend_ptr_stack_push
- zend_ptr_stack_pop
- zend_ptr_stack_top
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #ifndef ZEND_PTR_STACK_H
23 #define ZEND_PTR_STACK_H
24
25 typedef struct _zend_ptr_stack {
26 int top, max;
27 void **elements;
28 void **top_element;
29 zend_bool persistent;
30 } zend_ptr_stack;
31
32
33 #define PTR_STACK_BLOCK_SIZE 64
34
35 BEGIN_EXTERN_C()
36 ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack);
37 ZEND_API void zend_ptr_stack_init_ex(zend_ptr_stack *stack, zend_bool persistent);
38 ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count, ...);
39 ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count, ...);
40 ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack);
41 ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *));
42 ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *), zend_bool free_elements);
43 ZEND_API int zend_ptr_stack_num_elements(zend_ptr_stack *stack);
44 END_EXTERN_C()
45
46 #define ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, count) \
47 if (stack->top+count > stack->max) { \
48 \
49 do { \
50 stack->max += PTR_STACK_BLOCK_SIZE; \
51 } while (stack->top+count > stack->max); \
52 stack->elements = (void **) perealloc(stack->elements, (sizeof(void *) * (stack->max)), stack->persistent); \
53 stack->top_element = stack->elements+stack->top; \
54 }
55
56
57
58 static zend_always_inline void zend_ptr_stack_3_push(zend_ptr_stack *stack, void *a, void *b, void *c)
59 {
60 #define ZEND_PTR_STACK_NUM_ARGS 3
61
62 ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, ZEND_PTR_STACK_NUM_ARGS)
63
64 stack->top += ZEND_PTR_STACK_NUM_ARGS;
65 *(stack->top_element++) = a;
66 *(stack->top_element++) = b;
67 *(stack->top_element++) = c;
68
69 #undef ZEND_PTR_STACK_NUM_ARGS
70 }
71
72 static zend_always_inline void zend_ptr_stack_2_push(zend_ptr_stack *stack, void *a, void *b)
73 {
74 #define ZEND_PTR_STACK_NUM_ARGS 2
75
76 ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, ZEND_PTR_STACK_NUM_ARGS)
77
78 stack->top += ZEND_PTR_STACK_NUM_ARGS;
79 *(stack->top_element++) = a;
80 *(stack->top_element++) = b;
81
82 #undef ZEND_PTR_STACK_NUM_ARGS
83 }
84
85 static zend_always_inline void zend_ptr_stack_3_pop(zend_ptr_stack *stack, void **a, void **b, void **c)
86 {
87 *a = *(--stack->top_element);
88 *b = *(--stack->top_element);
89 *c = *(--stack->top_element);
90 stack->top -= 3;
91 }
92
93 static zend_always_inline void zend_ptr_stack_2_pop(zend_ptr_stack *stack, void **a, void **b)
94 {
95 *a = *(--stack->top_element);
96 *b = *(--stack->top_element);
97 stack->top -= 2;
98 }
99
100 static zend_always_inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr)
101 {
102 ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, 1)
103
104 stack->top++;
105 *(stack->top_element++) = ptr;
106 }
107
108 static zend_always_inline void *zend_ptr_stack_pop(zend_ptr_stack *stack)
109 {
110 stack->top--;
111 return *(--stack->top_element);
112 }
113
114 static zend_always_inline void *zend_ptr_stack_top(zend_ptr_stack *stack)
115 {
116 return stack->elements[stack->top - 1];
117 }
118
119 #endif
120
121
122
123
124
125
126
127