Skip to content
Newer
Older
100644 116 lines (93 sloc) 2.82 KB
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
13a78ac @sebastianbergmann sed -i "s#1998-2009#1998-2010#g" **/*.c **/*.h **/*.php
sebastianbergmann authored Jan 5, 2010
5 | Copyright (c) 1998-2010 Zend Technologies Ltd. (http://www.zend.com) |
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
6 +----------------------------------------------------------------------+
d863d52 @sebastianbergmann Update headers.
sebastianbergmann authored Dec 11, 2001
7 | This source file is subject to version 2.00 of the Zend license, |
b5b1117 @zsuraski License update
zsuraski authored Jul 16, 1999
8 | that is bundled with this package in the file LICENSE, and is |
f68c7ff updating license information in the headers.
James Cox authored Jun 10, 2003
9 | available through the world-wide-web at the following url: |
d863d52 @sebastianbergmann Update headers.
sebastianbergmann authored Dec 11, 2001
10 | http://www.zend.com/license/2_00.txt. |
b5b1117 @zsuraski License update
zsuraski authored Jul 16, 1999
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 Apr 7, 1999
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 Feb 1, 2003
20 /* $Id$ */
b5b1117 @zsuraski License update
zsuraski authored Jul 16, 1999
21
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
22 #include "zend.h"
23 #include "zend_ptr_stack.h"
009025e * header file cleanup
Stig S. Bakken authored Sep 6, 1999
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 Jul 30, 1999
26 #endif
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
27
28 ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
29 {
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored Jul 30, 1999
30 stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE);
31 stack->max = PTR_STACK_BLOCK_SIZE;
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
32 stack->top = 0;
33 }
34
35
7f27821 @zsuraski inline functions cannot accept varargs
zsuraski authored Dec 25, 1999
36 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 Jul 30, 1999
37 {
38 va_list ptr;
39 void *elem;
40
d7c839d @andigutmans - More ptr_stack optimizations and cleanups
andigutmans authored Jul 30, 2004
41 ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, count)
42
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored Jul 30, 1999
43 va_start(ptr, count);
44 while (count>0) {
45 elem = va_arg(ptr, void *);
46 stack->top++;
47 *(stack->top_element++) = elem;
48 count--;
49 }
50 va_end(ptr);
51 }
52
53
7f27821 @zsuraski inline functions cannot accept varargs
zsuraski authored Dec 25, 1999
54 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 Jul 30, 1999
55 {
56 va_list ptr;
57 void **elem;
58
59 va_start(ptr, count);
60 while (count>0) {
61 elem = va_arg(ptr, void **);
447eb3b @andigutmans - Damn that's more like it.
andigutmans authored Jul 30, 1999
62 *elem = *(--stack->top_element);
e9e7bc6 @andigutmans - Add ptr_stack_n_{push,pop} in order to speed up function calls a bit.
andigutmans authored Jul 30, 1999
63 stack->top--;
64 count--;
65 }
66 va_end(ptr);
67 }
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
68
69
70
71 ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack)
72 {
73 if (stack->elements) {
74 efree(stack->elements);
75 }
76 }
77
78
79 ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *))
80 {
81 int i = stack->top;
82
83 while (--i >= 0) {
84 func(stack->elements[i]);
85 }
86 }
87
88
34c2b0a @zsuraski - Add restore_error_handler()
zsuraski authored Jun 17, 2000
89 ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *), zend_bool free_elements)
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
90 {
91 zend_ptr_stack_apply(stack, func);
34c2b0a @zsuraski - Add restore_error_handler()
zsuraski authored Jun 17, 2000
92 if (free_elements) {
93 int i = stack->top;
94
95 while (--i >= 0) {
96 efree(stack->elements[i]);
97 }
98 }
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
99 stack->top = 0;
3fcc651 @andigutmans * Optimize argument_stack top lookup
andigutmans authored Apr 13, 1999
100 stack->top_element = stack->elements;
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
101 }
39a7f4c @zsuraski This patch is a go. Not fully optimized yet, but working properly.
zsuraski authored Apr 12, 1999
102
103
34c2b0a @zsuraski - Add restore_error_handler()
zsuraski authored Jun 17, 2000
104 ZEND_API int zend_ptr_stack_num_elements(zend_ptr_stack *stack)
105 {
106 return stack->top;
107 }
333406b - Added some missing CVS $Id$ tags, headers and footers.
foobar authored Feb 1, 2003
108
109 /*
110 * Local variables:
111 * tab-width: 4
112 * c-basic-offset: 4
113 * indent-tabs-mode: t
114 * End:
115 */
Something went wrong with that request. Please try again.