cleanup TMALLOC etc macros

This commit is contained in:
rlar 2010-10-31 19:36:57 +00:00
parent 1372c00bf4
commit c3f20f8321
5 changed files with 42 additions and 32 deletions

View File

@ -1,3 +1,10 @@
2010-10-31 Robert Larice
* src/include/memory.h ,
* src/maths/sparse/spdefs.h ,
* src/xspice/icm/xtraevt/int/udnfunc.c ,
* src/xspice/icm/xtraevt/real/udnfunc.c :
cleanup TMALLOC etc macros
2010-10-31 Holger Vogt
* compile_min.sh: exit upon autogen or configure error

View File

@ -3,56 +3,59 @@
#include <stddef.h>
#define TMALLOC(t,n) (t*) /**/ tmalloc(sizeof(t) * (size_t)(n))
#define TREALLOC(t,p,n) (t*) /**/ trealloc(p, sizeof(t) * (size_t)(n))
#define TMALLOC(t,n) (t*) tmalloc(sizeof(t) * (size_t)(n))
#define TREALLOC(t,p,n) (t*) trealloc(p, sizeof(t) * (size_t)(n))
#ifndef HAVE_LIBGC
extern void *tmalloc(size_t num);
extern void *trealloc(void *str, size_t num);
extern void txfree(void *ptr);
#define tfree(x) (txfree(x), x = 0)
#define tfree(x) (txfree(x), (x) = 0)
#else
#include <gc/gc.h>
#define tmalloc(m) GC_malloc(m)
#define tmalloc(m) GC_malloc(m)
#define trealloc(m,n) GC_realloc((m),(n))
#define tfree(m)
#define txfree(m)
#endif
#include "../misc/stringutil.h" /* va: spice3 internally bzero */
#define alloc(TYPE) (TMALLOC(TYPE, 1))
#define MALLOC(x) tmalloc((unsigned)(x))
#define FREE(x) {if (x) {txfree((char *)(x));(x) = 0;}}
#define REALLOC(x,y) trealloc((x),(unsigned)(y))
#define ZERO(PTR,TYPE) (bzero((PTR),sizeof(TYPE)))
#define alloc(TYPE) TMALLOC(TYPE, 1)
#define MALLOC(x) tmalloc((size_t)(x))
#define FREE(x) {if(x) { txfree(x); (x) = 0; }}
#define REALLOC(x,y) trealloc(x, (size_t)(y))
#define ZERO(PTR,TYPE) bzero(PTR, sizeof(TYPE))
#if defined(_MSC_VER) || defined(__MINGW32__)
void *
hrealloc(void *ptr, size_t num);
void * hrealloc(void *ptr, size_t num);
#endif
#ifdef CIDER
#define RALLOC(ptr,type,number)\
if ((number) && (!(ptr = (type *)calloc((number), (unsigned)(sizeof(type)))))) {\
return(E_NOMEM);\
#define RALLOC(ptr,type,number) \
if ((number) && !(ptr = (type *)calloc((size_t)(number), sizeof(type)))) { \
return(E_NOMEM); \
}
#define XALLOC(ptr,type,number) \
if ((number) && (!(ptr = (type *)calloc((number), (unsigned)(sizeof(type)))))) {\
SPfrontEnd->IFerror( E_PANIC, "Out of Memory", NIL(IFuid) );\
exit( 1 );\
#define XALLOC(ptr,type,number) \
if ((number) && !(ptr = (type *)calloc((size_t)(number), sizeof(type)))) { \
SPfrontEnd->IFerror( E_PANIC, "Out of Memory", NIL(IFuid) ); \
exit( 1 ); \
}
#define XCALLOC(ptr,type,number) \
if ((number) && (!(ptr = (type *)calloc((number), (unsigned)(sizeof(type)))))) {\
fprintf( stderr, "Out of Memory\n" );\
exit( 1 );\
#define XCALLOC(ptr,type,number) \
if ((number) && !(ptr = (type *)calloc((size_t)(number), sizeof(type)))) { \
fprintf( stderr, "Out of Memory\n" ); \
exit( 1 ); \
}
#endif /* CIDER */
#endif

View File

@ -369,21 +369,21 @@ extern void * tmalloc(size_t);
extern void txfree(void *);
extern void * trealloc(void *, size_t);
#define SP_MALLOC(type,number) ((type *)tmalloc((size_t)(sizeof(type)*(number))))
#define SP_REALLOC(ptr,type,number) \
ptr = (type *)trealloc(ptr,(unsigned)(sizeof(type)*(number)))
#define SP_FREE(ptr) { if ((ptr) != NULL) txfree((char *)(ptr)); (ptr) = NULL; }
#define SP_MALLOC(type,number) (type *) tmalloc((size_t)(number) * sizeof(type))
#define SP_REALLOC(ptr,type,number) \
ptr = (type *) trealloc(ptr, (size_t)(number) * sizeof(type))
#define SP_FREE(ptr) { if ((ptr) != NULL) txfree(ptr); (ptr) = NULL; }
/* A new calloc */
#ifndef HAVE_LIBGC
#define SP_CALLOC(ptr,type,number) \
{ ptr = (type *) calloc(number, sizeof(type)); \
#define SP_CALLOC(ptr,type,number) \
{ ptr = (type *) calloc((size_t)(number), sizeof(type)); \
}
#else /* HAVE_LIBCG */
#define SP_CALLOC(ptr,type,number) \
{ ptr = TMALLOC(type, (size_t)number); \
#define SP_CALLOC(ptr,type,number) \
{ ptr = (type *) tmalloc((size_t)(number) * sizeof(type)); \
}
#endif

View File

@ -46,7 +46,7 @@ NON-STANDARD FEATURES
void *tmalloc(size_t);
#define TMALLOC(t,n) (t*) /**/ tmalloc(sizeof(t) * (size_t)(n))
#define TMALLOC(t,n) (t*) tmalloc(sizeof(t) * (size_t)(n))
/* ************************************************************************ */

View File

@ -46,7 +46,7 @@ NON-STANDARD FEATURES
void *tmalloc(size_t);
#define TMALLOC(t,n) (t*) /**/ tmalloc(sizeof(t) * (size_t)(n))
#define TMALLOC(t,n) (t*) tmalloc(sizeof(t) * (size_t)(n))
/* ************************************************************************ */