Browse Source

Store the numparam dicoS structure for each circuit in a list.

Functions to add, remove, retrive dicoS from the list
and to update dicoS, if the circuit has been changed.
Keeping dicoS is necessary because it may be used by measure.
This patch prevents (huge) memory leaks by overwriting
dicoS if multiple calls to the 'source' command are executed.
pre-master-46
h_vogt 10 years ago
committed by Holger Vogt
parent
commit
1066bf0a7b
  1. 3
      src/frontend/inp.c
  2. 3
      src/frontend/numparam/numpaif.h
  3. 34
      src/frontend/numparam/spicenum.c
  4. 4
      src/frontend/runcoms.c
  5. 3
      src/frontend/runcoms2.c
  6. 2
      src/include/ngspice/ftedefs.h

3
src/frontend/inp.c

@ -1057,8 +1057,9 @@ inp_dodeck(
ct->ci_inprogress = FALSE; ct->ci_inprogress = FALSE;
ct->ci_runonce = FALSE; ct->ci_runonce = FALSE;
ct->ci_commands = end; ct->ci_commands = end;
ct->ci_dicos = nupa_add_dicoslist();
/* prevent false reads in multi-threaded ngshared */ /* prevent false reads in multi-threaded ngshared */
#ifndef SHARED_MODULE
#ifndef SHARED_MODULE
if (reuse) if (reuse)
tfree(ct->ci_filename); tfree(ct->ci_filename);
#endif #endif

3
src/frontend/numparam/numpaif.h

@ -23,6 +23,9 @@ extern void nupa_add_param(char *param_name, double value);
extern void nupa_add_inst_param(char *param_name, double value); extern void nupa_add_inst_param(char *param_name, double value);
extern void nupa_copy_inst_dico(void); extern void nupa_copy_inst_dico(void);
extern void nupa_del_dicoS(void); extern void nupa_del_dicoS(void);
extern int nupa_add_dicoslist(void);
extern void nupa_rem_dicoslist(int);
extern void nupa_set_dicoslist(int);
extern int dynMaxckt; /* number of lines in deck after expansion */ extern int dynMaxckt; /* number of lines in deck after expansion */

34
src/frontend/numparam/spicenum.c

@ -297,6 +297,7 @@ static bool inexpansionS = 0; /* flag subckt expansion phase */
static bool incontrolS = 0; /* flag control code sections */ static bool incontrolS = 0; /* flag control code sections */
static bool firstsignalS = 1; static bool firstsignalS = 1;
static dico_t *dicoS = NULL; static dico_t *dicoS = NULL;
static dico_t *dicos_list[100];
static void static void
@ -685,3 +686,36 @@ nupa_signal(int sig)
firstsignalS = 1; firstsignalS = 1;
} }
} }
/* Store dicoS for each circuit loaded.
The return value will be stored in ft_curckt->ci_dicos.
We need to keep dicoS because it may be used by measure. */
int
nupa_add_dicoslist(void)
{
int i;
for (i = 0; i < 100; i++)
if (dicos_list[i] == NULL) {
dicos_list[i] = dicoS;
break;
}
return (i);
}
/* remove dicoS from list if circuit is removed */
void
nupa_rem_dicoslist(int ir)
{
dicos_list[ir] = NULL;
}
/* change dicoS to the active circuit */
void
nupa_set_dicoslist(int ir)
{
dicoS = dicos_list[ir];
}

4
src/frontend/runcoms.c

@ -15,6 +15,8 @@ Modified: 2000 AlansFixes
#include "ngspice/ftedebug.h" #include "ngspice/ftedebug.h"
#include "ngspice/dvec.h" #include "ngspice/dvec.h"
#include "numparam/numpaif.h"
#include "circuits.h" #include "circuits.h"
#include "completion.h" #include "completion.h"
#include "runcoms.h" #include "runcoms.h"
@ -108,6 +110,8 @@ com_scirc(wordlist *wl)
modtab = ft_curckt->ci_modtab; modtab = ft_curckt->ci_modtab;
/* get the database for save, iplot, stop */ /* get the database for save, iplot, stop */
dbs = ft_curckt->ci_dbs; dbs = ft_curckt->ci_dbs;
/* set the numparam dicos structure for use with measure */
nupa_set_dicoslist(ft_curckt->ci_dicos);
} }

3
src/frontend/runcoms2.c

@ -222,6 +222,8 @@ com_remcirc(wordlist *wl)
/* delete numparam data structure dicoS */ /* delete numparam data structure dicoS */
nupa_del_dicoS(); nupa_del_dicoS();
/* delete entry in dicoslist */
nupa_rem_dicoslist(ft_curckt->ci_dicos);
dbfree(ft_curckt->ci_dbs); dbfree(ft_curckt->ci_dbs);
ft_curckt->ci_dbs = NULL; ft_curckt->ci_dbs = NULL;
@ -283,5 +285,6 @@ com_remcirc(wordlist *wl)
if (ft_curckt) { if (ft_curckt) {
modtab = ft_curckt->ci_modtab; modtab = ft_curckt->ci_modtab;
dbs = ft_curckt->ci_dbs; dbs = ft_curckt->ci_dbs;
nupa_set_dicoslist(ft_curckt->ci_dicos);
} }
} }

2
src/include/ngspice/ftedefs.h

@ -56,6 +56,8 @@ struct circ {
JOB *ci_curOpt; /* most recent options anal. for the circuit */ JOB *ci_curOpt; /* most recent options anal. for the circuit */
char *ci_last_an; /* name of last analysis run */ char *ci_last_an; /* name of last analysis run */
int ci_dicos; /* index to the numparam dicoS structure
for this circuit */
struct pt_temper *modtlist; /* all expressions with 'temper' struct pt_temper *modtlist; /* all expressions with 'temper'
in .model lines */ in .model lines */
struct pt_temper *devtlist; /* all expressions with 'temper' struct pt_temper *devtlist; /* all expressions with 'temper'

Loading…
Cancel
Save