2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2008 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Daniel Cowgill <dcowgill@communityconnect.com> |
16 +----------------------------------------------------------------------+
18 This software was contributed to PHP by Community Connect Inc. in 2002
19 and revised in 2005 by Yahoo! Inc. to add support for PHP 5.1.
20 Future revisions and derivatives of this source code must acknowledge
21 Community Connect Inc. as the original contributor of this module by
22 leaving this note intact in the source code.
24 All other licensing and usage conditions are those of the PHP Group.
28 /* $Id: apc_stack.c,v 3.4.2.1 2008/05/11 18:57:00 rasmus Exp $ */
30 #include "apc_stack.h"
39 apc_stack_t* apc_stack_create(int size_hint)
41 apc_stack_t* stack = (apc_stack_t*) apc_emalloc(sizeof(apc_stack_t));
43 stack->capacity = (size_hint > 0) ? size_hint : 10;
45 stack->data = (void**) apc_emalloc(sizeof(void*) * stack->capacity);
50 void apc_stack_destroy(apc_stack_t* stack)
53 apc_efree(stack->data);
58 void apc_stack_clear(apc_stack_t* stack)
60 assert(stack != NULL);
64 void apc_stack_push(apc_stack_t* stack, void* item)
66 assert(stack != NULL);
67 if (stack->size == stack->capacity) {
69 stack->data = apc_erealloc(stack->data, sizeof(void*)*stack->capacity);
71 stack->data[stack->size++] = item;
74 void* apc_stack_pop(apc_stack_t* stack)
76 assert(stack != NULL && stack->size > 0);
77 return stack->data[--stack->size];
80 void* apc_stack_top(apc_stack_t* stack)
82 assert(stack != NULL && stack->size > 0);
83 return stack->data[stack->size-1];
86 void* apc_stack_get(apc_stack_t* stack, int n)
88 assert(stack != NULL && stack->size > n);
89 return stack->data[n];
92 int apc_stack_size(apc_stack_t* stack)
94 assert(stack != NULL);
103 * vim600: expandtab sw=4 ts=4 sts=4 fdm=marker
104 * vim<600: expandtab sw=4 ts=4 sts=4