From 89d90c21dba1e70f39aaa1058b1e3e1e0436a6a9 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sat, 17 Jun 2023 23:58:35 +0200 Subject: [PATCH] xctx->sch made an array of pointers instead of array of PATH_MAX strings (memory saver) --- src/actions.c | 6 +++--- src/callback.c | 15 ++------------- src/font.c | 2 +- src/save.c | 10 +++++----- src/spice_netlist.c | 4 ++-- src/tedax_netlist.c | 2 +- src/verilog_netlist.c | 2 +- src/vhdl_netlist.c | 2 +- src/xinit.c | 3 ++- src/xschem.h | 2 +- 10 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/actions.c b/src/actions.c index 43f66d04..d911cc45 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1884,7 +1884,7 @@ void go_back(int confirm) /* 20171006 add confirm */ load_sym_def(xctx->sch[xctx->currsch], NULL); from_embedded_sym=1; } - my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); + my_free(_ALLOC_ID_, &xctx->sch[xctx->currsch]); if(xctx->portmap[xctx->currsch].table) str_hash_free(&xctx->portmap[xctx->currsch]); xctx->sch_path_hash[xctx->currsch] = 0; @@ -1935,7 +1935,7 @@ void clear_schematic(int cancel, int symbol) else my_snprintf(name, S(name), "%s-%d.sym", "untitled", i); if(stat(name, &buf)) break; } - my_snprintf(xctx->sch[xctx->currsch], S(xctx->sch[xctx->currsch]), "%s/%s", pwd_dir, name); + my_mstrcat(_ALLOC_ID_, &xctx->sch[xctx->currsch], pwd_dir, "/", name, NULL); my_strncpy(xctx->current_name, name, S(xctx->current_name)); } else { xctx->netlist_type = CAD_SPICE_NETLIST; @@ -1945,7 +1945,7 @@ void clear_schematic(int cancel, int symbol) else my_snprintf(name, S(name), "%s-%d.sch", "untitled", i); if(stat(name, &buf)) break; } - my_snprintf(xctx->sch[xctx->currsch], S(xctx->sch[xctx->currsch]), "%s/%s", pwd_dir, name); + my_mstrcat(_ALLOC_ID_, &xctx->sch[xctx->currsch], pwd_dir, "/", name, NULL); my_strncpy(xctx->current_name, name, S(xctx->current_name)); } draw(); diff --git a/src/callback.c b/src/callback.c index 79bbab95..3c7517de 100644 --- a/src/callback.c +++ b/src/callback.c @@ -2041,18 +2041,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } if(0 && (key=='u') && (state==ControlMask)) /* testmode */ { - int mult; - remove_symbol(2); - link_symbols_to_instances(-1); - expandlabel("/RST", &mult); - expandlabel("/CCC[3:0]", &mult); - expandlabel("CCC[AA:BB:DD]", &mult); - expandlabel("CCC[9:1:2]", &mult); - expandlabel("CCC[10:BB:DD]", &mult); - expandlabel("CCC[10..BB..DD]", &mult); - expandlabel("CCC[10..0..2]", &mult); - expandlabel("123", &mult); - expandlabel("123AA", &mult); + dbg(0, "%d\n", sizeof(Xschem_ctx)); break; } if(key=='u' && state==0) /* undo */ @@ -2341,7 +2330,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, check_unique_names(1); break; } - if( 0 && (key==';') && (state & ControlMask) ) /* testmode: for performance testing */ + if( 0 && (key==';') && (state & ControlMask) ) /* testmode */ { break; } diff --git a/src/font.c b/src/font.c index 3f049a32..749b563e 100644 --- a/src/font.c +++ b/src/font.c @@ -60,6 +60,6 @@ void compile_font(void) clear_drawing(); unselect_all(1); xctx->currsch = 0; - my_strncpy(xctx->sch[xctx->currsch], "", S(xctx->sch[xctx->currsch])); + my_free(_ALLOC_ID_, &xctx->sch[xctx->currsch]); } diff --git a/src/save.c b/src/save.c index 0994c162..a88066b0 100644 --- a/src/save.c +++ b/src/save.c @@ -2330,7 +2330,7 @@ int save_schematic(const char *schname) /* 20171020 added return value */ xRect *rect; int rects; - if( strcmp(schname,"") ) my_strncpy(xctx->sch[xctx->currsch], schname, S(xctx->sch[xctx->currsch])); + if( strcmp(schname,"") ) my_strdup2(_ALLOC_ID_, &xctx->sch[xctx->currsch], schname); else return 0; dbg(1, "save_schematic(): currsch=%d name=%s\n",xctx->currsch, schname); dbg(1, "save_schematic(): sch[currsch]=%s\n", xctx->sch[xctx->currsch]); @@ -2443,7 +2443,7 @@ void load_schematic(int load_symbols, const char *fname, int reset_undo, int ale my_snprintf(msg, S(msg), "get_directory {%s}", fname); my_strncpy(xctx->current_dirname, tcleval(msg), S(xctx->current_dirname)); /* local file name */ - my_strncpy(xctx->sch[xctx->currsch], name, S(xctx->sch[xctx->currsch])); + my_strdup2(_ALLOC_ID_, &xctx->sch[xctx->currsch], name); /* local relative reference */ my_strncpy(xctx->current_name, rel_sym_path(name), S(xctx->current_name)); @@ -2460,7 +2460,7 @@ void load_schematic(int load_symbols, const char *fname, int reset_undo, int ale } /* local file name */ - my_strncpy(xctx->sch[xctx->currsch], fname, S(xctx->sch[xctx->currsch])); + my_strdup2(_ALLOC_ID_, &xctx->sch[xctx->currsch], fname); /* local relative reference */ my_strncpy(xctx->current_name, rel_sym_path(fname), S(xctx->current_name)); } else { /* local file specified and not coming from web url */ @@ -2468,7 +2468,7 @@ void load_schematic(int load_symbols, const char *fname, int reset_undo, int ale my_snprintf(msg, S(msg), "get_directory {%s}", fname); my_strncpy(xctx->current_dirname, tcleval(msg), S(xctx->current_dirname)); /* local file name */ - my_strncpy(xctx->sch[xctx->currsch], fname, S(xctx->sch[xctx->currsch])); + my_strdup2(_ALLOC_ID_, &xctx->sch[xctx->currsch], fname); /* local relative reference */ my_strncpy(xctx->current_name, rel_sym_path(fname), S(xctx->current_name)); } @@ -2548,7 +2548,7 @@ void load_schematic(int load_symbols, const char *fname, int reset_undo, int ale } else { my_strncpy(xctx->current_dirname, pwd_dir, S(xctx->current_dirname)); } - my_snprintf(xctx->sch[xctx->currsch], S(xctx->sch[xctx->currsch]), "%s/%s", xctx->current_dirname, name); + my_mstrcat(_ALLOC_ID_, &xctx->sch[xctx->currsch], xctx->current_dirname, "/", name, NULL); if(reset_undo) set_modify(0); } check_collapsing_objects(); diff --git a/src/spice_netlist.c b/src/spice_netlist.c index b9a30ca2..d934649e 100644 --- a/src/spice_netlist.c +++ b/src/spice_netlist.c @@ -116,7 +116,7 @@ void hier_psprint(char **res, int what) /* netlister driver */ my_free(_ALLOC_ID_, &abs_path); str_hash_free(&subckt_table); my_free(_ALLOC_ID_, &subckt_name); - my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); + my_free(_ALLOC_ID_, &xctx->sch[xctx->currsch]); xctx->currsch--; unselect_all(1); xctx->pop_undo(4, 0); @@ -430,7 +430,7 @@ int global_spice_netlist(int global) /* netlister driver */ /* get_additional_symbols(0); */ my_free(_ALLOC_ID_, &subckt_name); /*clear_drawing(); */ - my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); + my_free(_ALLOC_ID_, &xctx->sch[xctx->currsch]); xctx->currsch--; unselect_all(1); dbg(1, "global_spice_netlist(): invoking pop_undo(0, 0)\n"); diff --git a/src/tedax_netlist.c b/src/tedax_netlist.c index 7d3a2d21..e1e38d55 100644 --- a/src/tedax_netlist.c +++ b/src/tedax_netlist.c @@ -229,7 +229,7 @@ int global_tedax_netlist(int global) /* netlister driver */ str_hash_free(&subckt_table); my_free(_ALLOC_ID_, &subckt_name); /*clear_drawing(); */ - my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); + my_free(_ALLOC_ID_, &xctx->sch[xctx->currsch]); xctx->currsch--; unselect_all(1); xctx->pop_undo(4, 0); diff --git a/src/verilog_netlist.c b/src/verilog_netlist.c index 44bffd15..ce3d47e7 100644 --- a/src/verilog_netlist.c +++ b/src/verilog_netlist.c @@ -357,7 +357,7 @@ int global_verilog_netlist(int global) /* netlister driver */ /* get_additional_symbols(0); */ str_hash_free(&subckt_table); my_free(_ALLOC_ID_, &subckt_name); - my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); + my_free(_ALLOC_ID_, &xctx->sch[xctx->currsch]); xctx->currsch--; unselect_all(1); xctx->pop_undo(4, 0); diff --git a/src/vhdl_netlist.c b/src/vhdl_netlist.c index 4549b060..82bfea05 100644 --- a/src/vhdl_netlist.c +++ b/src/vhdl_netlist.c @@ -446,7 +446,7 @@ int global_vhdl_netlist(int global) /* netlister driver */ /* get_additional_symbols(0); */ str_hash_free(&subckt_table); my_free(_ALLOC_ID_, &subckt_name); - my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); + my_free(_ALLOC_ID_, &xctx->sch[xctx->currsch]); xctx->currsch--; unselect_all(1); xctx->pop_undo(4, 0); diff --git a/src/xinit.c b/src/xinit.c index 0f60f968..77525dc9 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -365,6 +365,7 @@ static void free_xschem_data() my_free(_ALLOC_ID_, &xctx->sel_array); for(i=0;iportmap[i].table) str_hash_free(&xctx->portmap[i]); + if(xctx->sch[i]) my_free(_ALLOC_ID_, &xctx->sch[i]); if(xctx->sch_path[i]) my_free(_ALLOC_ID_, &xctx->sch_path[i]); if(xctx->hier_attr[i].templ) my_free(_ALLOC_ID_, &xctx->hier_attr[i].templ); if(xctx->hier_attr[i].prop_ptr) my_free(_ALLOC_ID_, &xctx->hier_attr[i].prop_ptr); @@ -550,7 +551,7 @@ static void alloc_xschem_data(const char *top_path, const char *win_path) xctx->hilight_nets = 0; xctx->hilight_color = 0; for(i=0;isch[i][0] = '\0'; + xctx->sch[i] = NULL; xctx->sch_path[i]=NULL; xctx->sch_path_hash[i]=0; xctx->hier_attr[i].prop_ptr = NULL; diff --git a/src/xschem.h b/src/xschem.h index 47fa7984..d482f7f8 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -850,7 +850,7 @@ typedef struct { char *schvhdlprop; char *schsymbolprop; char *schverilogprop; - char sch[CADMAXHIER][PATH_MAX]; + char *sch[CADMAXHIER]; int currsch; char *version_string; char *header_text; /* header text (license info) placed in the 'v' record after xschem/file version */