00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 00002 /* ==================================================================== 00003 * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 00004 * reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in 00015 * the documentation and/or other materials provided with the 00016 * distribution. 00017 * 00018 * This work was supported in part by funding from the Defense Advanced 00019 * Research Projects Agency and the National Science Foundation of the 00020 * United States of America, and the CMU Sphinx Speech Consortium. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 00023 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00024 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00025 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 00026 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00028 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00029 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00030 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * ==================================================================== 00035 * 00036 */ 00037 /* 00038 * ckd_alloc.h -- Memory allocation package. 00039 * 00040 * ********************************************** 00041 * CMU ARPA Speech Project 00042 * 00043 * Copyright (c) 1999 Carnegie Mellon University. 00044 * ALL RIGHTS RESERVED. 00045 * ********************************************** 00046 * 00047 * HISTORY 00048 * $Log: ckd_alloc.h,v $ 00049 * Revision 1.10 2005/06/22 02:59:25 arthchan2003 00050 * Added keyword 00051 * 00052 * Revision 1.3 2005/03/30 01:22:48 archan 00053 * Fixed mistakes in last updates. Add 00054 * 00055 * 00056 * 19-Jun-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 00057 * Removed file,line arguments from free functions. 00058 * 00059 * 01-Jan-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University 00060 * Created. 00061 */ 00062 00063 00064 /********************************************************************* 00065 * 00066 * $Header: /cvsroot/cmusphinx/sphinx3/src/libutil/ckd_alloc.h,v 1.10 2005/06/22 02:59:25 arthchan2003 Exp $ 00067 * 00068 * Carnegie Mellon ARPA Speech Group 00069 * 00070 * Copyright (c) 1994 Carnegie Mellon University. 00071 * All rights reserved. 00072 * 00073 ********************************************************************* 00074 * 00075 * file: ckd_alloc.h 00076 * 00077 * traceability: 00078 * 00079 * description: 00080 * 00081 * author: 00082 * 00083 *********************************************************************/ 00084 00085 00086 #ifndef _LIBUTIL_CKD_ALLOC_H_ 00087 #define _LIBUTIL_CKD_ALLOC_H_ 00088 00089 #include <stdlib.h> 00090 #include <setjmp.h> 00091 00092 /* Win32/WinCE DLL gunk */ 00093 #include <sphinxbase_export.h> 00094 #include <prim_type.h> 00095 00104 #ifdef __cplusplus 00105 extern "C" { 00106 #endif 00107 #if 0 00108 /* Fool Emacs. */ 00109 } 00110 #endif 00111 00127 jmp_buf *ckd_set_jump(jmp_buf *env, int abort); 00128 00132 void ckd_fail(char *format, ...); 00133 00134 /* 00135 * The following functions are similar to the malloc family, except 00136 * that they have two additional parameters, caller_file and 00137 * caller_line, for error reporting. All functions print a diagnostic 00138 * message if any error occurs, with any other behaviour determined by 00139 * ckd_set_jump(), above. 00140 */ 00141 00142 SPHINXBASE_EXPORT 00143 void *__ckd_calloc__(size_t n_elem, size_t elem_size, 00144 const char *caller_file, int caller_line); 00145 00146 SPHINXBASE_EXPORT 00147 void *__ckd_malloc__(size_t size, 00148 const char *caller_file, int caller_line); 00149 00150 SPHINXBASE_EXPORT 00151 void *__ckd_realloc__(void *ptr, size_t new_size, 00152 const char *caller_file, int caller_line); 00153 00158 SPHINXBASE_EXPORT 00159 char *__ckd_salloc__(const char *origstr, 00160 const char *caller_file, int caller_line); 00161 00166 SPHINXBASE_EXPORT 00167 void *__ckd_calloc_2d__(size_t d1, size_t d2, /* In: #elements in the 2 dimensions */ 00168 size_t elemsize, /* In: Size (#bytes) of each element */ 00169 const char *caller_file, int caller_line); /* In */ 00170 00175 SPHINXBASE_EXPORT 00176 void *__ckd_calloc_3d__(size_t d1, size_t d2, size_t d3, /* In: #elems in the dims */ 00177 size_t elemsize, /* In: Size (#bytes) per element */ 00178 const char *caller_file, int caller_line); /* In */ 00179 00183 SPHINXBASE_EXPORT 00184 void * __ckd_alloc_3d_ptr(size_t d1, 00185 size_t d2, 00186 size_t d3, 00187 void *store, 00188 size_t elem_size, 00189 char *caller_file, 00190 int caller_line); 00191 00195 SPHINXBASE_EXPORT 00196 void *__ckd_alloc_2d_ptr(size_t d1, 00197 size_t d2, 00198 void *store, 00199 size_t elem_size, 00200 char *caller_file, 00201 int caller_line); 00202 00206 SPHINXBASE_EXPORT 00207 void ckd_free(void *ptr); 00208 00212 SPHINXBASE_EXPORT 00213 void ckd_free_2d(void *ptr); 00214 00215 00219 SPHINXBASE_EXPORT 00220 void ckd_free_3d(void *ptr); 00221 00230 #define ckd_calloc(n,sz) __ckd_calloc__((n),(sz),__FILE__,__LINE__) 00231 00235 #define ckd_malloc(sz) __ckd_malloc__((sz),__FILE__,__LINE__) 00236 00240 #define ckd_realloc(ptr,sz) __ckd_realloc__(ptr,(sz),__FILE__,__LINE__) 00241 00246 #define ckd_salloc(ptr) __ckd_salloc__(ptr,__FILE__,__LINE__) 00247 00252 #define ckd_calloc_2d(d1,d2,sz) __ckd_calloc_2d__((d1),(d2),(sz),__FILE__,__LINE__) 00253 00258 #define ckd_calloc_3d(d1,d2,d3,sz) __ckd_calloc_3d__((d1),(d2),(d3),(sz),__FILE__,__LINE__) 00259 00264 #define ckd_alloc_2d_ptr(d1, d2, bf, sz) __ckd_alloc_2d_ptr((d1), (d2), (bf), (sz), __FILE__, __LINE__) 00265 00269 #define ckd_free_2d_ptr(bf) ckd_free(bf) 00270 00275 #define ckd_alloc_3d_ptr(d1, d2, d3, bf, sz) __ckd_alloc_3d_ptr((d1), (d2), (d3), (bf), (sz), __FILE__, __LINE__) 00276 00280 #define ckd_free_3d_ptr(bf) ckd_free_2d(bf) 00281 00282 #ifdef __cplusplus 00283 } 00284 #endif 00285 00286 #endif