From 8b7f4060033e0a53c4f78365fe4a2e038c7b651c Mon Sep 17 00:00:00 2001 From: pnenzi Date: Tue, 6 Feb 2001 18:29:13 +0000 Subject: [PATCH] Modified CALLOC macro. Now uses calloc if LIBGC is not installed and malloc otherwise. LIBGC provides a malloc that clean the allocated memory. --- src/maths/sparse/spdefs.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/maths/sparse/spdefs.h b/src/maths/sparse/spdefs.h index bb865d728..1b4f78631 100644 --- a/src/maths/sparse/spdefs.h +++ b/src/maths/sparse/spdefs.h @@ -255,13 +255,17 @@ #define FREE(ptr) { if ((ptr) != NULL) txfree((char *)(ptr)); (ptr) = NULL; } -/* Calloc that properly handles allocating a cleared vector. */ -#define CALLOC(ptr,type,number) \ -{ int i; ptr = ALLOC(type, number); \ - if (ptr != (type *)NULL) \ - for(i=(number)-1;i>=0; i--) ptr[i] = (type) 0; \ -} +/* A new calloc */ +#ifndef HAVE_LIBGC +#define CALLOC(ptr,type,number) \ +{ ptr = (type *) calloc(type, number); \ +} +#else /* HAVE_LIBCG */ +#define CALLOC(ptr,type,number) \ +{ ptr = (type *) tmalloc(((size_t)number) * sizeof(type)); \ +} +#endif #include "complex.h"