94 #pragma warning (disable: 4996)
105 static jmp_buf *ckd_target;
106 static int jmp_abort;
126 va_start(args, format);
127 vfprintf(stderr, format, args);
132 #if defined(_WIN32_WCE)
138 longjmp(*ckd_target, 1);
144 __ckd_calloc__(
size_t n_elem,
size_t elem_size,
145 const char *caller_file,
int caller_line)
149 #if defined(__ADSPBLACKFIN__) && !defined(__linux__)
150 if ((mem = heap_calloc(heap_lookup(1),n_elem, elem_size)) == NULL)
151 if ((mem = heap_calloc(heap_lookup(0),n_elem, elem_size)) == NULL)
153 ckd_fail(
"calloc(%d,%d) failed from %s(%d), free space: %d\n", n_elem,
154 elem_size, caller_file, caller_line,space_unused());
157 if ((mem = calloc(n_elem, elem_size)) == NULL) {
158 ckd_fail(
"calloc(%d,%d) failed from %s(%d)\n", n_elem,
159 elem_size, caller_file, caller_line);
169 __ckd_malloc__(
size_t size,
const char *caller_file,
int caller_line)
173 #if defined(__ADSPBLACKFIN__) && !defined(__linux__)
174 if ((mem = heap_malloc(heap_lookup(0),size)) == NULL)
175 if ((mem = heap_malloc(heap_lookup(1),size)) == NULL)
177 if ((mem = malloc(size)) == NULL)
179 ckd_fail(
"malloc(%d) failed from %s(%d)\n", size,
180 caller_file, caller_line);
187 __ckd_realloc__(
void *ptr,
size_t new_size,
188 const char *caller_file,
int caller_line)
191 #if defined(__ADSPBLACKFIN__) && !defined(__linux__)
192 if ((mem = heap_realloc(heap_lookup(0),ptr, new_size)) == NULL) {
194 if ((mem = realloc(ptr, new_size)) == NULL) {
196 ckd_fail(
"malloc(%d) failed from %s(%d)\n", new_size,
197 caller_file, caller_line);
211 len = strlen(orig) + 1;
212 buf = (
char *) __ckd_malloc__(len, caller_file, caller_line);
221 const char *caller_file,
int caller_line)
227 (
char *) __ckd_calloc__(d1 * d2, elemsize, caller_file,
230 (
char **) __ckd_malloc__(d1 *
sizeof(
void *), caller_file,
233 for (i = 0, offset = 0; i < d1; i++, offset += d2 * elemsize)
234 ref[i] = mem + offset;
244 #if defined(__ADSPBLACKFIN__) && !defined(__linux__)
254 void **ptr = (
void **)tmpptr;
263 const char *caller_file,
int caller_line)
265 char ***ref1, **ref2, *mem;
269 (
char *) __ckd_calloc__(d1 * d2 * d3, elemsize, caller_file,
272 (
char ***) __ckd_malloc__(d1 *
sizeof(
void **), caller_file,
275 (
char **) __ckd_malloc__(d1 * d2 *
sizeof(
void *), caller_file,
278 for (i = 0, offset = 0; i < d1; i++, offset += d2)
279 ref1[i] = ref2 + offset;
282 for (i = 0; i < d1; i++) {
283 for (j = 0; j < d2; j++) {
284 ref1[i][j] = mem + offset;
285 offset += d3 * elemsize;
296 void ***ptr = (
void ***)inptr;
321 store = calloc(d1 * d2 * d3 * d4, elem_size);
323 E_FATAL(
"ckd_calloc_4d failed for caller at %s(%d) at %s(%d)\n",
324 file, line, __FILE__, __LINE__);
327 tmp1 = calloc(d1 * d2 * d3,
sizeof(
void *));
329 E_FATAL(
"ckd_calloc_4d failed for caller at %s(%d) at %s(%d)\n",
330 file, line, __FILE__, __LINE__);
335 E_FATAL(
"ckd_calloc_4d failed for caller at %s(%d) at %s(%d)\n",
336 file, line, __FILE__, __LINE__);
341 E_FATAL(
"ckd_calloc_4d failed for caller at %s(%d) at %s(%d)\n",
342 file, line, __FILE__, __LINE__);
345 for (i = 0, j = 0; i < d1*d2*d3; i++, j += d4) {
346 tmp1[i] = &((
char *)store)[j*elem_size];
349 for (i = 0, j = 0; i < d1*d2; i++, j += d3) {
353 for (i = 0, j = 0; i < d1; i++, j += d2) {
363 void ****ptr = (
void ****)inptr;
389 tmp1 = __ckd_calloc__(d1 * d2,
sizeof(
void *), file, line);
391 out = __ckd_calloc__(d1,
sizeof(
void **), file, line);
393 for (i = 0, j = 0; i < d1*d2; i++, j += d3) {
394 tmp1[i] = &((
char *)store)[j*elem_size];
397 for (i = 0, j = 0; i < d1; i++, j += d2) {
415 out = __ckd_calloc__(d1,
sizeof(
void *), file, line);
417 for (i = 0, j = 0; i < d1; i++, j += d2) {
418 out[i] = &((
char *)store)[j*elem_size];
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.
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
SPHINXBASE_EXPORT void ckd_free_4d(void *ptr)
Free a 4-D array (ptr) previously allocated by ckd_calloc_4d.
Sphinx's memory allocation/deallocation routines.
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
jmp_buf * ckd_set_jump(jmp_buf *env, int abort)
Control behaviour of the program when allocation fails.
Implementation of logging routines.
SPHINXBASE_EXPORT void ckd_free_3d(void *ptr)
Free a 3-D array (ptr) previously allocated by ckd_calloc_3d.
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.
#define E_FATAL
Exit with non-zero status after error message.
SPHINXBASE_EXPORT void ckd_free_2d(void *ptr)
Free a 2-D array (ptr) previously allocated by ckd_calloc_2d.
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.
void ckd_fail(char *format,...)
Fail (with a message) according to behaviour specified by ckd_set_jump().
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.
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).
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.