From 4748c92de9c1f6a0976ddfbc85c0729611e06fe6 Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 10 Feb 2018 23:03:11 +0100 Subject: [PATCH] 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. --- src/include/ngspice/devdefs.h | 4 +-- src/include/ngspice/dllitf.h | 2 +- src/include/ngspice/mifproto.h | 2 +- src/spicelib/analysis/cktdest.c | 25 +++++++++++++--- .../adms/admst/ngspiceMODULEdest.c.xml | 17 +---------- .../devices/adms/admst/ngspiceMODULEext.h.xml | 2 +- src/spicelib/devices/asrc/asrcdest.c | 18 +----------- src/xspice/icm/dlmain.c | 4 +-- src/xspice/mif/mifdestr.c | 29 +------------------ 9 files changed, 31 insertions(+), 72 deletions(-) diff --git a/src/include/ngspice/devdefs.h b/src/include/ngspice/devdefs.h index 942ae68ad..0e338e348 100644 --- a/src/include/ngspice/devdefs.h +++ b/src/include/ngspice/devdefs.h @@ -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*); diff --git a/src/include/ngspice/dllitf.h b/src/include/ngspice/dllitf.h index 1353cdc75..a8d950968 100644 --- a/src/include/ngspice/dllitf.h +++ b/src/include/ngspice/dllitf.h @@ -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)); diff --git a/src/include/ngspice/mifproto.h b/src/include/ngspice/mifproto.h index cf39adf19..0aeaa6a4d 100644 --- a/src/include/ngspice/mifproto.h +++ b/src/include/ngspice/mifproto.h @@ -133,7 +133,7 @@ extern int MIFmDelete( ); extern void MIFdestroy( - GENmodel **inModel + void ); extern char *MIFgettok( diff --git a/src/spicelib/analysis/cktdest.c b/src/spicelib/analysis/cktdest.c index 338ca71d8..9573ba79e 100644 --- a/src/spicelib/analysis/cktdest.c +++ b/src/spicelib/analysis/cktdest.c @@ -37,11 +37,28 @@ CKTdestroy(CKTcircuit *ckt) } #endif - for (i=0;iDEVdestroy && 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]); } diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEdest.c.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEdest.c.xml index e15c38ddc..5e5f9b6fd 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEdest.c.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEdest.c.xml @@ -45,23 +45,8 @@ #include "ngspice/suffix.h" 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->$(module)nextInstance; - FREE(inst); - inst = next_inst; - } - FREE(mod); - mod = next_mod; - } - - *inModel = NULL; } diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml index 9a8516782..63ada4f98 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml @@ -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 diff --git a/src/spicelib/devices/asrc/asrcdest.c b/src/spicelib/devices/asrc/asrcdest.c index e95ce3170..9e4a09d3b 100644 --- a/src/spicelib/devices/asrc/asrcdest.c +++ b/src/spicelib/devices/asrc/asrcdest.c @@ -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; } diff --git a/src/xspice/icm/dlmain.c b/src/xspice/icm/dlmain.c index 6dd3732c7..61d591a14 100644 --- a/src/xspice/icm/dlmain.c +++ b/src/xspice/icm/dlmain.c @@ -209,9 +209,9 @@ int MIFmDelete( } void MIFdestroy( - GENmodel **inModel + void ) { - (coreitf->dllitf_MIFdestroy)(inModel); + (coreitf->dllitf_MIFdestroy)(); } char *MIFgettok( diff --git a/src/xspice/mif/mifdestr.c b/src/xspice/mif/mifdestr.c index d9093d75e..0a197aec3 100644 --- a/src/xspice/mif/mifdestr.c +++ b/src/xspice/mif/mifdestr.c @@ -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; }