DEVdestroy(), change API, #2/2, complete the change, inclusive CKTdestroy()

loop over DEVmodDelete() and DEVdelete() in CKTdestroy()
  instead of doing this business in the DEVdestroy() functions.

As a consequence, most DEVdestroy() functions
  collapse completely.
This commit is contained in:
rlar 2018-02-10 23:03:11 +01:00
parent 1befa488f6
commit 4748c92de9
9 changed files with 31 additions and 72 deletions

View File

@ -69,8 +69,8 @@ typedef struct SPICEdev {
/* ac analysis loading function */
int (*DEVaccept)(CKTcircuit*,GENmodel*);
/* subroutine to call on acceptance of a timepoint */
void (*DEVdestroy)(GENmodel**);
/* subroutine to destroy all models and instances */
void (*DEVdestroy)(void);
/* subroutine to delete device specfic extra data */
int (*DEVmodDelete)(GENmodel*);
/* subroutine to delete a model */
int (*DEVdelete)(GENinstance*);

View File

@ -28,7 +28,7 @@ struct coreInfo_t {
int ((*dllitf_MIFconvTest)(GENmodel *, CKTcircuit *));
int ((*dllitf_MIFdelete)(GENinstance *));
int ((*dllitf_MIFmDelete)(GENmodel *));
void ((*dllitf_MIFdestroy)(GENmodel **));
void ((*dllitf_MIFdestroy)(void));
char * ((*dllitf_MIFgettok)(char **));
char * ((*dllitf_MIFget_token)(char **, Mif_Token_Type_t *));
Mif_Cntl_Src_Type_t ((*dllitf_MIFget_cntl_src_type)(Mif_Port_Type_t, Mif_Port_Type_t));

View File

@ -133,7 +133,7 @@ extern int MIFmDelete(
);
extern void MIFdestroy(
GENmodel **inModel
void
);
extern char *MIFgettok(

View File

@ -37,11 +37,28 @@ CKTdestroy(CKTcircuit *ckt)
}
#endif
for (i=0;i<DEVmaxnum;i++) {
if ( DEVices[i] && DEVices[i]->DEVdestroy && ckt->CKThead[i] ) {
DEVices[i]->DEVdestroy (&(ckt->CKThead[i]));
for (i = 0; i < DEVmaxnum; i++)
if (DEVices[i]) {
GENmodel *model = ckt->CKThead[i];
while (model) {
GENmodel *next_model = model->GENnextModel;
GENinstance *inst = model->GENinstances;
while (inst) {
GENinstance *next_inst = inst->GENnextInstance;
if (DEVices[i]->DEVdelete)
DEVices[i]->DEVdelete(inst);
FREE(inst);
inst = next_inst;
}
if (DEVices[i]->DEVmodDelete)
DEVices[i]->DEVmodDelete(model);
FREE(model);
model = next_model;
}
if (DEVices[i]->DEVdestroy)
DEVices[i]->DEVdestroy();
}
}
for(i=0;i<=ckt->CKTmaxOrder+1;i++){
FREE(ckt->CKTstates[i]);
}

View File

@ -45,23 +45,8 @@
#include &quot;ngspice/suffix.h&quot;
void
$(module)destroy(GENmodel **inModel)
$(module)destroy(void)
{
$(module)model *mod = *($(module)model**) inModel;
while (mod) {
$(module)model *next_mod = mod->$(module)nextModel;
$(module)instance *inst = mod->$(module)instances;
while (inst) {
$(module)instance *next_inst = inst-&gt;$(module)nextInstance;
FREE(inst);
inst = next_inst;
}
FREE(mod);
mod = next_mod;
}
*inModel = NULL;
}
</admst:template>

View File

@ -51,7 +51,7 @@ extern int $(module)noise(int,int,GENmodel*,CKTcircuit*,Ndata*,double*);
extern int $(module)pzLoad(GENmodel*,CKTcircuit*,SPcomplex*);
extern int $(module)trunc(GENmodel*,CKTcircuit*,double*);
extern int $(module)unsetup(GENmodel*,CKTcircuit*);
extern void $(module)destroy(GENmodel**);
extern void $(module)destroy(void);
#endif

View File

@ -9,25 +9,9 @@ Author: 1987 Kanwar Jit Singh
void
ASRCdestroy(GENmodel **inModel)
ASRCdestroy(void)
{
ASRCmodel *mod = *(ASRCmodel**) inModel;
while (mod) {
ASRCmodel *next_mod = mod->ASRCnextModel;
ASRCinstance *inst = mod->ASRCinstances;
while (inst) {
ASRCinstance *next_inst = inst->ASRCnextInstance;
FREE(inst);
inst = next_inst;
}
FREE(mod);
mod = next_mod;
}
FREE(asrc_vals);
FREE(asrc_derivs);
asrc_nvals = 0;
*inModel = NULL;
}

View File

@ -209,9 +209,9 @@ int MIFmDelete(
}
void MIFdestroy(
GENmodel **inModel
void
) {
(coreitf->dllitf_MIFdestroy)(inModel);
(coreitf->dllitf_MIFdestroy)();
}
char *MIFgettok(

View File

@ -49,35 +49,8 @@ NON-STANDARD FEATURES
/*
MIFdestroy
This function deletes all models and all instances of a specified
device type. It traverses the linked list of model structures
for that type and calls MIFmDelete on each model.
*/
void MIFdestroy(
GENmodel **inModel) /* The head of the list of models to delete */
void MIFdestroy(void)
{
/* Free all models of this device type by removing */
/* models from the head of the linked list until */
/* the head is null */
GENmodel *model = *inModel;
while (model) {
GENmodel *next_model = model->GENnextModel;
GENinstance *inst = model->GENinstances;
while (inst) {
GENinstance *next_instance = inst->GENnextInstance;
MIFdelete(inst);
FREE(inst);
inst = next_instance;
}
MIFmDelete(model);
FREE(model);
model = next_model;
}
*inModel = NULL;
}