|
|
|
@ -6,25 +6,22 @@ $Id$ |
|
|
|
/* |
|
|
|
* Memory alloction functions |
|
|
|
*/ |
|
|
|
#include <config.h> |
|
|
|
#include "ngspice.h" |
|
|
|
|
|
|
|
#ifndef HAVE_LIBGC |
|
|
|
#include <ngspice.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <memory.h> |
|
|
|
|
|
|
|
/*saj For Tcl module locking*/ |
|
|
|
#ifdef TCL_MODULE |
|
|
|
#include <tcl.h> |
|
|
|
//#include <tclDecls.h> |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAS_WINDOWS |
|
|
|
#if defined(_MSC_VER) || defined(__MINGW32__) |
|
|
|
#undef BOOLEAN |
|
|
|
#include <windows.h> |
|
|
|
extern HANDLE outheap; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
/* Malloc num bytes and initialize to zero. Fatal error if the space can't |
|
|
|
* be tmalloc'd. Return NULL for a request for 0 bytes. |
|
|
|
@ -59,6 +56,54 @@ tmalloc(size_t num) |
|
|
|
return(s); |
|
|
|
} |
|
|
|
|
|
|
|
/* Original Berkeley Implementation */ |
|
|
|
/* |
|
|
|
void * |
|
|
|
tmalloc(size_t num) |
|
|
|
{ |
|
|
|
void *s; |
|
|
|
|
|
|
|
if (!num) |
|
|
|
return NULL; |
|
|
|
|
|
|
|
s = malloc((unsigned) num); |
|
|
|
if (!s) { |
|
|
|
fprintf(stderr, |
|
|
|
"malloc: Internal Error: can't allocate %d bytes.\n", num); |
|
|
|
exit(EXIT_BAD); |
|
|
|
} |
|
|
|
|
|
|
|
bzero(s, num); |
|
|
|
|
|
|
|
return(s); |
|
|
|
} |
|
|
|
|
|
|
|
void * |
|
|
|
trealloc(void *str, size_t num) |
|
|
|
{ |
|
|
|
void *s; |
|
|
|
|
|
|
|
if (!num) { |
|
|
|
if (str) |
|
|
|
free(str); |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
if (!str) |
|
|
|
s = tmalloc(num); |
|
|
|
else |
|
|
|
s = realloc(str, (unsigned) num); |
|
|
|
|
|
|
|
if (!s) { |
|
|
|
fprintf(stderr, |
|
|
|
"realloc: Internal Error: can't allocate %d bytes.\n", num); |
|
|
|
exit(EXIT_BAD); |
|
|
|
} |
|
|
|
return(s); |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
void * |
|
|
|
trealloc(void *ptr, size_t num) |
|
|
|
{ |
|
|
|
@ -98,6 +143,7 @@ trealloc(void *ptr, size_t num) |
|
|
|
Function is used in outitf.c to prevent heap fragmentation |
|
|
|
An additional heap outheap is used to store the plot output data. |
|
|
|
*/ |
|
|
|
#ifdef HAS_WINDOWS |
|
|
|
#if defined(_MSC_VER) || defined(__MINGW32__) |
|
|
|
void * |
|
|
|
hrealloc(void *ptr, size_t num) |
|
|
|
@ -134,56 +180,7 @@ hrealloc(void *ptr, size_t num) |
|
|
|
return(s); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Original Berkeley Implementation */ |
|
|
|
/* |
|
|
|
void * |
|
|
|
tmalloc(size_t num) |
|
|
|
{ |
|
|
|
void *s; |
|
|
|
|
|
|
|
if (!num) |
|
|
|
return NULL; |
|
|
|
|
|
|
|
s = malloc((unsigned) num); |
|
|
|
if (!s) { |
|
|
|
fprintf(stderr, |
|
|
|
"malloc: Internal Error: can't allocate %d bytes.\n", num); |
|
|
|
exit(EXIT_BAD); |
|
|
|
} |
|
|
|
|
|
|
|
bzero(s, num); |
|
|
|
|
|
|
|
return(s); |
|
|
|
} |
|
|
|
|
|
|
|
void * |
|
|
|
trealloc(void *str, size_t num) |
|
|
|
{ |
|
|
|
void *s; |
|
|
|
|
|
|
|
if (!num) { |
|
|
|
if (str) |
|
|
|
free(str); |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
if (!str) |
|
|
|
s = tmalloc(num); |
|
|
|
else |
|
|
|
s = realloc(str, (unsigned) num); |
|
|
|
|
|
|
|
if (!s) { |
|
|
|
fprintf(stderr, |
|
|
|
"realloc: Internal Error: can't allocate %d bytes.\n", num); |
|
|
|
exit(EXIT_BAD); |
|
|
|
} |
|
|
|
return(s); |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|