Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / php / Zend / zend_static_allocator.c
blob1150deb570d7c1bc86604c717ffd58e707fb6953
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 2.00 of the Zend 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.zend.com/license/2_00.txt. |
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. |
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 +----------------------------------------------------------------------+
19 /* $Id$ */
21 #include "zend_static_allocator.h"
23 /* Not checking emalloc() and erealloc() return values as they are supposed to bailout */
25 inline static void block_init(Block *block, zend_uint block_size)
27 block->pos = block->bp = (char *) emalloc(block_size);
28 block->end = block->bp + block_size;
31 inline static char *block_allocate(Block *block, zend_uint size)
33 char *retval = block->pos;
34 if ((block->pos += size) >= block->end) {
35 return (char *)NULL;
37 return retval;
40 inline static void block_destroy(Block *block)
42 efree(block->bp);
45 void static_allocator_init(StaticAllocator *sa)
47 sa->Blocks = (Block *) emalloc(sizeof(Block));
48 block_init(sa->Blocks, ALLOCATOR_BLOCK_SIZE);
49 sa->num_blocks = 1;
50 sa->current_block = 0;
53 char *static_allocator_allocate(StaticAllocator *sa, zend_uint size)
55 char *retval;
57 retval = block_allocate(&sa->Blocks[sa->current_block], size);
58 if (retval) {
59 return retval;
61 sa->Blocks = (Block *) erealloc(sa->Blocks, ++sa->num_blocks);
62 sa->current_block++;
63 block_init(&sa->Blocks[sa->current_block], (size > ALLOCATOR_BLOCK_SIZE) ? size : ALLOCATOR_BLOCK_SIZE);
64 retval = block_allocate(&sa->Blocks[sa->current_block], size);
65 return retval;
68 void static_allocator_destroy(StaticAllocator *sa)
70 zend_uint i;
72 for (i=0; i<sa->num_blocks; i++) {
73 block_free(&sa->Blocks[i]);
75 efree(sa->Blocks);
79 * Local variables:
80 * tab-width: 4
81 * c-basic-offset: 4
82 * indent-tabs-mode: t
83 * End: