Manual resolution of some differences with pre-master.

This commit is contained in:
Jim Monte 2020-02-21 14:18:19 -05:00
parent 887b48b9d5
commit e8546ac087
17 changed files with 225 additions and 213 deletions

View File

@ -934,8 +934,7 @@ static void get_physical_processor_count(void)
/* Allocate buffer to get the info */
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX * const buf =
(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *) TMALLOC(
char, n_byte_buf);
(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *) malloc(n_byte_buf);
if (buf == (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *) NULL) {
fprintf(cp_err,
"Unable to allocate a buffer of %lu bytes "

View File

@ -2,8 +2,7 @@
#include "ngspice/dvec.h"
struct dvec *dvec_alloc(
/* not const -- given to non-const struct */ char *name,
struct dvec *dvec_alloc(/* NOT const -- assigned to char */ char *name,
int type, short flags, int length, void *storage)
{
struct dvec * const rv = TMALLOC(struct dvec, 1);

View File

@ -17,32 +17,45 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
void
lincopy(struct dvec *ov, double *newscale, int newlen, struct dvec *oldscale)
{
struct dvec *v;
double *nd;
if (!isreal(ov)) {
fprintf(cp_err, "Warning: %s is not real\n", ov->v_name);
fprintf(cp_err, "Warning: vector %s is a complex vector - "
"complex vectors cannot be interpolated\n",
ov->v_name);
return;
}
if (ov->v_length == 1) {
fprintf(cp_err, "Warning: %s is a scalar - "
"interpolation is not possible\n",
ov->v_name);
return;
}
if (ov->v_length < oldscale->v_length) {
fprintf(cp_err, "Warning: %s is too short\n", ov->v_name);
fprintf(cp_err, "Warning: %s only contains %d points - "
"interpolation is not performed unless there are "
"at least as many points as the scale vector (%d)\n",
ov->v_name, ov->v_length, oldscale->v_length);
return;
}
v = dvec_alloc(copy(ov->v_name),
/* Allocate the vector to receive the linearized data */
struct dvec * const v = dvec_alloc(copy(ov->v_name),
ov->v_type,
ov->v_flags | VF_PERMANENT,
newlen, NULL);
nd = v->v_realdata;
if (!ft_interpolate(ov->v_realdata, nd, oldscale->v_realdata,
oldscale->v_length, newscale, newlen, 1))
{
/* Do interpolation and then add the vector to the current plot. If
* interpolation fails, the vector must be freed. */
if (!ft_interpolate(ov->v_realdata, v->v_realdata, oldscale->v_realdata,
oldscale->v_length, newscale, newlen, 1)) {
fprintf(cp_err, "Error: can't interpolate %s\n", ov->v_name);
dvec_free(v);
return;
}
vec_new(v);
}
} /* end of function lincopy */

View File

@ -407,18 +407,6 @@ char *cp_tildexpand(const char *string)
} /* end of function cp_tildexpand */
/* Say whether the pattern p can match the string s. */
/* MW. Now simply compare strings */
bool cp_globmatch(const char *p, const char *s)
{
return !(strcmp(p, s));
} /* end of function cp_globmatch */
/* This function expands the leading ~ of wl_node. */
static void tilde_expand_word(wordlist *wl_node)
{

View File

@ -79,7 +79,6 @@ extern void cp_pushcontrol(void);
/* glob.c */
extern bool cp_globmatch(const char *p, const char *s);
extern char *cp_tildexpand(const char *string);
extern char cp_cbrac;
extern char cp_ccurl;

View File

@ -75,8 +75,7 @@ struct dveclist {
bool f_own_vector;
};
struct dvec *dvec_alloc(
/* not const -- given to non-const struct */ char *name,
struct dvec *dvec_alloc(/* NOT CONST -- assigned to const */ char *name,
int type, short flags, int length, void *storage);
void dvec_realloc(struct dvec *v, int length, void *storage);
void dvec_extend(struct dvec *v, int length);

View File

@ -172,7 +172,12 @@ extern double x_acosh(double);
extern double x_atanh(double);
#define hypot _hypot
#endif
/////#define strdup _strdup
/* Do not override macro used by CRT debugging */
#ifndef strdup
#define strdup _strdup
#endif
#define unlink _unlink
#define fileno _fileno
#define getcwd _getcwd

View File

@ -63,13 +63,9 @@ struct coreInfo_t *coreitf;
#endif
extern CM_EXPORT void *CMdevs(void);
extern CM_EXPORT void *CMdevs2(void);
extern CM_EXPORT void *CMdevNum(void);
extern CM_EXPORT void *CMdevNum2(void);
extern CM_EXPORT void *CMudns(void);
extern CM_EXPORT void *CMudns2(void);
extern CM_EXPORT void *CMudnNum(void);
extern CM_EXPORT void *CMudnNum2(void);
extern CM_EXPORT void *CMgetCoreItfPtr(void);
@ -472,62 +468,6 @@ void txfree(void *ptr) {
(coreitf->dllitf_txfree)(ptr);
}
/* Declared in cmproto.h */
int
cm_message_printf(const char *fmt, ...)
{
char buf[1024];
char *p = buf;
int size = sizeof(buf);
int rv;
for (;;) {
int nchars;
va_list ap;
va_start(ap, fmt);
nchars = vsnprintf(p, (size_t) size, fmt, ap);
va_end(ap);
if (nchars == -1) { // compatibility to old implementations
size *= 2;
} else if (size < nchars + 1) {
size = nchars + 1;
} else {
break;
}
/* 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)
txfree(p);
return rv;
}
/*
fopen_with_path()
@ -611,3 +551,51 @@ FILE *fopen_with_path(const char *path, const char *mode)
int
cm_message_printf(const char *fmt, ...)
{
char buf[1024];
char *p = buf;
int size = sizeof(buf);
for (;;) {
int nchars;
va_list ap;
va_start(ap, fmt);
nchars = vsnprintf(p, (size_t) size, fmt, ap);
va_end(ap);
if (nchars == -1) { // compatibility to old implementations
size *= 2;
} else if (size < nchars + 1) {
size = nchars + 1;
} else {
break;
}
{
void *p_new;
if (p == buf) {
p_new = tmalloc((size_t) size * sizeof(char));
}
else {
p_new = trealloc(p, (size_t) size * sizeof(char));
}
if (p_new == NULL) { /* Allocation failure, so just print fmt */
cm_message_send(fmt);
if (p != buf) {
free(p);
}
return -1;
}
}
}
const int rv = cm_message_send(p);
if (p != buf)
free(p);
return rv;
}

View File

@ -97,10 +97,10 @@ sf_eno_close (sf_eno ent)
int i;
const int n = ent->order;
for (i = 0; i < n; i++) {
txfree (ent->diff[i]);
free (ent->diff[i]);
}
txfree (ent->diff);
txfree (ent);
free (ent->diff);
free (ent);
}
void

View File

@ -129,10 +129,10 @@ sf_eno2_close (sf_eno2 pnt)
sf_eno_close (pnt->jnt);
for (i2 = 0; i2 < pnt->n2; i2++)
sf_eno_close (pnt->ent[i2]);
txfree (pnt->f);
txfree (pnt->f1);
txfree (pnt->ent);
txfree (pnt);
free (pnt->f);
free (pnt->f1);
free (pnt->ent);
free (pnt);
}
void

View File

@ -115,7 +115,7 @@ EXITPOINT:
if (xrc != 0) {
if (pnt != (sf_eno3) NULL) {
sf_eno3_close(pnt);
txfree(pnt);
free(pnt);
pnt = (sf_eno3) NULL;
}
}
@ -146,14 +146,14 @@ sf_eno3_close(sf_eno3 pnt)
for (i3 = 0; i3 < pnt->n3; i3++) {
for (i2 = 0; i2 < pnt->n2; i2++)
sf_eno_close (pnt->ent[i3][i2]);
txfree(pnt->ent[i3]);
free(pnt->ent[i3]);
}
txfree(pnt->ent);
txfree(pnt->f[0]);
txfree(pnt->f);
txfree(pnt->f1[0]);
txfree(pnt->f1);
txfree(pnt);
free(pnt->ent);
free(pnt->f[0]);
free(pnt->f);
free(pnt->f1[0]);
free(pnt->f1);
free(pnt);
}
void

View File

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

View File

@ -42,7 +42,7 @@ char *CNVgettok(char **s)
case '\0': /* End of string found */
if (buf) {
txfree(buf);
free(buf);
}
return NULL;
@ -79,7 +79,7 @@ char *CNVgettok(char **s)
return (char *) NULL;
}
(void) strcpy(ret_str, buf);
txfree(buf);
free(buf);
return ret_str;
}
} /* end of function CNVgettok */

View File

@ -111,7 +111,67 @@ static void cm_table2D_callback(ARGS, Mif_Callback_Reason_t reason);
extern int findCrossOver(double arr[], int n, double x);
static void free_local_data(Table2_Data_t *loc);
static inline double get_local_diff(int n, double *col, int ind);
static Table2_Data_t *init_local_data(const char *filename, int order);
static Table2_Data_t *init_local_data(const char *filename, int interporder);
/*==============================================================================
FUNCTION cnv_get_spice_value()
AUTHORS
??? Bill Kuhn
MODIFICATIONS
30 Sep 1991 Jeffrey P. Murray
SUMMARY
This function takes as input a string token from a SPICE
deck and returns a floating point equivalent value.
INTERFACES
FILE ROUTINE CALLED
N/A N/A
RETURNED VALUE
Returns the floating point value in pointer *p_value. Also
returns an integer representing successful completion.
GLOBAL VARIABLES
NONE
NON-STANDARD FEATURES
NONE
==============================================================================*/
static void cm_table2D_callback(ARGS,
Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
Table2_Data_t *loc = (Table2_Data_t *) STATIC_VAR(locdata);
if (loc) {
free_local_data(loc);
loc = (Table2_Data_t *) (STATIC_VAR(locdata) = NULL);
}
break;
} /* end of case MIF_CB_DESTROY */
} /* end of switch over reason being called */
} /* end of function cm_table2D_callback */
/*==============================================================================
@ -289,6 +349,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
int xrc = 0;
int ix = 0, /* elements in a row */
iy = 0; /* number of rows */
double **table_data;
double tmp;
FILE *fp = (FILE *) NULL; /* Handle to file */
@ -331,7 +392,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
(void) sprintf(p, "%s%s%s",
lbuffer, DIR_PATHSEP, filename);
fp = fopen(p, "r");
txfree(p);
free(p);
}
}
@ -373,6 +434,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
lFileRead = fread(cFile, sizeof(char), lFileLen, fp);
const int file_error = ferror(fp);
fclose(fp); /* done with file */
fp = (FILE *) NULL;
if (file_error) {
cm_message_printf("Error reading data file %s", filename);
xrc = -1;
@ -447,7 +509,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
goto EXITPOINT;
}
cnv_get_spice_value(token, &loc->xcol[i++]);
txfree(token);
free(token);
token = CNVgettok(&cThisLinePtr);
}
if (i < ix) {
@ -466,7 +528,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
goto EXITPOINT;
}
cnv_get_spice_value(token, &loc->ycol[i++]);
txfree(token);
free(token);
token = CNVgettok(&cThisLinePtr);
}
if (i < iy) {
@ -489,7 +551,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
interporder);
interporder = 2;
}
/* int order : interpolation order,
/* int interporder : interpolation order,
int n1, int n2 : data dimensions */
if ((loc->newtable = sf_eno2_init(
interporder, ix, iy)) == (sf_eno2) NULL) {
@ -573,7 +635,7 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
* structure table_data */
cnv_get_spice_value(token, &tmpval);
table_data[lLineCount - 1][i++] = tmpval;
txfree(token);
free(token);
token = CNVgettok(&cThisLinePtr);
}
if (i < ix) {
@ -591,10 +653,10 @@ static Table2_Data_t *init_local_data(const char *filename, int interporder)
EXITPOINT:
/* free the file and memory allocated */
if (cFile != (char *) NULL) {
txfree(cFile);
free(cFile);
}
if (cThisLine != (char *) NULL) {
txfree(cThisLine);
free(cThisLine);
}
if (fp != (FILE *) NULL) {
(void) fclose(fp);
@ -624,24 +686,16 @@ static void free_local_data(Table2_Data_t *loc)
int i;
int n_y = loc->iy;
for (i = 0; i < n_y; i++) {
txfree(loc->table[i]);
free(loc->table[i]);
}
txfree(loc->table);
free(loc->table);
}
if (loc->xcol != (double *) NULL) {
txfree(loc->xcol);
}
if (loc->ycol != (double *) NULL) {
txfree(loc->ycol);
}
if (loc->newtable != (sf_eno2) NULL) {
sf_eno2_close(loc->newtable);
}
txfree(loc);
free(loc->xcol);
free(loc->ycol);
sf_eno2_close(loc->newtable);
free(loc);
} /* end of function free_local_data */
@ -660,21 +714,3 @@ static inline double get_local_diff(int n, double *col, int ind)
/* This function frees resources when called with reason argument
* MIF_CB_DESTROY */
static void cm_table2D_callback(ARGS, Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
Table2_Data_t *loc = (Table2_Data_t *) STATIC_VAR(locdata);
if (loc) {
free_local_data(loc);
STATIC_VAR(locdata) = NULL;
}
break;
} /* end of case MIF_CB_DESTROY */
} /* end of switch over reason being called */
} /* end of function cm_table2D_callback */

View File

@ -112,9 +112,26 @@ extern double TrilinearInterpolation(double x, double y, double z,
int xind, int yind, int zind, double ***td);
static void cm_table3D_callback(ARGS, Mif_Callback_Reason_t reason);
extern int findCrossOver(double arr[], int n, double x);
static void free_local_data(Table3_Data_t *loc);
static inline double get_local_diff(int n, double *col, int ind);
static Table3_Data_t *init_local_data(const char *filename, int order);
static Table3_Data_t *init_local_data(const char *filename, int interporder);
static void cm_table3D_callback(ARGS,
Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
Table3_Data_t *loc = (Table3_Data_t *) STATIC_VAR(locdata);
if (loc) {
free_local_data(loc);
loc = (Table3_Data_t *) (STATIC_VAR(locdata) = NULL);
}
break;
} /* end of case MIF_CB_DESTROY */
} /* end of switch over reason being called */
} /* end of function cm_table2D_callback */
/*==============================================================================
@ -359,7 +376,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
(void) sprintf(p, "%s%s%s",
lbuffer, DIR_PATHSEP, filename);
fp = fopen(p, "r");
txfree(p);
free(p);
}
}
@ -486,7 +503,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
goto EXITPOINT;
}
cnv_get_spice_value(token, &loc->xcol[i++]);
txfree(token);
free(token);
token = CNVgettok(&cThisLinePtr);
}
if (i < ix) {
@ -505,7 +522,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
goto EXITPOINT;
}
cnv_get_spice_value(token, &loc->ycol[i++]);
txfree(token);
free(token);
token = CNVgettok(&cThisLinePtr);
}
if (i < iy) {
@ -524,7 +541,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
goto EXITPOINT;
}
cnv_get_spice_value(token, &loc->zcol[i++]);
txfree(token);
free(token);
token = CNVgettok(&cThisLinePtr);
}
if (i < iz) {
@ -642,7 +659,7 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
table_data[lTableCount][lLineCount][i++] = tmpval;
txfree(token);
free(token);
token = CNVgettok(&cThisLinePtr);
}
if (i < ix) {
@ -663,10 +680,10 @@ static Table3_Data_t *init_local_data(const char *filename, int interporder)
EXITPOINT:
/* free the file and memory allocated */
if (cFile != (char *) NULL) {
txfree(cFile);
free(cFile);
}
if (cThisLine != (char *) NULL) {
txfree(cThisLine);
free(cThisLine);
}
if (fp != (FILE *) NULL) {
(void) fclose(fp);
@ -684,7 +701,7 @@ EXITPOINT:
/* Free memory allocations in Local_Data_t structure */
/* Free memory allocations in Table3_Data_t structure */
static void free_local_data(Table3_Data_t *loc)
{
if (loc == (Table3_Data_t *) NULL) {
@ -699,29 +716,19 @@ static void free_local_data(Table3_Data_t *loc)
for (i = 0; i < n_z; i++) {
int j;
for (j = 0; j < n_y; j++) {
txfree(loc->table[i][j]);
free(loc->table[i][j]);
}
txfree(loc->table[i]);
free(loc->table[i]);
}
txfree(loc->table);
free(loc->table);
}
if (loc->xcol != (double *) NULL) {
txfree(loc->xcol);
}
if (loc->ycol != (double *) NULL) {
txfree(loc->ycol);
}
if (loc->zcol != (double *) NULL) {
txfree(loc->zcol);
}
if (loc->newtable != (sf_eno3) NULL) {
sf_eno3_close(loc->newtable);
}
txfree(loc);
free(loc->xcol);
free(loc->ycol);
free(loc->zcol);
sf_eno3_close(loc->newtable);
free(loc);
} /* end of function free_local_data */
@ -739,25 +746,6 @@ static inline double get_local_diff(int n, double *col, int ind)
} /* end of function get_local_diff */
/* This function frees resources when called with reason argument
* MIF_CB_DESTROY */
static void cm_table3D_callback(ARGS, Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
Table3_Data_t *loc = (Table3_Data_t *) STATIC_VAR(locdata);
if (loc) {
free_local_data(loc);
STATIC_VAR(locdata) = NULL;
}
break;
} /* end of case MIF_CB_DESTROY */
} /* end of switch over reason being called */
} /* end of function cm_table3D_callback */
/* These includes add functions from extra source code files,
* still using the standard XSPICE procedure of cmpp-ing cfunc.mod
* and then only compiling the resulting *.c file.

View File

@ -1,4 +1,3 @@
#Directory
aswitch
capacitor
cmeter

View File

@ -86,7 +86,22 @@ typedef struct {
/*=== FUNCTION PROTOTYPE DEFINITIONS ===*/
static void cm_sidiode_callback(ARGS, Mif_Callback_Reason_t reason);
/* This function frees resources when called with reason argument
* MIF_CB_DESTROY */
static void cm_sidiode_callback(ARGS, Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
Local_Data_t *loc = (Local_Data_t *) STATIC_VAR(locdata);
if (loc != (Local_Data_t *) NULL) {
txfree(loc);
}
break;
}
}
} /* end of function cm_sidiode_callback */
/*==============================================================================
@ -119,6 +134,7 @@ void cm_sidiode(ARGS) /* structure holding parms,
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().");
return;
}
CALLBACK = cm_sidiode_callback;
@ -232,20 +248,4 @@ void cm_sidiode(ARGS) /* structure holding parms,
/* This function frees resources when called with reason argument
* MIF_CB_DESTROY */
static void cm_sidiode_callback(ARGS, Mif_Callback_Reason_t reason)
{
switch (reason) {
case MIF_CB_DESTROY: {
Local_Data_t *loc = (Local_Data_t *) STATIC_VAR(locdata);
if (loc != (Local_Data_t *) NULL) {
txfree(loc);
}
break;
}
}
} /* end of function cm_sidiode_callback */