From db1bf8818ad2c15b58db0d3fd1c6991ce68086e7 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Thu, 28 Sep 2023 23:19:14 +0200 Subject: [PATCH] cleanup in usage of new_prop_string() and hash_names() --- src/actions.c | 4 ++-- src/editprop.c | 9 +++++---- src/move.c | 6 +++--- src/paste.c | 1 + src/scheduler.c | 11 +++++++---- src/token.c | 6 ++---- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/actions.c b/src/actions.c index f52abac9..c80c4600 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1205,7 +1205,7 @@ void attach_labels_to_inst(int interactive) /* offloaded from callback.c 201710 if(symname_pin && symname_wire) { rebuild_selected_array(); k = xctx->lastsel; - first_call=1; /* 20171214 for place_symbol--> new_prop_string */ + first_call=1; prepare_netlist_structs(0); for(j=0;jsel_array[j].type==ELEMENT) { found=1; @@ -1417,6 +1417,7 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot if(i!=-1) { + if(first_call) hash_names(-1, XINSERT); check_inst_storage(); if(pos==-1 || pos > xctx->instances) n=xctx->instances; else @@ -1450,7 +1451,6 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot xctx->inst[n].prop_ptr=NULL; xctx->inst[n].instname=NULL; dbg(1, "place_symbol() :all inst_ptr members set\n"); /* 03-02-2000 */ - if(first_call) hash_names(-1, XINSERT); if(inst_props) { new_prop_string(n, inst_props,!first_call, tclgetboolvar("disable_unique_names")); /* 20171214 first_call */ } diff --git a/src/editprop.c b/src/editprop.c index db8df1f3..b7873a7e 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -643,7 +643,7 @@ void set_inst_prop(int i) my_strdup(_ALLOC_ID_, &xctx->inst[i].prop_ptr, ptr); if(get_tok_value(ptr, "name",0)[0]) { my_strdup(_ALLOC_ID_, &tmp, xctx->inst[i].prop_ptr); - new_prop_string(i, tmp, 0, tclgetboolvar("disable_unique_names")); + new_prop_string(i, tmp, 0, tclgetboolvar("disable_unique_names")); /* sets also inst[].instname */ my_free(_ALLOC_ID_, &tmp); } } @@ -1431,9 +1431,11 @@ static int update_symbol(const char *result, int x, int first_sel) /* set unique name of current inst */ if(!pushed) { xctx->push_undo(); pushed=1;} if(!k) hash_names(-1, XINSERT); - new_prop_string(*ii, ptr, k, tclgetboolvar("disable_unique_names")); /* set new prop_ptr */ + hash_names(*ii, XDELETE); + new_prop_string(*ii, ptr, k, /* sets also inst[].instname */ + tclgetboolvar("disable_unique_names")); /* set new prop_ptr */ + hash_names(*ii, XINSERT); } - set_inst_flags(&xctx->inst[*ii]); /* set cached flags in instances */ type=xctx->sym[xctx->inst[*ii].ptr].type; @@ -1444,7 +1446,6 @@ static int update_symbol(const char *result, int x, int first_sel) get_tok_value(xctx->inst[*ii].prop_ptr, "lab",0)); } else xctx->inst[*ii].flags &= ~PIN_OR_LABEL; - } /* end for(k=0;klastsel; ++k) */ if(pushed) modified = 1; diff --git a/src/move.c b/src/move.c index 7904652f..b7c86b14 100644 --- a/src/move.c +++ b/src/move.c @@ -1041,13 +1041,13 @@ void copy_objects(int what) xctx->inst[xctx->instances].rot = (xctx->inst[xctx->instances].rot + ( (xctx->move_flip && (xctx->inst[xctx->instances].rot & 1) ) ? xctx->move_rot+2 : xctx->move_rot) ) & 0x3; xctx->inst[xctx->instances].flip = (xctx->move_flip? !xctx->inst[n].flip:xctx->inst[n].flip); + my_strdup(_ALLOC_ID_, &xctx->inst[xctx->instances].instname, xctx->inst[n].instname); /* the newpropcnt argument is zero for the 1st call and used in */ /* new_prop_string() for cleaning some internal caches. */ if(!newpropcnt) hash_names(-1, XINSERT); - new_prop_string(xctx->instances, xctx->inst[n].prop_ptr,newpropcnt++, + new_prop_string(xctx->instances, xctx->inst[n].prop_ptr,newpropcnt++, /* sets also inst[].instname */ tclgetboolvar("disable_unique_names")); - my_strdup(_ALLOC_ID_, &xctx->inst[xctx->instances].instname, - get_tok_value(xctx->inst[xctx->instances].prop_ptr, "name", 0)); + hash_names(xctx->instances, XINSERT); /* this is needed since no find_inst_to_be_redrawn() is executed if floaters are present */ if(floaters) symbol_bbox(xctx->instances, &xctx->inst[xctx->instances].x1, &xctx->inst[xctx->instances].y1, diff --git a/src/paste.c b/src/paste.c index 30a5f29a..2c729d52 100644 --- a/src/paste.c +++ b/src/paste.c @@ -279,6 +279,7 @@ static void merge_inst(int k,FILE *fd) new_prop_string(i, prop_ptr, k, tclgetboolvar("disable_unique_names")); /* will also assign .instname */ /* the final tmp argument is zero for the 1st call and used in */ /* new_prop_string() for cleaning some internal caches. */ + hash_names(i, XINSERT); my_free(_ALLOC_ID_, &prop_ptr); xctx->instances++; } diff --git a/src/scheduler.c b/src/scheduler.c index 09539bbc..03896182 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -3319,9 +3319,10 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if(prefix) name[0]=(char)prefix; /* change prefix if changing symbol type; */ my_strdup(_ALLOC_ID_, &ptr,subst_token(xctx->inst[inst].prop_ptr, "name", name) ); if(!fast) hash_names(-1, XINSERT); - new_prop_string(inst, ptr, fast, tclgetboolvar("disable_unique_names")); /* set new prop_ptr */ - my_strdup(_ALLOC_ID_, &xctx->inst[inst].instname, get_tok_value(xctx->inst[inst].prop_ptr, "name", 0)); - + hash_names(inst, XDELETE); + new_prop_string(inst, ptr, fast, /* sets also inst[].instname */ + tclgetboolvar("disable_unique_names")); /* set new prop_ptr */ + hash_names(inst, XINSERT); type=xctx->sym[xctx->inst[inst].ptr].type; cond= type && IS_LABEL_SH_OR_PIN(type); if(cond) { @@ -4021,15 +4022,17 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg xctx->prep_hash_inst=0; xctx->prep_net_structs=0; xctx->prep_hi_structs=0; - if(!strcmp(argv[4], "name")) hash_names(-1, XINSERT); + if(!strcmp(argv[4], "name") && fast == 0) hash_names(-1, XINSERT); if(argc > 5) { my_strdup2(_ALLOC_ID_, &subst, subst_token(xctx->inst[inst].prop_ptr, argv[4], argv[5])); } else {/* assume argc == 5 , delete attribute */ my_strdup2(_ALLOC_ID_, &subst, subst_token(xctx->inst[inst].prop_ptr, argv[4], NULL)); } + hash_names(inst, XDELETE); new_prop_string(inst, subst, fast, tclgetboolvar("disable_unique_names")); my_free(_ALLOC_ID_, &subst); set_inst_flags(&xctx->inst[inst]); + hash_names(inst, XINSERT); type=xctx->sym[xctx->inst[inst].ptr].type; cond= type && IS_LABEL_SH_OR_PIN(type); diff --git a/src/token.c b/src/token.c index 5afe5b9c..3febbaca 100644 --- a/src/token.c +++ b/src/token.c @@ -61,6 +61,7 @@ void hash_names(int inst, int action) int i, mult, start, stop; char *upinst = NULL; char *upinst_ptr, *upinst_state, *single_name; + dbg(1, "hash_names(): inst=%d, action=%d\n", inst, action); if(inst == -1) { int_hash_free(&xctx->inst_name_table); int_hash_init(&xctx->inst_name_table, HASHSIZE); @@ -88,7 +89,7 @@ void hash_names(int inst, int action) } } } - my_free(_ALLOC_ID_, &upinst); + if(upinst) my_free(_ALLOC_ID_, &upinst); } @@ -187,7 +188,6 @@ void check_unique_names(int rename) if( (xctx->inst[i].color != -10000)) { my_strdup(_ALLOC_ID_, &tmp, xctx->inst[i].prop_ptr); new_prop_string(i, tmp, newpropcnt++, 0); - my_strdup(_ALLOC_ID_, &xctx->inst[i].instname, get_tok_value(xctx->inst[i].prop_ptr, "name", 0)); hash_names(i, XINSERT); symbol_bbox(i, &xctx->inst[i].x1, &xctx->inst[i].y1, &xctx->inst[i].x2, &xctx->inst[i].y2); bbox(ADD, xctx->inst[i].x1, xctx->inst[i].y1, xctx->inst[i].x2, xctx->inst[i].y2); @@ -795,7 +795,6 @@ void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names) is_used = name_is_used(old_name); if(dis_uniq_names || is_used == -1 || is_used == i) { my_strdup(_ALLOC_ID_, &xctx->inst[i].prop_ptr, old_prop); - hash_names(i, XINSERT); /* add instance 'i' to xctx->inst_name_table */ my_free(_ALLOC_ID_, &old_name); return; } @@ -823,7 +822,6 @@ void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names) if(strcmp(new_prop, old_prop) ) { my_strdup(_ALLOC_ID_, &xctx->inst[i].prop_ptr, new_prop); my_strdup2(_ALLOC_ID_, &xctx->inst[i].instname, new_name); - hash_names(i, XINSERT); } my_free(_ALLOC_ID_, &old_name); my_free(_ALLOC_ID_, &new_name);