Undid versioning for code models and mutex protection for their memory allocations.

This commit is contained in:
Jim Monte 2020-02-20 01:54:26 -05:00
parent 9ff5363ea8
commit 887b48b9d5
31 changed files with 261 additions and 672 deletions

View File

@ -77,25 +77,6 @@ struct coreInfo_t {
void * ((*dllitf_tmalloc)(size_t));
void * ((*dllitf_trealloc)(void *, size_t));
void ((*dllitf_txfree)(void *));
/*** VERSION 2 ADDITIONS ***/
const char *(*dllitf_ngspice_version)(void);
/* version string of ngspice using the cm */
void *(*dllitf_tmalloc_raw)(size_t size);
/* mutex-protected malloc() that will not
* cause program termination on failure */
void *(*dllitf_tcalloc_raw)(size_t num, size_t size);
/* mutex-protected calloc() that will not
* cause program termination on failure */
void *(*dllitf_trealloc_raw)(void *p, size_t size);
/* mutex-protected realloc() that will not
* cause program termination on failure */
char *(*dllitf_tstrdup)(const char *sz);
/* mutex-protected strdup() that WILL
* cause program termination on failure */
char *(*dllitf_tstrdup_raw)(const char *sz);
/* mutex-protected strdup() that will not
* cause program termination on failure */
};
extern const struct coreInfo_t coreInfo;

View File

@ -194,7 +194,7 @@ inline char *ds_free_move(DSTRING *p_ds, unsigned int opt)
if (opt & DS_FREE_MOVE_OPT_FORCE_ALLOC) {
/* Allocate to minimum size */
size_t n_byte_alloc = p_ds->length + 1;
char * const p_ret = (char *) tmalloc_raw(n_byte_alloc);
char * const p_ret = (char *) malloc(n_byte_alloc);
if (p_ret == (char *) NULL) {
return (char *) NULL;
}
@ -206,7 +206,7 @@ inline char *ds_free_move(DSTRING *p_ds, unsigned int opt)
if (opt & DS_FREE_MOVE_OPT_COMPACT) {
/* Allocate to minimum size */
size_t n_byte_alloc = p_ds->length + 1;
char * const p_ret = (char *) trealloc_raw(p_buf_active, n_byte_alloc);
char * const p_ret = (char *) realloc(p_buf_active, n_byte_alloc);
if (p_ret == (char *) NULL) {
/* Realloc to smaller size somehow failed! */
return (char *) NULL;

View File

@ -212,8 +212,7 @@ static int ds_reserve_internal(DSTRING *p_ds,
n_byte_alloc_min = n_byte_alloc_opt;
}
for ( ; ; ) {
if ((p_buf_new = (char *) tmalloc_raw(
n_byte_alloc)) != (char *) NULL) {
if ((p_buf_new = (char *) malloc(n_byte_alloc)) != (char *) NULL) {
break; /* Allocated OK */
}
@ -348,7 +347,7 @@ int ds_compact(DSTRING *p_ds)
/* Else realloc the heap buffer */
{
void * const p = trealloc_raw(p_ds->p_buf, n_byte_alloc_min);
void * const p = realloc(p_ds->p_buf, n_byte_alloc_min);
if (p == NULL) {
return DS_E_NO_MEMORY;
}

View File

@ -53,9 +53,10 @@ funptr_t dlsym(void *, const char *);
char *dlerror(void);
#define FREE_DLERR_MSG(msg) free_dlerr_msg(msg)
static void free_dlerr_msg(char *msg);
#define RTLD_LAZY 1 /* lazy function call binding */
#define RTLD_NOW 2 /* immediate function call binding */
#define RTLD_GLOBAL 4 /* symbols in this dlopen'ed obj are visible to other dlopen'ed objs */
#define RTLD_LAZY 1 /* lazy function call binding */
#define RTLD_NOW 2 /* immediate function call binding */
#define RTLD_GLOBAL 4 /* symbols in this dlopen'ed obj are visible to other
* dlopen'ed objs */
#endif /* ifndef HAS_WINGUI */
#include "ngspice/dllitf.h" /* the coreInfo Structure*/
@ -422,43 +423,26 @@ int load_opus(const char *name)
/* Get code models defined by the library */
if ((fetch = dlsym(lib, "CMdevNum2")) != (funptr_t) NULL) {
/* Version 2 code models present */
if ((fetch = dlsym(lib, "CMdevNum")) != (funptr_t) NULL) {
num = *(*(int * (*)(void)) fetch)();
fetch = dlsym(lib, "CMdevs2");
fetch = dlsym(lib, "CMdevs");
if (fetch != (funptr_t) NULL) {
devs = (*(SPICEdev ** (*)(void)) fetch)();
}
else {
msg = dlerror();
printf("Error getting the list of version 2 devices: %s\n",
printf("Error getting the list of devices: %s\n",
msg);
FREE_DLERR_MSG(msg);
return 1;
}
}
else { /* no version 2, so try version 1 */
if ((fetch = dlsym(lib, "CMdevNum")) != (funptr_t) NULL) {
num = *(*(int * (*)(void)) fetch)();
fetch = dlsym(lib, "CMdevs");
if (fetch != (funptr_t) NULL) {
devs = (*(SPICEdev ** (*)(void)) fetch)();
}
else {
msg = dlerror();
printf("Error getting the list of version 1 devices: %s\n",
msg);
FREE_DLERR_MSG(msg);
return 1;
}
} /* end of case that got version 1 */
else { /* no version 2 or version 1 */
msg = dlerror();
printf("Error finding the number of devices: %s\n", msg);
FREE_DLERR_MSG(msg);
return 1;
}
} /* end of case of no version 2 */
else {
msg = dlerror();
printf("Error finding the number of devices: %s\n", msg);
FREE_DLERR_MSG(msg);
return 1;
}
add_device(num, devs, 1);
@ -468,46 +452,26 @@ int load_opus(const char *name)
/* Get user-defined ndes defined by the library */
if ((fetch = dlsym(lib, "CMudnNum2")) != (funptr_t) NULL) {
/* Version 2 user-defined types present */
if ((fetch = dlsym(lib, "CMudnNum")) != (funptr_t) NULL) {
num = *(*(int * (*)(void)) fetch)();
fetch = dlsym(lib, "CMudns2");
fetch = dlsym(lib, "CMudns");
if (fetch != (funptr_t) NULL) {
udns = (*(Evt_Udn_Info_t ** (*)(void)) fetch)();
}
else {
msg = dlerror();
printf("Error getting the list of version 2 "
"user-defined types: %s\n",
printf("Error getting the list of user-defined types: %s\n",
msg);
FREE_DLERR_MSG(msg);
return 1;
}
}
else { /* no version 2, so try version 1 */
if ((fetch = dlsym(lib, "CMudnNum")) != (funptr_t) NULL) {
num = *(*(int * (*)(void)) fetch)();
fetch = dlsym(lib, "CMudns");
if (fetch != (funptr_t) NULL) {
udns = (*(Evt_Udn_Info_t ** (*)(void)) fetch)();
}
else {
msg = dlerror();
printf("Error getting the list of version 1 "
"user-defined types: %s\n",
msg);
FREE_DLERR_MSG(msg);
return 1;
}
} /* end of case that got version 1 */
else { /* no version 2 or version 1 */
msg = dlerror();
printf("Error finding the number of "
"user-defined types: %s\n", msg);
FREE_DLERR_MSG(msg);
return 1;
}
} /* end of case of no version 2 */
else {
msg = dlerror();
printf("Error finding the number of user-defined types: %s\n", msg);
FREE_DLERR_MSG(msg);
return 1;
}
add_udn(num, udns);
#ifdef TRACE

View File

@ -92,11 +92,4 @@ const struct coreInfo_t coreInfo =
&tmalloc,
&trealloc,
&txfree,
/* Version 2 additions */
&get_ngspice_version,
&tmalloc_raw,
&tcalloc_raw,
&trealloc_raw,
&tstrdup,
&tstrdup_raw
};

View File

@ -14,21 +14,12 @@
static int fb_fill(FILEBUF *p_fb);
static int fbget_quoted_unescaped_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
static int fbget_quoted_unescaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static size_t fb_make_space_at_end(FILEBUF *p_fb);
static int fbget_quoted_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
static int fbget_quoted_escaped_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
static int fbget_unquoted_string(FILEBUF *p_fb,
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
static int fb_return_obj(FILEBUF *p_fb,
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
static int fb_return_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
static int fbget_quoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static int fbget_quoted_escaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static int fbget_unquoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static int fb_return_string(FILEBUF *p_fb, FBSTRING *p_fbstr);
static int fb_skip_to_eol(FILEBUF *p_fb);
static int fb_skip_whitespace(FILEBUF *p_fb);
@ -147,12 +138,7 @@ int fbclose(FILEBUF *p_fb)
*
* Parameters
* p_fb: FILEBUF pointer initialized using fbopen()
* n_type_wanted: number of desired type conversions for data from highest
* priority to lowest.
* p_type_wanted: Desired type conversions for data from highest priority
* to lowest.
* p_type_found: Address to receive the type of the data obtained
* p_fbobj: Address of an FBOBJ structure to receive the data
* p_fbstr: Address of an FBSTRING structure to receive the data
*
* Return codes
* +1: EOF reached
@ -180,9 +166,7 @@ int fbclose(FILEBUF *p_fb)
* 0: Normal
* -1: Error
*/
int fbget(FILEBUF *p_fb,
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
int fbget(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Test for existing EOF */
if (p_fb->is_eof && p_fb->p_data_cur == p_fb->p_data_end) { /* no data */
@ -210,12 +194,11 @@ int fbget(FILEBUF *p_fb,
/* Current char exists and starts the item */
if (*p_fb->p_data_cur == '"') { /* quoted string */
return fbget_quoted_string(p_fb, p_type_found, p_fbobj);
return fbget_quoted_string(p_fb, p_fbstr);
}
/* Else unquoted string */
return fbget_unquoted_string(p_fb, n_type_wanted, p_type_wanted,
p_type_found, p_fbobj);
return fbget_unquoted_string(p_fb, p_fbstr);
} /* end of function fbget */
@ -224,8 +207,7 @@ int fbget(FILEBUF *p_fb,
* to the quote starting the quoted string. On return it points to the first
* character after the current item or equals p_fb->p_data_end if the
* current item extens to the end of the current data string. */
static int fbget_quoted_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
static int fbget_quoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Advance past the opening quote to the true start of the string */
if (++p_fb->p_data_cur == p_fb->p_data_end) {
@ -243,7 +225,7 @@ static int fbget_quoted_string(FILEBUF *p_fb,
* and the buffer has at leat 1 byte a NULL to create the
* string "" can be written here */
*(p_fb->p_obj_end = p_fb->p_obj_start = p_fb->p_buf) = '\0';
return fb_return_string(p_fb, p_type_found, p_fbobj);
return fb_return_string(p_fb, p_fbstr);
}
/* Else data is now available at p_fb->p_data_cur */
} /* end of case that at end of data from file */
@ -253,15 +235,14 @@ static int fbget_quoted_string(FILEBUF *p_fb,
/* Continue processing as an unescaped string, unless the contrary
* is found to be true */
return fbget_quoted_unescaped_string(p_fb, p_type_found, p_fbobj);
return fbget_quoted_unescaped_string(p_fb, p_fbstr);
} /* end of function fbget_quoted_string */
/* Get a quoted string with no escape. The start has already been set on
* entry. If an escape is found, processing continues as an escaped string */
int fbget_quoted_unescaped_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
int fbget_quoted_unescaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Step through characters until end or escape */
char *p_data_cur = p_fb->p_data_cur;
@ -272,14 +253,13 @@ int fbget_quoted_unescaped_string(FILEBUF *p_fb,
if (ch_cur == '"') { /* Closing quote, so done */
*(p_fb->p_obj_end = p_data_cur) = '\0';
p_fb->p_data_cur = p_data_cur + 1;
return fb_return_string(p_fb, p_type_found, p_fbobj);
return fb_return_string(p_fb, p_fbstr);
}
if (ch_cur == '\\') { /* Escape */
/* After an escape, data must be moved to fill in the gap
* left by the escape character */
p_fb->p_data_cur = p_data_cur; /* Reprocess the escape */
return fbget_quoted_escaped_string(p_fb,
p_type_found, p_fbobj);
return fbget_quoted_escaped_string(p_fb, p_fbstr);
}
/* Else the character is part of the quoted string */
} /* end of loop over current text */
@ -295,7 +275,7 @@ int fbget_quoted_unescaped_string(FILEBUF *p_fb,
* did not return -1, there is at least 1 byte at the end of
* the buffer where the read would have gone. */
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
return fb_return_string(p_fb, p_type_found, p_fbobj);
return fb_return_string(p_fb, p_fbstr);
}
p_data_cur = p_fb->p_data_cur; /* Update after fill */
p_data_end = p_fb->p_data_end;
@ -306,8 +286,7 @@ int fbget_quoted_unescaped_string(FILEBUF *p_fb,
/* Get a quoted string with an escape. The start has already been set on
* entry */
static int fbget_quoted_escaped_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
static int fbget_quoted_escaped_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Step through characters until end */
char *p_data_src = p_fb->p_data_cur; /* at current char */
@ -325,7 +304,7 @@ static int fbget_quoted_escaped_string(FILEBUF *p_fb,
if (ch_cur == '"') { /* Closing quote, so done */
p_fb->p_data_cur = p_data_src + 1;
*(p_fb->p_obj_end = p_data_dst) = '\0';
return fb_return_string(p_fb, p_type_found, p_fbobj);
return fb_return_string(p_fb, p_fbstr);
}
if (ch_cur == '\\') { /* Escape */
f_escape_in_progress = true;
@ -344,8 +323,7 @@ static int fbget_quoted_escaped_string(FILEBUF *p_fb,
/* If no pending escape, can switch back to unescaped version and
* avoid the moves */
if (!f_escape_in_progress) {
return fbget_quoted_unescaped_string(p_fb, p_type_found,
p_fbobj);
return fbget_quoted_unescaped_string(p_fb, p_fbstr);
}
/* Else escape must be processed, so continue with escaped version */
@ -359,7 +337,7 @@ static int fbget_quoted_escaped_string(FILEBUF *p_fb,
* did not return -1, there is at least 1 byte at the end of
* the buffer where the read would have gone. */
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
return fb_return_string(p_fb, p_type_found, p_fbobj);
return fb_return_string(p_fb, p_fbstr);
}
p_data_dst = p_data_src = p_fb->p_data_cur; /* Update after fill */
p_data_end = p_fb->p_data_end;
@ -369,9 +347,7 @@ static int fbget_quoted_escaped_string(FILEBUF *p_fb,
/* Get an unquoted string starting at the current position */
static int fbget_unquoted_string(FILEBUF *p_fb,
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
static int fbget_unquoted_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
/* Save the start of the string as the current position */
p_fb->p_obj_start = p_fb->p_data_cur;
@ -397,8 +373,7 @@ static int fbget_unquoted_string(FILEBUF *p_fb,
*(p_fb->p_obj_end = p_data_cur) = '\0';
p_fb->p_data_cur = p_data_cur + 1; /* 1st char past string */
p_fb->f_skip_to_eol = map_cur < 0;
return fb_return_obj(p_fb, n_type_wanted, p_type_wanted,
p_type_found, p_fbobj);
return fb_return_string(p_fb, p_fbstr);
}
/* Else more of the string */
} /* end of loop over current text */
@ -414,8 +389,7 @@ static int fbget_unquoted_string(FILEBUF *p_fb,
* did not return -1, there is at least 1 byte at the end of
* the buffer where the read would have gone. */
*(p_fb->p_obj_end = p_fb->p_data_cur) = '\0';
return fb_return_obj(p_fb, n_type_wanted, p_type_wanted,
p_type_found, p_fbobj);
return fb_return_string(p_fb, p_fbstr);
}
p_data_cur = p_fb->p_data_cur; /* Update after fill */
p_data_end = p_fb->p_data_end;
@ -619,78 +593,11 @@ static int fb_skip_to_eol(FILEBUF *p_fb)
/* Return the data found in the most preferred format possible */
static int fb_return_obj(FILEBUF *p_fb,
unsigned int n_type_wanted, FBTYPE *p_type_wanted,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
{
const char * const p_obj_start = p_fb->p_obj_start; /* data to convert */
const char * const p_obj_end = p_fb->p_obj_end;
/* Must test for null string separately since strto* does not set
* errno in this case. Aside from that, it can only be returned
* as a string anyhow. */
if (p_obj_start != p_obj_end) { /* have a string besides "" */
unsigned int i;
for (i = 0; i < n_type_wanted; ++i) {
FBTYPE type_cur = p_type_wanted[i];
errno = 0;
if (type_cur == BUF_TYPE_ULONG) {
char *p_end;
unsigned long val = strtoul(p_obj_start, &p_end, 10);
/* Test for processing of full string. Note that checking
* for the end of the string rather than a NULL handles the
* case of an embedded NULL which the latter test would
* not */
if (errno == 0 && p_end == p_obj_end) {
*p_type_found = BUF_TYPE_ULONG;
p_fbobj->ulong_value = val;
return 0;
}
}
else if (type_cur == BUF_TYPE_LONG) {
char *p_end;
long val = strtol(p_obj_start, &p_end, 10);
if (errno == 0 && p_end == p_obj_end) {
*p_type_found = BUF_TYPE_LONG;
p_fbobj->long_value = val;
return 0;
}
}
else if (type_cur == BUF_TYPE_DOUBLE) {
char *p_end;
double val = strtod(p_obj_start, &p_end);
if (errno == 0 && p_end == p_obj_end) {
*p_type_found = BUF_TYPE_DOUBLE;
p_fbobj->dbl_value = val;
return 0;
}
}
else if (type_cur == BUF_TYPE_STRING) {
break; /* exit loop and use default return of string */
}
else { /* unknown type */
print_error("Unknown output data type %d is ignored.",
(int) type_cur);
}
} /* end of loop trying types */
} /* end of case that string is not "" */
/* If no rquested type was converted OK or string requested, return as
* a string */
return fb_return_string(p_fb, p_type_found, p_fbobj);
} /* end of function fb_return_obj */
/* Return string */
static int fb_return_string(FILEBUF *p_fb,
FBTYPE *p_type_found, FBOBJ *p_fbobj)
static int fb_return_string(FILEBUF *p_fb, FBSTRING *p_fbstr)
{
const char *p_data_start =
p_fbobj->str_value.sz = p_fb->p_obj_start;
p_fbobj->str_value.n_char = p_fb->p_obj_end - p_data_start;
*p_type_found = BUF_TYPE_STRING;
const char *p_data_start = p_fbstr->sz = p_fb->p_obj_start;
p_fbstr->n_char = p_fb->p_obj_end - p_data_start;
return 0;
} /* end of function fb_return_string */

View File

@ -10,14 +10,6 @@ typedef struct Filebuf_len_str {
char *sz; /* Start of string */
} FBSTRING;
/* Union for returned value */
typedef union Filebuf_obj {
FBSTRING str_value;
unsigned long ulong_value;
long long_value;
double dbl_value;
} FBOBJ;
/* Structure for getting file data */
typedef struct Filebuf {
FILE *fp; /* handle to file */
@ -50,8 +42,7 @@ typedef enum FBtype {
FILEBUF *fbopen(const char *filename, size_t n_byte_buf_init);
int fbget(FILEBUF *p_fb, unsigned int n_type_wanted, FBTYPE *p_type_wanted,
FBTYPE *p_type_found, FBOBJ *p_fbobj);
int fbget(FILEBUF *p_fb, FBSTRING *p_fbstr);
int fbclose(FILEBUF *fbp);

View File

@ -67,14 +67,12 @@ typedef struct {
char *path_name; /* Pathname read from model path file */
char *spice_name; /* Name of model from ifspec.ifs */
char *cfunc_name; /* Name of C fcn from ifspec.ifs */
unsigned int version; /* version of the code model */
} Model_Info_t;
typedef struct {
char *path_name; /* Pathname read from udn path file */
char *node_name; /* Name of node type */
unsigned int version; /* version of the code model */
} Node_Info_t;
@ -111,10 +109,8 @@ static bool test_for_duplicates(unsigned int n, struct Key_src *p_ks,
static inline void trim_slash(size_t *p_n, char *p);
static int write_CMextrn(int num_models, Model_Info_t *model_info);
static int write_CMinfo(int num_models, Model_Info_t *model_info);
static int write_CMinfo2(int num_models, Model_Info_t *model_info);
static int write_UDNextrn(int num_nodes, Node_Info_t *node_info);
static int write_UDNinfo(int num_nodes, Node_Info_t *node_info);
static int write_UDNinfo2(int num_nodes, Node_Info_t *node_info);
static int write_objects_inc(int num_models, Model_Info_t *model_info,
int num_nodes, Node_Info_t *node_info);
static int read_udn_type_name(const char *path, char **node_name);
@ -192,10 +188,6 @@ void preprocess_lst_files(void)
if(status != 0) {
exit(1);
}
status = write_CMinfo2(num_models, model_info);
if(status != 0) {
exit(1);
}
/* Write out the UDNextrn.h file used to compile SPIinit.c */
status = write_UDNextrn(num_nodes, node_info);
@ -208,10 +200,6 @@ void preprocess_lst_files(void)
if(status != 0) {
exit(1);
}
status = write_UDNinfo2(num_nodes, node_info);
if(status != 0) {
exit(1);
}
/* Write the make_include file used to link the models and */
/* user-defined node functions with the simulator */
@ -249,40 +237,10 @@ int output_paths_from_lst_file(const char *filename)
goto EXITPOINT;
}
bool f_have_path = false; /* do not have a path to store */
FBTYPE fbtype;
FBOBJ fbobj;
FBSTRING fbstr;
for ( ; ; ) { /* Read items until end of file */
/* Get the next path if not found yet */
if (!f_have_path) {
const int rc = fbget(fbp, 0, (FBTYPE *) NULL, &fbtype, &fbobj);
if (rc != 0) {
if (rc == -1) { /* Error */
print_error("ERROR - Unable to read item to buffer");
xrc = -1;
goto EXITPOINT;
}
else { /* +1 -- EOF */
break;
}
} /* end of abnormal case */
/* Remove trailing slash if appended to path */
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
}
/* Output the file that was found */
if (fprintf(stdout, "%s\n", fbobj.str_value.sz) < 0) {
print_error("ERROR - Unable to output path name to stdout: %s",
strerror(errno));
xrc = -1;
goto EXITPOINT;
}
++n_path; /* 1 more path printed OK */
/* Try getting a version. If found, it will be discarded */
FBTYPE type_wanted = BUF_TYPE_ULONG;
const int rc = fbget(fbp, 1, &type_wanted, &fbtype, &fbobj);
const int rc = fbget(fbp, &fbstr);
if (rc != 0) {
if (rc == -1) { /* Error */
print_error("ERROR - Unable to read item to buffer");
@ -294,15 +252,17 @@ int output_paths_from_lst_file(const char *filename)
}
} /* end of abnormal case */
if (fbtype == BUF_TYPE_ULONG) { /* found version number */
f_have_path = false;
}
else { /* it was a string, so it is the next path */
f_have_path = true;
/* Remove trailing slash if appended to path */
trim_slash(&fbstr.n_char, fbstr.sz);
/* Remove trailing slash if appended to path */
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
/* Output the file that was found */
if (fprintf(stdout, "%s\n", fbstr.sz) < 0) {
print_error("ERROR - Unable to output path name to stdout: %s",
strerror(errno));
xrc = -1;
goto EXITPOINT;
}
++n_path; /* 1 more path printed OK */
} /* end of loop reading items into buffer */
EXITPOINT:
@ -377,27 +337,23 @@ static int read_modpath(
}
n_model_info_alloc = N_MODEL_INIT;
bool f_have_path = false; /* do not have a path to store */
FBTYPE fbtype;
FBOBJ fbobj;
FBSTRING fbstr;
for ( ; ; ) { /* Read items until end of file */
/* Get the next path if not found yet */
if (!f_have_path) {
const int rc = fbget(fbp, 0, (FBTYPE *) NULL, &fbtype, &fbobj);
if (rc != 0) {
if (rc == -1) { /* Error */
print_error("ERROR - Unable to read item to buffer");
xrc = -1;
goto EXITPOINT;
}
else { /* +1 -- EOF */
break;
}
} /* end of abnormal case */
const int rc = fbget(fbp, &fbstr);
if (rc != 0) {
if (rc == -1) { /* Error */
print_error("ERROR - Unable to read item to buffer");
xrc = -1;
goto EXITPOINT;
}
else { /* +1 -- EOF */
break;
}
} /* end of abnormal case */
/* Remove trailing slash if appended to path */
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
}
/* Remove trailing slash if appended to path */
trim_slash(&fbstr.n_char, fbstr.sz);
/* Enlarge model array if full */
if (n_model_info_alloc == n_model_info) {
@ -417,44 +373,18 @@ static int read_modpath(
n_model_info;
if ((p_model_info_cur->path_name = (char *) malloc(
fbobj.str_value.n_char + 1)) == (char *) NULL) {
fbstr.n_char + 1)) == (char *) NULL) {
print_error("ERROR - Unable to allocate path name");
xrc = -1;
goto EXITPOINT;
}
strcpy(p_model_info_cur->path_name, fbobj.str_value.sz);
strcpy(p_model_info_cur->path_name, fbstr.sz);
p_model_info_cur->spice_name = (char *) NULL;
p_model_info_cur->cfunc_name = (char *) NULL;
/* Must set before returning due to EOF. */
p_model_info_cur->version = 1;
++n_model_info;
/* Try getting a version */
FBTYPE type_wanted = BUF_TYPE_ULONG;
const int rc = fbget(fbp, 1, &type_wanted, &fbtype, &fbobj);
if (rc != 0) {
if (rc == -1) { /* Error */
print_error("ERROR - Unable to read item to buffer");
xrc = -1;
goto EXITPOINT;
}
else { /* +1 -- EOF */
break;
}
} /* end of abnormal case */
if (fbtype == BUF_TYPE_ULONG) { /* found version number */
f_have_path = false;
p_model_info_cur->version = (unsigned int) fbobj.ulong_value;
}
else { /* it was a string, so it is the next path */
f_have_path = true;
/* Remove trailing slash if appended to path */
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
}
} /* end of loop reading items into buffer */
EXITPOINT:
@ -552,29 +482,24 @@ static int read_udnpath(
}
n_node_info_alloc = N_NODE_INIT;
bool f_have_path = false; /* do not have a path to store */
FBTYPE fbtype;
FBOBJ fbobj;
FBSTRING fbstr;
for ( ; ; ) { /* Read items until end of file */
/* Get the next path if not found yet */
if (!f_have_path) {
const int rc = fbget(fbp, 0, (FBTYPE *) NULL, &fbtype, &fbobj);
if (rc != 0) {
if (rc == -1) { /* Error */
print_error("ERROR - Unable to read item to buffer");
xrc = -1;
goto EXITPOINT;
}
else { /* +1 -- EOF */
break;
}
} /* end of abnormal case */
/* Remove trailing slash if appended to path */
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
}
const int rc = fbget(fbp, &fbstr);
if (rc != 0) {
if (rc == -1) { /* Error */
print_error("ERROR - Unable to read item to buffer");
xrc = -1;
goto EXITPOINT;
}
else { /* +1 -- EOF */
break;
}
} /* end of abnormal case */
/* Remove trailing slash if appended to path */
trim_slash(&fbstr.n_char, fbstr.sz);
/* Enlarge node array if full */
if (n_node_info_alloc == n_node_info) {
@ -594,44 +519,14 @@ static int read_udnpath(
n_node_info;
if ((p_node_info_cur->path_name = (char *) malloc(
fbobj.str_value.n_char + 1)) == (char *) NULL) {
fbstr.n_char + 1)) == (char *) NULL) {
print_error("ERROR - Unable to allocate path name");
xrc = -1;
goto EXITPOINT;
}
strcpy(p_node_info_cur->path_name, fbobj.str_value.sz);
strcpy(p_node_info_cur->path_name, fbstr.sz);
p_node_info_cur->node_name = NULL;
/* Must set before returning due to EOF. */
p_node_info_cur->version = 1;
++n_node_info;
/* Try getting a version */
FBTYPE type_wanted = BUF_TYPE_ULONG;
const int rc = fbget(fbp, 1, &type_wanted, &fbtype, &fbobj);
if (rc != 0) {
if (rc == -1) { /* Error */
print_error("ERROR - Unable to read item to buffer");
xrc = -1;
goto EXITPOINT;
}
else { /* +1 -- EOF */
break;
}
} /* end of abnormal case */
if (fbtype == BUF_TYPE_ULONG) { /* found version number */
f_have_path = false;
p_node_info_cur->version = (unsigned int) fbobj.ulong_value;
}
else { /* it was a string, so it is the next path */
f_have_path = true;
/* Remove trailing slash if appended to path */
trim_slash(&fbobj.str_value.n_char, fbobj.str_value.sz);
}
} /* end of loop reading items into buffer */
EXITPOINT:
@ -1230,10 +1125,7 @@ static int write_CMinfo(
/* Write out the data */
for(i = 0; i < num_models; i++) {
Model_Info_t *p_mi_cur = model_info + i;
if (p_mi_cur->version == 1) {
fprintf(fp, "&%s_info,\n", model_info[i].cfunc_name);
}
fprintf(fp, "&%s_info,\n", model_info[i].cfunc_name);
}
/* Close the file and return */
@ -1249,49 +1141,6 @@ static int write_CMinfo(
static int write_CMinfo2(
int num_models, /* Number of model pathnames */
Model_Info_t *model_info /* Info about each model */
)
{
int i; /* A temporary counter */
FILE *fp; /* File pointer for writing CMinfo.h */
char *filename = (char *) NULL;
/* Open the file to be written */
if ((filename = gen_filename("cminfo2.h", "w")) == (char *) NULL) {
print_error("ERROR - Unable to build path to cminfo2.h");
return -1;
}
fp = fopen(filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening %s for write", filename);
free(filename);
return -1;
}
/* Write out the data */
for (i = 0; i < num_models; i++) {
Model_Info_t *p_mi_cur = model_info + i;
if (p_mi_cur->version <= 2) {
fprintf(fp, "&%s_info,\n", model_info[i].cfunc_name);
}
}
/* Close the file and return */
if (fclose(fp) != 0) {
print_error("ERROR - Problems closing %s", filename);
free(filename);
return -1;
}
free(filename);
return 0;
} /* end of function write_CMinfo2 */
/* *********************************************************************** */
@ -1383,51 +1232,7 @@ static int write_UDNinfo(
/* Write out the data */
for(i = 0; i < num_nodes; i++) {
Node_Info_t *p_ni_cur = node_info + i;
if (p_ni_cur->version == 1) {
fprintf(fp, "&udn_%s_info,\n", p_ni_cur->node_name);
}
}
/* Close the file and return */
if (fclose(fp) != 0) {
print_error("ERROR - Problems closing %s", filename);
free(filename);
return -1;
}
free(filename);
return 0;
} /* end of function write_UDNinfo */
static int write_UDNinfo2(
int num_nodes, /* Number of node pathnames */
Node_Info_t *node_info /* Info about each node */
)
{
int i; /* A temporary counter */
FILE *fp; /* File pointer for writing UDNinfo.h */
char *filename = (char *) NULL;
/* Open the file to be written */
if ((filename = gen_filename("udninfo2.h", "w")) == (char *) NULL) {
print_error("ERROR - Unable to build path to udninfo2.h");
return -1;
}
fp = fopen(filename, "w");
if(fp == NULL) {
print_error("ERROR - Problems opening %s for write", filename);
return -1;
}
/* Write out the data */
for(i = 0; i < num_nodes; i++) {
Node_Info_t *p_ni_cur = node_info + i;
if (p_ni_cur->version <= 2) {
fprintf(fp, "&udn_%s_info,\n", p_ni_cur->node_name);
}
fprintf(fp, "&udn_%s_info,\n", p_ni_cur->node_name);
}
/* Close the file and return */

View File

@ -65,6 +65,12 @@ NON-STANDARD FEATURES
#define DIR_PATHSEP "/"
#endif
/* For WIN32, make strdup become _strdup unless it is defined already,
* as it would be if CRT debugging is being used */
#if defined(_WIN32) && !defined(strdup)
#define strdup _strdup
#endif
/*=== LOCAL VARIABLES & TYPEDEFS =======*/
struct filesource_state {
@ -167,7 +173,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
int count;
/*** allocate static storage for *loc ***/
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = tcalloc_raw(1,
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = calloc(1,
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
cm_message_send("Unable to allocate Local_Data_t "
"in cm_filesource()");
@ -175,14 +181,14 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
}
/* Allocate storage for internal state */
loc->timeinterval = (double *) tcalloc_raw(2, sizeof(double));
loc->amplinterval = (double *) tcalloc_raw(2 * (size_t) size,
loc->timeinterval = (double *) calloc(2, sizeof(double));
loc->amplinterval = (double *) calloc(2 * (size_t) size,
sizeof(double));
loc->state = (struct filesource_state *) tcalloc_raw(1,
loc->state = (struct filesource_state *) calloc(1,
sizeof(struct filesource_state)); /* calloc to null fp */
loc->indata = (struct infiledata *) tmalloc_raw(
loc->indata = (struct infiledata *) malloc(
sizeof(struct infiledata));
loc->indata->datavec = (double *) tmalloc_raw(sizeof(double) *
loc->indata->datavec = (double *) malloc(sizeof(double) *
stepsize * 1000);
/* Check allocations */
@ -212,7 +218,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
lbuffer = getenv("NGSPICE_INPUT_DIR");
if (lbuffer && *lbuffer) {
char *p;
if ((p = (char *) tmalloc_raw(strlen(lbuffer) +
if ((p = (char *) malloc(strlen(lbuffer) +
strlen(DIR_PATHSEP) + strlen(PARAM(file)) + 1)) ==
(char *) NULL) {
cm_message_send("Unable to allocate buffer "
@ -243,7 +249,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
loc->state->atend = 1;
break;
}
if ((cpdel = cp = tstrdup_raw(line)) == (char *) NULL) {
if ((cpdel = cp = strdup(line)) == (char *) NULL) {
cm_message_send("Unable to duplicate string "
"cm_filesource()");
loc->state->atend = 1;
@ -276,7 +282,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
If not, add another 1000*size doubles */
if (count > loc->indata->vecallocated - size) {
loc->indata->vecallocated += size * 1000;
void * const p = trealloc_raw(loc->indata->datavec,
void * const p = realloc(loc->indata->datavec,
sizeof(double) * loc->indata->vecallocated);
if (p == NULL) {
cm_message_printf("cannot allocate enough memory");

View File

@ -1,20 +1,20 @@
#Directory Version
climit 1
divide 1
d_dt 1
gain 1
hyst 1
ilimit 1
int 1
limit 1
mult 1
multi_input_pwl 1
oneshot 2
pwl 2
sine 2
slew 1
square 1
summer 1
s_xfer 2
triangle 1
file_source 2
#Directory
climit
divide
d_dt
gain
hyst
ilimit
int
limit
mult
multi_input_pwl
oneshot
pwl
sine
slew
square
summer
s_xfer
triangle
file_source

View File

@ -253,7 +253,7 @@ void cm_oneshot(ARGS) /* structure holding parms,
cm_analog_alloc(OUTPUT_OLD,sizeof(double));
/*** allocate static storage for *loc ***/
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = tcalloc_raw(1,
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = calloc(1,
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
cm_message_send("Unable to allocate Local_Data_t "
"in cm_oneshot()");
@ -262,13 +262,13 @@ void cm_oneshot(ARGS) /* structure holding parms,
}
/* Allocate storage for breakpoint domain & pulse width values */
if ((x = loc->control = (double *) tcalloc_raw((size_t) cntl_size,
if ((x = loc->control = (double *) calloc((size_t) cntl_size,
sizeof(double))) == (double *) NULL) {
cm_message_send(oneshot_allocation_error);
cm_oneshot_callback(mif_private, MIF_CB_DESTROY);
return;
}
if ((y = loc->pw = (double *) tcalloc_raw((size_t) pw_size,
if ((y = loc->pw = (double *) calloc((size_t) pw_size,
sizeof(double))) == (double *) NULL) {
cm_message_send(oneshot_allocation_error);
cm_oneshot_callback(mif_private, MIF_CB_DESTROY);

View File

@ -297,11 +297,11 @@ void cm_pwl(ARGS) /* structure holding parms,
if (INIT==1) { /* First pass...allocate storage for previous value... */
/* Allocate storage for last_x_value */
last_x_value = (double *) (STATIC_VAR(last_x_value) = tmalloc_raw(
last_x_value = (double *) (STATIC_VAR(last_x_value) = malloc(
sizeof(double)));
x = (double *) (STATIC_VAR(x) = tcalloc_raw((size_t) size,
x = (double *) (STATIC_VAR(x) = calloc((size_t) size,
sizeof(double)));
y = (double *) (STATIC_VAR(y) = tcalloc_raw((size_t) size,
y = (double *) (STATIC_VAR(y) = calloc((size_t) size,
sizeof(double)));
if (last_x_value == (double *) NULL ||
x == (double *) NULL || y == (double *) NULL) {

View File

@ -275,20 +275,20 @@ void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
/* We have to allocate memory and use cm_analog_alloc, because the
* ITP variables are not functional */
integrator = (double **) tcalloc_raw((size_t) den_size,
integrator = (double **) calloc((size_t) den_size,
sizeof(double *));
old_integrator = (double **) tcalloc_raw((size_t) den_size,
old_integrator = (double **) calloc((size_t) den_size,
sizeof(double *));
/* Allocate storage for coefficient values */
den_coefficient = (double **) tcalloc_raw((size_t) den_size,
den_coefficient = (double **) calloc((size_t) den_size,
sizeof(double *));
old_den_coefficient = (double **) tcalloc_raw((size_t) den_size,
old_den_coefficient = (double **) calloc((size_t) den_size,
sizeof(double *));
num_coefficient = (double **) tcalloc_raw((size_t) num_size,
num_coefficient = (double **) calloc((size_t) num_size,
sizeof(double *));
old_num_coefficient = (double **) tcalloc_raw((size_t) num_size,
old_num_coefficient = (double **) calloc((size_t) num_size,
sizeof(double *));
if (integrator == (double **) NULL ||
@ -324,7 +324,7 @@ void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
/* ITP_VAR_SIZE(den) = den_size; */
/* gain = (double *) tcalloc_raw(1, sizeof(double));
/* gain = (double *) calloc(1, sizeof(double));
ITP_VAR(total_gain) = gain;
ITP_VAR_SIZE(total_gain) = 1.0; */

View File

@ -169,7 +169,7 @@ void cm_d_genlut(ARGS)
if (INIT) { /* initial pass */
/* allocate storage for the lookup table */
if ((lookup_table = (Digital_t *) (STATIC_VAR(locdata) = tcalloc_raw(
if ((lookup_table = (Digital_t *) (STATIC_VAR(locdata) = calloc(
(size_t) tablelen, sizeof(Digital_t)))) ==
(Digital_t *) NULL) {
cm_message_send("Unable to allocate Digital_t structure "

View File

@ -135,7 +135,7 @@ void cm_d_lut(ARGS)
if (INIT) { /* initial pass */
/* allocate storage for the lookup table */
if ((lookup_table = (Digital_State_t *) (STATIC_VAR (locdata) =
tcalloc_raw((size_t) tablelen, sizeof(Digital_State_t)))) ==
calloc((size_t) tablelen, sizeof(Digital_State_t)))) ==
(Digital_State_t *) NULL) {
cm_message_send("Unable to allocate Digital_t structure "
"in cm_d_lut()");

View File

@ -277,13 +277,13 @@ void cm_d_osc(ARGS)
/* Allocate storage for breakpoint domain & freq. range values */
x = (double *) tcalloc_raw((size_t) cntl_size, sizeof(double));
x = (double *) calloc((size_t) cntl_size, sizeof(double));
if (!x) {
cm_message_send(d_osc_allocation_error);
return;
}
y = (double *) tcalloc_raw((size_t) freq_size, sizeof(double));
y = (double *) calloc((size_t) freq_size, sizeof(double));
if (!y) {
cm_message_send(d_osc_allocation_error);
txfree(x);

View File

@ -167,7 +167,7 @@ static char *CNVgettok(char **s)
/* allocate space big enough for the whole string */
if ((buf = (char *) tmalloc_raw(strlen(*s) + 1)) == (char *) NULL) {
if ((buf = (char *) malloc(strlen(*s) + 1)) == (char *) NULL) {
cm_message_send("Unable to allocate buffer in CNVgettok()");
return (char *) NULL;
}
@ -213,7 +213,7 @@ static char *CNVgettok(char **s)
{
char * const ret_str = (char *) tmalloc_raw(strlen(buf) + 1);
char * const ret_str = (char *) malloc(strlen(buf) + 1);
if (ret_str == (char *) NULL) {
cm_message_send("Unable to allocate return buffer "
"in CNVgettok()");
@ -751,7 +751,7 @@ static int cm_read_source(FILE *source, Local_Data_t *loc)
s = base_address;
/* set storage space for bits in a row and set them to 0*/
if ((loc->all_data[i] = (char *) tcalloc_raw(
if ((loc->all_data[i] = (char *) calloc(
(size_t) loc->width,
sizeof(char))) == (char *) NULL) {
cm_message_send("Unable to allocate buffer "
@ -936,7 +936,7 @@ void cm_d_source(ARGS)
char *lbuffer, *p;
lbuffer = getenv("NGSPICE_INPUT_DIR");
if (lbuffer && *lbuffer) {
p = (char *) tmalloc_raw(strlen(lbuffer) +
p = (char *) malloc(strlen(lbuffer) +
strlen(DIR_PATHSEP) + strlen(PARAM(input_file)) + 1);
if (p == (char *) NULL) {
cm_message_send("Unable to allocate buffer "
@ -966,7 +966,7 @@ void cm_d_source(ARGS)
}
/*** allocate static storage for *loc ***/
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = tcalloc_raw(1,
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = calloc(1,
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
cm_message_send("Unable to allocate buffer "
"for building file name in cm_d_source()");
@ -994,7 +994,7 @@ void cm_d_source(ARGS)
loc->width = PORT_SIZE(out);
/*** allocate storage for **all_data, & *all_timepoints ***/
if ((loc->all_timepoints = (double *) tcalloc_raw((size_t) i,
if ((loc->all_timepoints = (double *) calloc((size_t) i,
sizeof(double))) == (double *) NULL) {
cm_message_send("Unable to allocate all_timepoints "
"in cm_d_source()");
@ -1002,7 +1002,7 @@ void cm_d_source(ARGS)
STATIC_VAR(locdata) = NULL;
return;
}
if ((loc->all_data = (char **) tcalloc_raw((size_t) i,
if ((loc->all_data = (char **) calloc((size_t) i,
sizeof(char *))) == (char **) NULL) {
cm_message_send("Unable to allocate all_data "
"in cm_d_source()");

View File

@ -209,7 +209,7 @@ static char *CNVgettok(char **s)
/* allocate space big enough for the whole string */
if ((buf = (char *) tmalloc_raw(strlen(*s) + 1)) == (char *) NULL) {
if ((buf = (char *) malloc(strlen(*s) + 1)) == (char *) NULL) {
cm_message_send("Unable to allocate buffer in CNVgettok()");
return (char *) NULL;
}
@ -255,7 +255,7 @@ static char *CNVgettok(char **s)
{
char * const ret_str = (char *) tmalloc_raw(strlen(buf) + 1);
char * const ret_str = (char *) malloc(strlen(buf) + 1);
if (ret_str == (char *) NULL) {
cm_message_send("Unable to allocate return buffer "
"in CNVgettok()");
@ -1804,15 +1804,15 @@ void cm_d_state(ARGS)
/* assign storage for arrays to pointers in states table */
states->state = (int *) tcalloc_raw(
states->state = (int *) calloc(
(size_t) (states->depth + 1), sizeof(int));
states->bits = (short *) tcalloc_raw(
states->bits = (short *) calloc(
(size_t) (states->num_outputs * states->depth / 4 + 1),
sizeof(short));
states->inputs = (short *) tcalloc_raw(
states->inputs = (short *) calloc(
(size_t) (states->num_inputs * states->depth / 8 + 1),
sizeof(short));
states->next_state = (int *) tcalloc_raw(
states->next_state = (int *) calloc(
(size_t) (states->depth + 1), sizeof(int));
if (states->state == (int *) NULL ||
states->bits == (short *) NULL ||

View File

@ -1,29 +1,29 @@
#Directory Version
adc_bridge 1
dac_bridge 1
d_and 1
d_buffer 1
d_dff 1
d_dlatch 1
d_fdiv 1
d_genlut 2
d_inverter 1
d_jkff 1
d_lut 2
d_nand 1
d_nor 1
d_open_c 1
d_open_e 1
d_or 1
d_osc 2
d_pulldown 1
d_pullup 1
d_ram 1
d_source 2
d_srff 1
d_srlatch 1
d_state 2
d_tff 1
d_tristate 1
d_xnor 1
d_xor 1
#Directory
adc_bridge
dac_bridge
d_and
d_buffer
d_dff
d_dlatch
d_fdiv
d_genlut
d_inverter
d_jkff
d_lut
d_nand
d_nor
d_open_c
d_open_e
d_or
d_osc
d_pulldown
d_pullup
d_ram
d_source
d_srff
d_srlatch
d_state
d_tff
d_tristate
d_xnor
d_xor

View File

@ -32,26 +32,14 @@ const SPICEdev * const cmDEVices[] = {
NULL
};
const SPICEdev * const cmDEVices2[] = {
#include "cminfo2.h"
NULL
};
const int cmDEVicesCNT = sizeof(cmDEVices) / sizeof(SPICEdev *) - 1;
const int cmDEVicesCNT2 = sizeof(cmDEVices2) / sizeof(SPICEdev *) - 1;
const Evt_Udn_Info_t * const cmEVTudns[] = {
#include "udninfo.h"
NULL
};
const Evt_Udn_Info_t * const cmEVTudns2[] = {
#include "udninfo2.h"
NULL
};
const int cmEVTudnCNT = sizeof(cmEVTudns) / sizeof(Evt_Udn_Info_t *) - 1;
const int cmEVTudnCNT2 = sizeof(cmEVTudns2) / sizeof(Evt_Udn_Info_t *) - 1;
// Pointer to core info structure containing pointers to core functions.
struct coreInfo_t *coreitf;
@ -91,40 +79,24 @@ CM_EXPORT void *CMdevs(void)
{
return (void *) cmDEVices;
}
CM_EXPORT void *CMdevs2(void)
{
return (void *) cmDEVices2;
}
// This one returns the device count
CM_EXPORT void *CMdevNum(void)
{
return (void *) &cmDEVicesCNT;
}
CM_EXPORT void *CMdevNum2(void)
{
return (void *) &cmDEVicesCNT2;
}
// This one returns the UDN table
CM_EXPORT void *CMudns(void)
{
return (void *) cmEVTudns;
}
CM_EXPORT void *CMudns2(void)
{
return (void *) cmEVTudns2;
}
// This one returns the UDN count
CM_EXPORT void *CMudnNum(void)
{
return (void *) &cmEVTudnCNT;
}
CM_EXPORT void *CMudnNum2(void)
{
return (void *) &cmEVTudnCNT2;
}
// This one returns the pointer to the pointer to the core interface structure
CM_EXPORT void *CMgetCoreItfPtr(void) {
@ -526,11 +498,26 @@ cm_message_printf(const char *fmt, ...)
break;
}
if (p == buf)
p = tmalloc((size_t) size * sizeof(char));
else
p = trealloc(p, (size_t) size * sizeof(char));
}
/* Allocate a larger buffer to prepare for another format attempt */
{
void *p_new;
if (p == buf) { /* was using buffer from stack */
p_new = malloc((size_t) size * sizeof(char));
}
else {
p_new = realloc(p, (size_t) size * sizeof(char));
}
if (p_new == NULL) {
/* allocation failure, so just send the format string */
(void) cm_message_send(fmt);
if (p != buf) {
free(p);
}
return -1;
}
p = (char *) p_new; /* give new allocation to p */
}
} /* end of loop formatting message */
rv = cm_message_send(p);
if (p != buf)
@ -542,48 +529,6 @@ cm_message_printf(const char *fmt, ...)
/**** V E R S I O N 2 A D D I T I O N S ***/
/* Declared in cmproto.h */
const char *ngspice_version(void)
{
return (*coreitf->dllitf_ngspice_version)();
}
/* Wrapper functions around interface function pointers that are used to get
* access to "raw" malloc(), calloc(), and realloc() under mutex protection
* when necessary */
/* Declared in cmproto.h */
void *tmalloc_raw(size_t s)
{
return (*coreitf->dllitf_tmalloc_raw)(s);
}
/* Declared in cmproto.h */
void *tcalloc_raw(size_t n, size_t s)
{
return (*coreitf->dllitf_tcalloc_raw)(n, s);
}
/* Declared in cmproto.h */
void *trealloc_raw(void *ptr, size_t s)
{
return (*coreitf->dllitf_trealloc_raw)(ptr, s);
}
/* Declared in cmproto.h */
char *tstrdup(const char *sz_in)
{
return (*coreitf->dllitf_tstrdup)(sz_in);
} /* end of function tstrdup */
/* Declared in cmproto.h */
char *tstrdup_raw(const char *sz_in)
{
return (*coreitf->dllitf_tstrdup_raw)(sz_in);
} /* end of function tstrdup_raw */
/*
fopen_with_path()
Opens an input file <infile>. Called from d_state, file_source, d_source.
@ -592,8 +537,6 @@ Then searches for (and opens) <infile> an a sequence from
Infile_Path/<infile>
NGSPICE_INPUT_DIR/<infile>, where the path is given by the environmental variable
<infile>, where the path is the current directory
Requires version 2 due to DSTRING, which uses raw allocations.
*/
#define DFLT_BUF_SIZE 256
/* Declared in cmproto.h */

View File

@ -114,7 +114,7 @@ void spice2poly (ARGS)
if(INIT) {
Mif_Inst_Var_Data_t *p = STATIC_VAR_INST(acgains);
p -> size = num_inputs;
if ((p->element = (Mif_Value_t *) tmalloc_raw((size_t) num_inputs *
if ((p->element = (Mif_Value_t *) malloc((size_t) num_inputs *
sizeof(Mif_Value_t))) == (Mif_Value_t *) NULL) {
cm_message_send("Unable to allocate element array "
"in spice2poly()");
@ -139,7 +139,7 @@ void spice2poly (ARGS)
/* Get input values and coefficients to local storage for faster access */
if ((in = (double *) tmalloc_raw((size_t) num_inputs *
if ((in = (double *) malloc((size_t) num_inputs *
sizeof(double))) == (double *) NULL) {
cm_message_send("Unable to allocate array for inputs "
"in spice2poly()");
@ -150,7 +150,7 @@ void spice2poly (ARGS)
num_coefs = PARAM_SIZE(coef);
if ((coef = (double *) tmalloc_raw((size_t) num_coefs *
if ((coef = (double *) malloc((size_t) num_coefs *
sizeof(double))) == (double *) NULL) {
cm_message_send("Unable to allocate array for coef "
"in spice2poly()");
@ -161,7 +161,7 @@ void spice2poly (ARGS)
/* Allocate the array of exponents used in computing the poly terms */
if ((exp = (int *) tmalloc_raw((size_t) num_inputs *
if ((exp = (int *) malloc((size_t) num_inputs *
sizeof(int))) == (int *) NULL) {
cm_message_send("Unable to allocate array for exp "
"in spice2poly()");

View File

@ -1,2 +1,2 @@
#Directory Version
icm_spice2poly 1
#Directory
icm_spice2poly

View File

@ -41,7 +41,7 @@ sf_alloc(int n /* number of elements */,
/* Use calloc so that any internal allocations will be set to NULL to
* facilitate error recovery */
if ((ptr = tcalloc_raw(n, size)) == NULL) {
if ((ptr = calloc(n, size)) == NULL) {
cm_message_printf("%s: cannot allocate %zd bytes : ",
__FILE__, n * size);
return NULL;

View File

@ -1,3 +1,3 @@
#Directory version
table2D 2
table3D 2
#Directory
table2D
table3D

View File

@ -25,7 +25,7 @@ char *CNVgettok(char **s)
/* allocate space big enough for the whole string */
if ((buf = (char *) tmalloc_raw(strlen(*s) + 1)) == (char *) NULL) {
if ((buf = (char *) malloc(strlen(*s) + 1)) == (char *) NULL) {
cm_message_printf("cannot allocate buffer to tokenize");
return (char *) NULL;
}
@ -74,7 +74,7 @@ char *CNVgettok(char **s)
{
char * const ret_str = (char *) tmalloc_raw(strlen(buf) + 1);
char * const ret_str = (char *) malloc(strlen(buf) + 1);
if (ret_str == (char *) NULL) {
return (char *) NULL;
}

View File

@ -303,7 +303,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
/* Allocate static storage for *loc */
if ((loc = (Table2_Data_t *) tcalloc_raw(1,
if ((loc = (Table2_Data_t *) calloc(1,
sizeof(Table2_Data_t))) == (Table2_Data_t *) NULL) {
cm_message_printf("cannot allocate memory for lookup table.");
xrc = -1;
@ -319,7 +319,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
if (!fp) { /* Standard open attempt failed */
const char * const lbuffer = getenv("NGSPICE_INPUT_DIR");
if (lbuffer && *lbuffer) {
char * const p = (char *) tmalloc_raw(strlen(lbuffer) +
char * const p = (char *) malloc(strlen(lbuffer) +
strlen(DIR_PATHSEP) +
strlen(filename) + 1);
if (p == (char *) NULL) {
@ -356,9 +356,9 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
}
/* create string to hold the whole file */
cFile = tcalloc_raw(lFileLen + 1, sizeof(char));
cFile = calloc(lFileLen + 1, sizeof(char));
/* create another string long enough for file manipulation */
cThisLine = tcalloc_raw(lFileLen + 1, sizeof(char));
cThisLine = calloc(lFileLen + 1, sizeof(char));
if (cFile == NULL || cThisLine == NULL) {
cm_message_printf("Insufficient memory to read file %s",
filename);
@ -419,7 +419,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
cnv_get_spice_value(cThisLinePtr, &tmp);
loc->ix = ix = (int) tmp;
/* generate row data structure (x) */
if ((loc->xcol = (double *) tcalloc_raw((size_t) ix,
if ((loc->xcol = (double *) calloc((size_t) ix,
sizeof(double))) == (double *) NULL) {
cm_message_printf("Unable to allocate row structure.");
xrc = -1;
@ -430,7 +430,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
cnv_get_spice_value(cThisLinePtr, &tmp);
loc->iy = iy = (int) tmp;
/* generate column data structure (y) */
if ((loc->ycol = (double *) tcalloc_raw((size_t) iy,
if ((loc->ycol = (double *) calloc((size_t) iy,
sizeof(double))) == (double *) NULL) {
cm_message_printf("Unable to allocate colum structure.");
xrc = -1;
@ -500,7 +500,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
/* create table_data in memory */
/* data [n2][n1] */
if ((loc->table = table_data = (double **) tcalloc_raw((size_t) iy,
if ((loc->table = table_data = (double **) calloc((size_t) iy,
sizeof(double *))) == (double **) NULL) {
cm_message_send("Unable to allocate data table.");
xrc = -1;
@ -510,7 +510,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
{
int i;
for (i = 0; i < iy; i++) {
if ((table_data[i] = (double *) tcalloc_raw((size_t) ix,
if ((table_data[i] = (double *) calloc((size_t) ix,
sizeof(double))) == (double *) NULL) {
cm_message_printf("Unable to allocate data table "
"row %d", i + 1);

View File

@ -331,7 +331,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
/* Allocate static storage for *loc */
if ((loc = (Table3_Data_t *) tcalloc_raw(1,
if ((loc = (Table3_Data_t *) calloc(1,
sizeof(Table3_Data_t))) == (Table3_Data_t *) NULL) {
cm_message_printf("cannot allocate memory for lookup table.");
xrc = -1;
@ -347,7 +347,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
if (!fp) { /* Standard open attempt failed */
const char * const lbuffer = getenv("NGSPICE_INPUT_DIR");
if (lbuffer && *lbuffer) {
char * const p = (char *) tmalloc_raw(strlen(lbuffer) +
char * const p = (char *) malloc(strlen(lbuffer) +
strlen(DIR_PATHSEP) +
strlen(filename) + 1);
if (p == (char *) NULL) {
@ -384,9 +384,9 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
}
/* create string to hold the whole file */
cFile = tcalloc_raw(lFileLen + 1, sizeof(char));
cFile = calloc(lFileLen + 1, sizeof(char));
/* create another string long enough for file manipulation */
cThisLine = tcalloc_raw(lFileLen + 1, sizeof(char));
cThisLine = calloc(lFileLen + 1, sizeof(char));
if (cFile == NULL || cThisLine == NULL) {
cm_message_printf("Insufficient memory to read file %s",
filename);
@ -447,7 +447,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
cnv_get_spice_value(cThisLinePtr, &tmp);
loc->ix = ix = (int) tmp;
/* generate row data structure (x) */
if ((loc->xcol = (double *) tcalloc_raw((size_t) ix,
if ((loc->xcol = (double *) calloc((size_t) ix,
sizeof(double))) == (double *) NULL) {
cm_message_printf("Unable to allocate row structure.");
xrc = -1;
@ -458,7 +458,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
cnv_get_spice_value(cThisLinePtr, &tmp);
loc->iy = iy = (int) tmp;
/* generate column data structure (y) */
if ((loc->ycol = (double *) tcalloc_raw((size_t) iy,
if ((loc->ycol = (double *) calloc((size_t) iy,
sizeof(double))) == (double *) NULL) {
cm_message_printf("Unable to allocate colum structure.");
xrc = -1;
@ -469,7 +469,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
cnv_get_spice_value(cThisLinePtr, &tmp);
loc->iz = iz = (int) tmp;
/* generate column data structure (z) */
if ((loc->zcol = (double *) tcalloc_raw((size_t) iz,
if ((loc->zcol = (double *) calloc((size_t) iz,
sizeof(double))) == (double *) NULL) {
cm_message_printf("Unable to allocate \"z\" structure.");
xrc = -1;
@ -558,7 +558,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
/* create table_data in memory */
/* data [n3][n2][n1] */
if ((loc->table = table_data = (double ***) tcalloc_raw((size_t) iz,
if ((loc->table = table_data = (double ***) calloc((size_t) iz,
sizeof(double **))) == (double ***) NULL) {
cm_message_send("Unable to allocate data table.");
xrc = -1;
@ -568,7 +568,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
{
int i, j;
for (i = 0; i < iz; i++) {
if ((table_data[i] = (double **) tcalloc_raw((size_t) iy,
if ((table_data[i] = (double **) calloc((size_t) iy,
sizeof(double *))) == (double **) NULL) {
cm_message_printf("Unable to allocate data table "
"z=%d",
@ -577,7 +577,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
goto EXITPOINT;
}
for (j = 0; j < iy; j++) {
if ((table_data[i][j] = (double *) tcalloc_raw((size_t) ix,
if ((table_data[i][j] = (double *) calloc((size_t) ix,
sizeof(double))) == (double *) NULL) {
cm_message_printf("Unable to allocate data table "
"z=%d y=%d",

View File

@ -1,12 +1,12 @@
#Directory Version
aswitch 1
capacitor 1
cmeter 1
core 1
inductor 1
lcouple 1
lmeter 1
potentiometer 1
zener 2
memristor 1
sidiode 1
#Directory
aswitch
capacitor
cmeter
core
inductor
lcouple
lmeter
potentiometer
zener
memristor
sidiode

View File

@ -116,7 +116,7 @@ void cm_sidiode(ARGS) /* structure holding parms,
double grev, goff, gon, Va, Vb, Vc, Vd, hEpsilon, hRevepsilon;
/* allocate static storage for *loc */
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = tcalloc_raw(1,
if ((loc = (Local_Data_t *) (STATIC_VAR(locdata) = calloc(1,
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
cm_message_send("Unable to allocate locdata in cm_sidiode().");
}

View File

@ -175,7 +175,7 @@ void cm_zener(ARGS) /* structure holding parms,
/* Allocate storage for frequencies */
if ((previous_voltage = (double *) (STATIC_VAR(previous_voltage) =
tmalloc_raw(sizeof(double)))) == (double *) NULL) {
malloc(sizeof(double)))) == (double *) NULL) {
cm_message_send("Unable to allocate memory for previous "
"voltage in cm_zener()");
return;

View File

@ -1,5 +1,5 @@
#Directory Version
d_to_real 1
real_delay 1
real_gain 1
real_to_v 1
#Directory
d_to_real
real_delay
real_gain
real_to_v