SphinxBase  5prealpha
ckd_alloc.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 /*
38  * ckd_alloc.h -- Memory allocation package.
39  *
40  * **********************************************
41  * CMU ARPA Speech Project
42  *
43  * Copyright (c) 1999 Carnegie Mellon University.
44  * ALL RIGHTS RESERVED.
45  * **********************************************
46  *
47  * HISTORY
48  * $Log: ckd_alloc.h,v $
49  * Revision 1.10 2005/06/22 02:59:25 arthchan2003
50  * Added keyword
51  *
52  * Revision 1.3 2005/03/30 01:22:48 archan
53  * Fixed mistakes in last updates. Add
54  *
55  *
56  * 19-Jun-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
57  * Removed file,line arguments from free functions.
58  *
59  * 01-Jan-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
60  * Created.
61  */
62 
63 
64 /*********************************************************************
65  *
66  * $Header: /cvsroot/cmusphinx/sphinx3/src/libutil/ckd_alloc.h,v 1.10 2005/06/22 02:59:25 arthchan2003 Exp $
67  *
68  * Carnegie Mellon ARPA Speech Group
69  *
70  * Copyright (c) 1994 Carnegie Mellon University.
71  * All rights reserved.
72  *
73  *********************************************************************
74  *
75  * file: ckd_alloc.h
76  *
77  * traceability:
78  *
79  * description:
80  *
81  * author:
82  *
83  *********************************************************************/
84 
85 
86 #ifndef _LIBUTIL_CKD_ALLOC_H_
87 #define _LIBUTIL_CKD_ALLOC_H_
88 
89 #include <stdlib.h>
90 #include <setjmp.h>
91 
92 /* Win32/WinCE DLL gunk */
93 #include <sphinxbase/sphinxbase_export.h>
94 #include <sphinxbase/prim_type.h>
95 
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107 #if 0
108 /* Fool Emacs. */
109 }
110 #endif
111 
127 jmp_buf *ckd_set_jump(jmp_buf *env, int abort);
128 
132 void ckd_fail(char *format, ...);
133 
134 /*
135  * The following functions are similar to the malloc family, except
136  * that they have two additional parameters, caller_file and
137  * caller_line, for error reporting. All functions print a diagnostic
138  * message if any error occurs, with any other behaviour determined by
139  * ckd_set_jump(), above.
140  */
141 
142 SPHINXBASE_EXPORT
143 void *__ckd_calloc__(size_t n_elem, size_t elem_size,
144  const char *caller_file, int caller_line);
145 
146 SPHINXBASE_EXPORT
147 void *__ckd_malloc__(size_t size,
148  const char *caller_file, int caller_line);
149 
150 SPHINXBASE_EXPORT
151 void *__ckd_realloc__(void *ptr, size_t new_size,
152  const char *caller_file, int caller_line);
153 
158 SPHINXBASE_EXPORT
159 char *__ckd_salloc__(const char *origstr,
160  const char *caller_file, int caller_line);
161 
166 SPHINXBASE_EXPORT
167 void *__ckd_calloc_2d__(size_t d1, size_t d2, /* In: #elements in the 2 dimensions */
168  size_t elemsize, /* In: Size (#bytes) of each element */
169  const char *caller_file, int caller_line); /* In */
170 
175 SPHINXBASE_EXPORT
176 void *__ckd_calloc_3d__(size_t d1, size_t d2, size_t d3, /* In: #elems in the dims */
177  size_t elemsize, /* In: Size (#bytes) per element */
178  const char *caller_file, int caller_line); /* In */
179 
184 SPHINXBASE_EXPORT
185 void ****__ckd_calloc_4d__(size_t d1,
186  size_t d2,
187  size_t d3,
188  size_t d4,
189  size_t elem_size,
190  char *caller_file,
191  int caller_line);
192 
196 SPHINXBASE_EXPORT
197 void * __ckd_alloc_3d_ptr(size_t d1,
198  size_t d2,
199  size_t d3,
200  void *store,
201  size_t elem_size,
202  char *caller_file,
203  int caller_line);
204 
208 SPHINXBASE_EXPORT
209 void *__ckd_alloc_2d_ptr(size_t d1,
210  size_t d2,
211  void *store,
212  size_t elem_size,
213  char *caller_file,
214  int caller_line);
215 
219 SPHINXBASE_EXPORT
220 void ckd_free(void *ptr);
221 
225 SPHINXBASE_EXPORT
226 void ckd_free_2d(void *ptr);
227 
231 SPHINXBASE_EXPORT
232 void ckd_free_3d(void *ptr);
233 
237 SPHINXBASE_EXPORT
238 void ckd_free_4d(void *ptr);
239 
248 #define ckd_calloc(n,sz) __ckd_calloc__((n),(sz),__FILE__,__LINE__)
249 
253 #define ckd_malloc(sz) __ckd_malloc__((sz),__FILE__,__LINE__)
254 
258 #define ckd_realloc(ptr,sz) __ckd_realloc__(ptr,(sz),__FILE__,__LINE__)
259 
264 #define ckd_salloc(ptr) __ckd_salloc__(ptr,__FILE__,__LINE__)
265 
270 #define ckd_calloc_2d(d1,d2,sz) __ckd_calloc_2d__((d1),(d2),(sz),__FILE__,__LINE__)
271 
276 #define ckd_calloc_3d(d1,d2,d3,sz) __ckd_calloc_3d__((d1),(d2),(d3),(sz),__FILE__,__LINE__)
277 
281 #define ckd_calloc_4d(d1, d2, d3, d4, s) __ckd_calloc_4d__((d1), (d2), (d3), (d4), (s), __FILE__, __LINE__)
282 
287 #define ckd_alloc_2d_ptr(d1, d2, bf, sz) __ckd_alloc_2d_ptr((d1), (d2), (bf), (sz), __FILE__, __LINE__)
288 
292 #define ckd_free_2d_ptr(bf) ckd_free(bf)
293 
298 #define ckd_alloc_3d_ptr(d1, d2, d3, bf, sz) __ckd_alloc_3d_ptr((d1), (d2), (d3), (bf), (sz), __FILE__, __LINE__)
299 
303 #define ckd_free_3d_ptr(bf) ckd_free_2d(bf)
304 
305 
306 #ifdef __cplusplus
307 }
308 #endif
309 
310 #endif
SPHINXBASE_EXPORT void **** __ckd_calloc_4d__(size_t d1, size_t d2, size_t d3, size_t d4, size_t elem_size, char *caller_file, int caller_line)
Allocate a 34D array and return ptr to it.
Definition: ckd_alloc.c:310
SPHINXBASE_EXPORT void ckd_free_4d(void *ptr)
Free a 4-D array (ptr) previously allocated by ckd_calloc_4d.
Definition: ckd_alloc.c:364
Basic type definitions used in Sphinx.
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
Definition: ckd_alloc.c:244
jmp_buf * ckd_set_jump(jmp_buf *env, int abort)
Control behaviour of the program when allocation fails.
Definition: ckd_alloc.c:109
SPHINXBASE_EXPORT void ckd_free_3d(void *ptr)
Free a 3-D array (ptr) previously allocated by ckd_calloc_3d.
Definition: ckd_alloc.c:297
SPHINXBASE_EXPORT void * __ckd_alloc_3d_ptr(size_t d1, size_t d2, size_t d3, void *store, size_t elem_size, char *caller_file, int caller_line)
Overlay a 3-D array over a previously allocated storage area.
Definition: ckd_alloc.c:380
SPHINXBASE_EXPORT void ckd_free_2d(void *ptr)
Free a 2-D array (ptr) previously allocated by ckd_calloc_2d.
Definition: ckd_alloc.c:255
SPHINXBASE_EXPORT void * __ckd_alloc_2d_ptr(size_t d1, size_t d2, void *store, size_t elem_size, char *caller_file, int caller_line)
Overlay a s-D array over a previously allocated storage area.
Definition: ckd_alloc.c:408
void ckd_fail(char *format,...)
Fail (with a message) according to behaviour specified by ckd_set_jump().
Definition: ckd_alloc.c:122
SPHINXBASE_EXPORT void * __ckd_calloc_3d__(size_t d1, size_t d2, size_t d3, size_t elemsize, const char *caller_file, int caller_line)
Allocate a 3-D array and return ptr to it.
Definition: ckd_alloc.c:265
SPHINXBASE_EXPORT void * __ckd_calloc_2d__(size_t d1, size_t d2, size_t elemsize, const char *caller_file, int caller_line)
Allocate a 2-D array and return ptr to it (ie, ptr to vector of ptrs).
Definition: ckd_alloc.c:223
SPHINXBASE_EXPORT char * __ckd_salloc__(const char *origstr, const char *caller_file, int caller_line)
Like strdup, except that if an error occurs it prints a diagnostic message and exits.
Definition: ckd_alloc.c:205