Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 121 lines (97 sloc) 3.005 kb
573b460 andigutmans Zend Library
andigutmans authored
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
4e19825 Felipe Pena - Year++
felipensp authored
5 | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
573b460 andigutmans Zend Library
andigutmans authored
6 +----------------------------------------------------------------------+
d863d52 Update headers.
Sebastian Bergmann authored
7 | This source file is subject to version 2.00 of the Zend license, |
b5b1117 Zeev Suraski License update
zsuraski authored
8 | that is bundled with this package in the file LICENSE, and is |
f68c7ff updating license information in the headers.
James Cox authored
9 | available through the world-wide-web at the following url: |
d863d52 Update headers.
Sebastian Bergmann authored
10 | http://www.zend.com/license/2_00.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
333406b - Added some missing CVS $Id$ tags, headers and footers.
foobar authored
20 /* $Id$ */
b5b1117 Zeev Suraski License update
zsuraski authored
21
573b460 andigutmans Zend Library
andigutmans authored
22 #include "zend.h"
23 #include "zend_ptr_stack.h"
009025e * header file cleanup
Stig S. Bakken authored
24 #ifdef HAVE_STDARG_H
25 # include <stdarg.h>
e9e7bc6 andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
26 #endif
573b460 andigutmans Zend Library
andigutmans authored
27
e6dff0c Johannes Schlüter - MFH: Allow persistent zent_ptr_stacks (patch by Andrey Hristov)
johannes authored
28 ZEND_API void zend_ptr_stack_init_ex(zend_ptr_stack *stack, zend_bool persistent)
573b460 andigutmans Zend Library
andigutmans authored
29 {
bc1f1d2 zend_ptr_stack allocation is delayed before the actual usage
Dmitry Stogov authored
30 stack->top_element = stack->elements = NULL;
31 stack->top = stack->max = 0;
e6dff0c Johannes Schlüter - MFH: Allow persistent zent_ptr_stacks (patch by Andrey Hristov)
johannes authored
32 stack->persistent = persistent;
33 }
34
35 ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
36 {
37 zend_ptr_stack_init_ex(stack, 0);
573b460 andigutmans Zend Library
andigutmans authored
38 }
39
40
7f27821 Zeev Suraski inline functions cannot accept varargs
zsuraski authored
41 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
42 {
43 va_list ptr;
44 void *elem;
45
d7c839d andigutmans - More ptr_stack optimizations and cleanups
andigutmans authored
46 ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, count)
47
e9e7bc6 andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
48 va_start(ptr, count);
49 while (count>0) {
50 elem = va_arg(ptr, void *);
51 stack->top++;
52 *(stack->top_element++) = elem;
53 count--;
54 }
55 va_end(ptr);
56 }
57
58
7f27821 Zeev Suraski inline functions cannot accept varargs
zsuraski authored
59 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
60 {
61 va_list ptr;
62 void **elem;
63
64 va_start(ptr, count);
65 while (count>0) {
66 elem = va_arg(ptr, void **);
447eb3b andigutmans - Damn that's more like it.
andigutmans authored
67 *elem = *(--stack->top_element);
e9e7bc6 andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored
68 stack->top--;
69 count--;
70 }
71 va_end(ptr);
72 }
573b460 andigutmans Zend Library
andigutmans authored
73
74
75
76 ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack)
77 {
78 if (stack->elements) {
e6dff0c Johannes Schlüter - MFH: Allow persistent zent_ptr_stacks (patch by Andrey Hristov)
johannes authored
79 pefree(stack->elements, stack->persistent);
573b460 andigutmans Zend Library
andigutmans authored
80 }
81 }
82
83
84 ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *))
85 {
86 int i = stack->top;
87
88 while (--i >= 0) {
89 func(stack->elements[i]);
90 }
91 }
92
93
34c2b0a Zeev Suraski - Add restore_error_handler()
zsuraski authored
94 ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *), zend_bool free_elements)
573b460 andigutmans Zend Library
andigutmans authored
95 {
96 zend_ptr_stack_apply(stack, func);
34c2b0a Zeev Suraski - Add restore_error_handler()
zsuraski authored
97 if (free_elements) {
98 int i = stack->top;
99
100 while (--i >= 0) {
e6dff0c Johannes Schlüter - MFH: Allow persistent zent_ptr_stacks (patch by Andrey Hristov)
johannes authored
101 pefree(stack->elements[i], stack->persistent);
34c2b0a Zeev Suraski - Add restore_error_handler()
zsuraski authored
102 }
103 }
573b460 andigutmans Zend Library
andigutmans authored
104 stack->top = 0;
3fcc651 andigutmans * Optimize argument_stack top lookup
andigutmans authored
105 stack->top_element = stack->elements;
573b460 andigutmans Zend Library
andigutmans authored
106 }
39a7f4c Zeev Suraski This patch is a go. Not fully optimized yet, but working properly.
zsuraski authored
107
108
34c2b0a Zeev Suraski - Add restore_error_handler()
zsuraski authored
109 ZEND_API int zend_ptr_stack_num_elements(zend_ptr_stack *stack)
110 {
111 return stack->top;
112 }
333406b - Added some missing CVS $Id$ tags, headers and footers.
foobar authored
113
114 /*
115 * Local variables:
116 * tab-width: 4
117 * c-basic-offset: 4
118 * indent-tabs-mode: t
119 * End:
120 */
Something went wrong with that request. Please try again.