auditing of static in-function variables, remove unnecessary, add notes for allowed ones

This commit is contained in:
Stefan Frederik 2021-11-20 02:37:56 +01:00
parent 83746efbe9
commit 9ceb25716e
12 changed files with 51 additions and 53 deletions

View File

@ -110,7 +110,7 @@ void print_version()
void set_snap(double newsnap) /* 20161212 set new snap factor and just notify new value */
{
static double default_snap = -1.0;
static double default_snap = -1.0; /* safe to keep even with multiple schematics, set at program start */
double cs;
cs = tclgetdoublevar("cadsnap");
@ -129,7 +129,7 @@ void set_snap(double newsnap) /* 20161212 set new snap factor and just notify n
void set_grid(double newgrid)
{
static double default_grid = -1.0;
static double default_grid = -1.0; /* safe to keep even with multiple schematics, set at program start */
double cg;
cg = tclgetdoublevar("cadgrid");
@ -179,7 +179,7 @@ const char *rel_sym_path(const char *s)
const char *add_ext(const char *f, const char *ext)
{
static char ff[PATH_MAX];
static char ff[PATH_MAX]; /* safe to keep even with multiple schematics */
char *p;
int i;

View File

@ -122,7 +122,7 @@ void update_conn_cues(int draw_cues, int dr_win)
double timer(int start)
{
/* used only for test mode. No problem with switching schematic context */
static double st, cur, lap;
static double st, cur, lap; /* safe to keep even with multiple schematics */
if(start == 0) return lap = st = (double) clock() / CLOCKS_PER_SEC;
else if(start == 1) {
double prevlap = lap;

View File

@ -22,8 +22,8 @@
#include "xschem.h"
#include <float.h>
static double distance;
static Selected sel;
static double distance; /* safe to keep even with multiple schematics */
static Selected sel; /* safe to keep even with multiple schematics */
void find_closest_net(double mx,double my)
/* returns the net that is closest to the mouse pointer */
@ -124,8 +124,9 @@ void find_closest_net_or_symbol_pin(double mx,double my, double *x, double *y)
xRect box;
short rot, flip;
char *type=NULL;
double curr_dist;
distance = DBL_MAX;
curr_dist = DBL_MAX;
for(i=0;i<xctx->instances;i++) {
x0=xctx->inst[i].x0;
y0=xctx->inst[i].y0;
@ -147,8 +148,8 @@ void find_closest_net_or_symbol_pin(double mx,double my, double *x, double *y)
xx = (x1+x2)/2;
yy = (y1+y2)/2;
dist = (mx - xx) * (mx - xx) + (my - yy) * (my - yy);
if(dist < distance) {
distance = dist;
if(dist < curr_dist) {
curr_dist = dist;
min_dist_x = xx;
min_dist_y = yy;
}
@ -158,16 +159,16 @@ void find_closest_net_or_symbol_pin(double mx,double my, double *x, double *y)
xx=xctx->wire[i].x1;
yy = xctx->wire[i].y1;
dist = (mx - xx) * (mx - xx) + (my - yy) * (my - yy);
if(dist < distance) {
distance = dist;
if(dist < curr_dist) {
curr_dist = dist;
min_dist_x = xx;
min_dist_y = yy;
}
xx=xctx->wire[i].x2;
yy = xctx->wire[i].y2;
dist = (mx - xx) * (mx - xx) + (my - yy) * (my - yy);
if(dist < distance) {
distance = dist;
if(dist < curr_dist) {
curr_dist = dist;
min_dist_x = xx;
min_dist_y = yy;
}

View File

@ -1357,7 +1357,7 @@ void propagate_logic()
int propagate;
struct hilight_hashentry *entry;
int val, newval;
static int map[] = {LOGIC_0, LOGIC_1, LOGIC_X, LOGIC_Z, LOGIC_NOUP};
static const int map[] = {LOGIC_0, LOGIC_1, LOGIC_X, LOGIC_Z, LOGIC_NOUP};
prepare_netlist_structs(0);
if(!xctx->simdata) create_simdata();
@ -1474,7 +1474,7 @@ void logic_set(int value, int num)
char *type;
xRect boundbox;
int big = xctx->wires> 2000 || xctx->instances > 2000 ;
static int map[] = {LOGIC_0, LOGIC_1, LOGIC_X, LOGIC_Z, LOGIC_NOUP};
static const int map[] = {LOGIC_0, LOGIC_1, LOGIC_X, LOGIC_Z, LOGIC_NOUP};
struct hilight_hashentry *entry;
tclsetvar("tclstop", "0");

View File

@ -582,9 +582,9 @@ int get_unnamed_node(int what, int mult,int node)
/* 3: look if node is a global */
int record_global_node(int what, FILE *fp, char *node)
{
static int max_globals=0;
static int size_globals=0;
static char **globals=NULL;
static int max_globals=0; /* safe to keep even with multiple schematics, netlist code always resets data */
static int size_globals=0; /* safe to keep even with multiple schematics, netlist code always resets data */
static char **globals=NULL; /* safe to keep even with multiple schematics, netlist code always resets data */
int i;
if( what==1 || what==3) {
@ -638,7 +638,7 @@ void prepare_netlist_structs(int for_netlist)
char *global_node=NULL;
int inst_mult, pin_mult;
int print_erc;
static int startlevel = 0;
static int startlevel = 0; /* safe to keep even with multiple schematic windows, netlist is not interruptable */
xInstance * const inst = xctx->inst;
int const instances = xctx->instances;
@ -649,8 +649,12 @@ void prepare_netlist_structs(int for_netlist)
free_simdata(); /* invalidate simulation cache */
dbg(1, "prepare_netlist_structs(): extraction\n");
if(xctx->netlist_count == 0 ) startlevel = xctx->currsch;
/* print_erc is 1 the first time prepare_netlist_structs() is called on top level while
* doing the netlist, when netlist of sub blocks is completed and toplevel is reloaded
* a second prepare_netlist_structs() is called to name unnamed nets, in this second call
* print_erc must be set to 0 to avoid double erc printing
*/
print_erc = xctx->netlist_count == 0 || startlevel < xctx->currsch;
if (for_netlist>0) {
my_snprintf(nn, S(nn), "-----------%s", xctx->sch[xctx->currsch]);
statusmsg(nn,2);

View File

@ -64,7 +64,7 @@ void read_record(int firstchar, FILE *fp, int dbg_level)
char *read_line(FILE *fp, int dbg_level)
{
char s[300];
static char ret[300];
static char ret[300]; /* safe to keep even with multiple schematics */
int first = 0, items;
ret[0] = '\0';
@ -91,7 +91,7 @@ const char *random_string(const char *prefix)
static const int random_size=10;
static char str[PATH_MAX]; /* safe even with multiple schematics, if immediately copied */
int prefix_size;
static unsigned short once=1;
static unsigned short once=1; /* safe even with multiple schematics, set once and never changed */
int i;
int idx;
if(once) {
@ -180,9 +180,8 @@ void updatebbox(int count, xRect *boundbox, xRect *tmp)
void save_ascii_string(const char *ptr, FILE *fd, int newline)
{
int c, len, strbuf_pos = 0;
static char *strbuf = NULL;
static int strbuf_size=0;
static char *strbuf = NULL; /* safe even with multiple schematics */
static int strbuf_size=0; /* safe even with multiple schematics */
if(ptr == NULL) {
if( fd == NULL) { /* used to clear static data */
@ -1038,7 +1037,7 @@ void load_schematic(int load_symbols, const char *filename, int reset_undo) /* 2
{
FILE *fd;
char name[PATH_MAX];
static char msg[PATH_MAX+100];
char msg[PATH_MAX+100];
struct stat buf;
int i;
char *top_path;
@ -1165,7 +1164,6 @@ void push_undo(void)
my_snprintf(diff_name, S(diff_name), "%s/undo%d", xctx->undo_dirname, xctx->cur_undo_ptr%MAX_UNDO);
pipe(pd);
if((pid = fork()) ==0) { /* child process */
static char f[PATH_MAX] = "";
close(pd[1]); /* close write side of pipe */
if(!(diff_fd=freopen(diff_name,"w", stdout))) /* redirect stdout to file diff_name */
{
@ -1182,8 +1180,7 @@ void push_undo(void)
close(0); /* close stdin */
dup(pd[0]); /* duplicate read side of pipe to stdin */
#endif
if(!f[0]) my_strncpy(f, "gzip", S(f));
execlp(f, f, "--fast", "-c", NULL); /* replace current process with comand */
execlp("gzip", "gzip", "--fast", "-c", NULL); /* replace current process with comand */
/* never gets here */
fprintf(errfp, "push_undo(): problems with execlp\n");
Tcl_Eval(interp, "exit");
@ -1259,7 +1256,6 @@ void pop_undo(int redo)
my_snprintf(diff_name, S(diff_name), "%s/undo%d", xctx->undo_dirname, xctx->cur_undo_ptr%MAX_UNDO);
pipe(pd);
if((pid = fork())==0) { /* child process */
static char f[PATH_MAX] = "";
close(pd[0]); /* close read side of pipe */
if(!(diff_fd=freopen(diff_name,"r", stdin))) /* redirect stdin from file name */
{
@ -1273,8 +1269,7 @@ void pop_undo(int redo)
close(1); /* close stdout */
dup(pd[1]); /* write side of pipe --> stdout */
#endif
if(!f[0]) my_strncpy(f, "gzip", S(f));
execlp(f, f, "-d", "-c", NULL); /* replace current process with command */
execlp("gzip", "gzip", "-d", "-c", NULL); /* replace current process with command */
/* never gets here */
dbg(1, "pop_undo(): problems with execlp\n");
Tcl_Eval(interp, "exit");
@ -1599,7 +1594,7 @@ void calc_symbol_bbox(int pos)
*/
int load_sym_def(const char *name, FILE *embed_fd)
{
static int recursion_counter=0;
static int recursion_counter=0; /* safe to keep even with multiple schematics, operation not interruptable */
struct Lcc *lcc; /* size = level */
FILE *fd_tmp;
short rot,flip;
@ -2074,7 +2069,7 @@ int load_sym_def(const char *name, FILE *embed_fd)
/* calculate LCC sub-schematic x0, y0, rotation and flip */
if (level > 1) {
short rot, flip;
static int map[4]={0,3,2,1};
static const int map[4]={0,3,2,1};
flip = lcc[level-1].flip;
rot = lcc[level-1].rot;

View File

@ -22,12 +22,9 @@
#include "xschem.h"
static struct hashentry *model_table[HASHSIZE];
static struct hashentry *model_entry;
static struct hashentry *subckt_table[HASHSIZE];
static struct hashentry *model_table[HASHSIZE]; /* safe even with multiple schematics */
static struct hashentry *model_entry; /* safe even with multiple schematics */
static struct hashentry *subckt_table[HASHSIZE]; /* safe even with multiple schematics */
void hier_psprint(void) /* netlister driver */
{
@ -395,7 +392,7 @@ void global_spice_netlist(int global) /* netlister driver */
xctx->netlist_count = 0;
}
static char *model_name_result = NULL;
static char *model_name_result = NULL; /* safe even with multiple schematics */
static char *model_name(const char *m)
{

View File

@ -157,7 +157,7 @@ void hash_all_names(int n)
const char *tcl_hook2(char **res)
{
static char *result = NULL;
static char empty[]="";
static const char empty[]="";
if(res == NULL || *res == NULL) {
my_free(1285, &result);
@ -931,7 +931,7 @@ const char *subst_token(const char *s, const char *tok, const char *new_val)
const char *get_trailing_path(const char *str, int no_of_dir, int skip_ext)
{
static char s[PATH_MAX];
static char s[PATH_MAX]; /* safe to keep even with multiple schematic windows */
size_t len;
int ext_pos, dir_pos, n_ext, n_dir, c, i;
@ -2302,7 +2302,7 @@ const char *net_name(int i, int j, int *multip, int hash_prefix_unnamed_net, int
{
int tmp;
char errstr[2048];
static char unconn[50];
char unconn[50];
char str_node[40]; /* 20161122 overflow safe */
if(xctx->inst[i].node && xctx->inst[i].node[j]!=NULL)
{
@ -2720,9 +2720,9 @@ int isonlydigit(const char *s)
*/
const char *find_nth(const char *str, char sep, int n)
{
static char *result=NULL;
static int result_size = 0;
static char empty[]="";
static char *result=NULL; /* safe to keep even with multiple schematic windows */
static int result_size = 0; /* safe to keep even with multiple schematic windows */
static const char empty[]="";
int i, len;
char *ptr;
int count;
@ -2757,7 +2757,7 @@ const char *find_nth(const char *str, char sep, int n)
/* if s==NULL return emty string */
const char *translate(int inst, const char* s)
{
static char empty[]="";
static const char empty[]="";
static char *result=NULL;
int size=0, tmp;
register int c, state=TOK_BEGIN, space;
@ -3046,7 +3046,7 @@ const char *translate(int inst, const char* s)
const char *translate2(struct Lcc *lcc, int level, char* s)
{
static char empty[]="";
static const char empty[]="";
static char *result = NULL;
int i, size = 0, tmp, save_tok_size;
register int c, state = TOK_BEGIN, space;

View File

@ -21,7 +21,7 @@
*/
#include "xschem.h"
static struct hashentry *subckt_table[HASHSIZE];
static struct hashentry *subckt_table[HASHSIZE]; /* safe even with multiple schematics */
void global_verilog_netlist(int global) /* netlister driver */
{

View File

@ -22,7 +22,8 @@
#include "xschem.h"
static struct hashentry *subckt_table[HASHSIZE];
static struct hashentry *subckt_table[HASHSIZE]; /* safe even with multiple schematics */
void global_vhdl_netlist(int global) /* netlister driver */
{
FILE *fd;

View File

@ -1,4 +1,4 @@
v {xschem version=2.9.7 file_version=1.2}
v {xschem version=3.0.0 file_version=1.2 }
G {}
K {}
V {}

View File

@ -1,4 +1,4 @@
v {xschem version=2.9.9 file_version=1.2 }
v {xschem version=3.0.0 file_version=1.2 }
G {}
K {}
V {}