2 Copyright (c) 2003-2006 Hewlett-Packard Development Company, L.P.
3 Permission is hereby granted, free of charge, to any person
4 obtaining a copy of this software and associated documentation
5 files (the "Software"), to deal in the Software without
6 restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
33 static struct uwx_str_pool uwx_str_pool;
34 #define free(p) /* nullified */
35 #define malloc(sz) ((sz == sizeof(uwx_str_pool)) ? &uwx_str_pool : NULL)
41 * This file contains the routines for maintaining a string
42 * pool for the unwind environment. We preallocate enough
43 * space for most purposes so that no memory allocation is
44 * necessary during a normal unwind. If we do need more,
45 * we use the allocate callback, if one is provided.
47 * The string pool is reused with each call to step(),
48 * and is completely freed when the unwind environment is
53 int uwx_init_str_pool(struct uwx_env *env, struct uwx_str_pool *pool)
59 pool->size = STRPOOLSIZE;
62 env->string_pool = pool;
67 void uwx_free_str_pool(struct uwx_env *env)
69 struct uwx_str_pool *pool;
70 struct uwx_str_pool *next;
72 /* The first pool is preallocated as part of the uwx_env. Don't free it! */
73 pool = env->string_pool;
76 for (; pool != 0; pool = next) {
78 if (env->free_cb == 0)
81 (*env->free_cb)(pool);
85 char *uwx_alloc_str(struct uwx_env *env, char *str)
89 struct uwx_str_pool *pool;
90 struct uwx_str_pool *prev;
93 len = strlen(str) + 1;
95 for (pool = env->string_pool; pool != 0; pool = pool->next) {
97 if (pool->size - pool->used >= len)
104 size += sizeof(struct uwx_str_pool) - STRPOOLSIZE;
105 if (env->allocate_cb == 0)
106 pool = (struct uwx_str_pool *) malloc(size);
108 pool = (struct uwx_str_pool *) (*env->allocate_cb)(size);
109 if (env->string_pool == 0)
116 p = pool->pool + pool->used;
122 void uwx_reset_str_pool(struct uwx_env *env)
124 struct uwx_str_pool *pool;
126 for (pool = env->string_pool; pool != 0; pool = pool->next)