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 7762002b8c
commit d079bf7b87
9 changed files with 31 additions and 72 deletions

View File

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

View File

@ -28,7 +28,7 @@ struct coreInfo_t {
int ((*dllitf_MIFconvTest)(GENmodel *, CKTcircuit *)); int ((*dllitf_MIFconvTest)(GENmodel *, CKTcircuit *));
int ((*dllitf_MIFdelete)(GENinstance *)); int ((*dllitf_MIFdelete)(GENinstance *));
int ((*dllitf_MIFmDelete)(GENmodel *)); int ((*dllitf_MIFmDelete)(GENmodel *));
void ((*dllitf_MIFdestroy)(GENmodel **)); void ((*dllitf_MIFdestroy)(void));
char * ((*dllitf_MIFgettok)(char **)); char * ((*dllitf_MIFgettok)(char **));
char * ((*dllitf_MIFget_token)(char **, Mif_Token_Type_t *)); 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)); 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( extern void MIFdestroy(
GENmodel **inModel void
); );
extern char *MIFgettok( extern char *MIFgettok(

View File

@ -37,11 +37,28 @@ CKTdestroy(CKTcircuit *ckt)
} }
#endif #endif
for (i=0;i<DEVmaxnum;i++) { for (i = 0; i < DEVmaxnum; i++)
if ( DEVices[i] && DEVices[i]->DEVdestroy && ckt->CKThead[i] ) { if (DEVices[i]) {
DEVices[i]->DEVdestroy (&(ckt->CKThead[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++){ for(i=0;i<=ckt->CKTmaxOrder+1;i++){
FREE(ckt->CKTstates[i]); FREE(ckt->CKTstates[i]);
} }

View File

@ -45,23 +45,8 @@
#include &quot;ngspice/suffix.h&quot; #include &quot;ngspice/suffix.h&quot;
void 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> </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)pzLoad(GENmodel*,CKTcircuit*,SPcomplex*);
extern int $(module)trunc(GENmodel*,CKTcircuit*,double*); extern int $(module)trunc(GENmodel*,CKTcircuit*,double*);
extern int $(module)unsetup(GENmodel*,CKTcircuit*); extern int $(module)unsetup(GENmodel*,CKTcircuit*);
extern void $(module)destroy(GENmodel**); extern void $(module)destroy(void);
#endif #endif

View File

@ -9,25 +9,9 @@ Author: 1987 Kanwar Jit Singh
void 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_vals);
FREE(asrc_derivs); FREE(asrc_derivs);
asrc_nvals = 0; asrc_nvals = 0;
*inModel = NULL;
} }

View File

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

View File

@ -49,35 +49,8 @@ NON-STANDARD FEATURES
/* /*
MIFdestroy 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( void MIFdestroy(void)
GENmodel **inModel) /* The head of the list of models to delete */
{ {
/* 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;
} }