memory.h, polish macros
This commit is contained in:
parent
44ef3db000
commit
f973e7107f
|
|
@ -6,7 +6,9 @@
|
||||||
#define TMALLOC(t, n) (t*) tmalloc(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))
|
#define TREALLOC(t, p, n) (t*) trealloc(p, sizeof(t) * (size_t)(n))
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_LIBGC
|
#ifndef HAVE_LIBGC
|
||||||
|
|
||||||
extern void *tmalloc(size_t num);
|
extern void *tmalloc(size_t num);
|
||||||
extern void *trealloc(void *str, size_t num);
|
extern void *trealloc(void *str, size_t num);
|
||||||
extern void txfree(void *ptr);
|
extern void txfree(void *ptr);
|
||||||
|
|
@ -14,20 +16,22 @@ extern void txfree(void *ptr);
|
||||||
#define tfree(x) (txfree(x), (x) = 0)
|
#define tfree(x) (txfree(x), (x) = 0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <gc/gc.h>
|
#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 trealloc(m, n) GC_realloc((m), (n))
|
||||||
#define tfree(m)
|
#define tfree(m)
|
||||||
#define txfree(m)
|
#define txfree(m)
|
||||||
#endif
|
|
||||||
|
#endif /* HAVE_LIBGC */
|
||||||
|
|
||||||
|
|
||||||
#include "ngspice/stringutil.h" /* va: spice3 internally bzero */
|
#include "ngspice/stringutil.h" /* va: spice3 internally bzero */
|
||||||
|
|
||||||
#define alloc(TYPE) TMALLOC(TYPE, 1)
|
#define alloc(TYPE) TMALLOC(TYPE, 1)
|
||||||
#define MALLOC(x) tmalloc((size_t) (x))
|
#define MALLOC(x) tmalloc((size_t) (x))
|
||||||
#define FREE(x) {if(x) { txfree(x); (x) = 0; }}
|
#define FREE(x) do { if(x) { txfree(x); (x) = NULL; } } while(0)
|
||||||
#define REALLOC(x, y) trealloc(x, (size_t) (y))
|
#define REALLOC(x, y) trealloc(x, (size_t) (y))
|
||||||
#define ZERO(PTR, TYPE) bzero(PTR, sizeof(TYPE))
|
#define ZERO(PTR, TYPE) bzero(PTR, sizeof(TYPE))
|
||||||
|
|
||||||
|
|
@ -40,21 +44,26 @@ void * hrealloc(void *ptr, size_t num);
|
||||||
#ifdef CIDER
|
#ifdef CIDER
|
||||||
|
|
||||||
#define RALLOC(ptr, type, number) \
|
#define RALLOC(ptr, type, number) \
|
||||||
if ((number) && (ptr = (type *)calloc((size_t)(number), sizeof(type))) == NULL) { \
|
do { \
|
||||||
return(E_NOMEM); \
|
if ((number) && (ptr = (type *)calloc((size_t)(number), sizeof(type))) == NULL) \
|
||||||
}
|
return E_NOMEM; \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#define XALLOC(ptr, type, number) \
|
#define XALLOC(ptr, type, number) \
|
||||||
|
do { \
|
||||||
if ((number) && (ptr = (type *)calloc((size_t)(number), sizeof(type))) == NULL) { \
|
if ((number) && (ptr = (type *)calloc((size_t)(number), sizeof(type))) == NULL) { \
|
||||||
SPfrontEnd->IFerror( E_PANIC, "Out of Memory", NIL(IFuid) ); \
|
SPfrontEnd->IFerror(E_PANIC, "Out of Memory", NULL); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
}
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#define XCALLOC(ptr, type, number) \
|
#define XCALLOC(ptr, type, number) \
|
||||||
|
do { \
|
||||||
if ((number) && (ptr = (type *)calloc((size_t)(number), sizeof(type))) == NULL) { \
|
if ((number) && (ptr = (type *)calloc((size_t)(number), sizeof(type))) == NULL) { \
|
||||||
fprintf(stderr, "Out of Memory\n"); \
|
fprintf(stderr, "Out of Memory\n"); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
}
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#endif /* CIDER */
|
#endif /* CIDER */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ INPpas3(CKTcircuit *ckt, card *data, INPtables *tab, TSKtask *task,
|
||||||
|
|
||||||
for(current = data; current != NULL; current = current->nextcard) {
|
for(current = data; current != NULL; current = current->nextcard) {
|
||||||
line = current->line;
|
line = current->line;
|
||||||
FREE(token)
|
FREE(token);
|
||||||
INPgetTok(&line,&token,1);
|
INPgetTok(&line,&token,1);
|
||||||
|
|
||||||
if (strcmp(token,".nodeset")==0) {
|
if (strcmp(token,".nodeset")==0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue