From 3cd81295a87a75f81eddb2cc7f96a576060d721f Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 10 Feb 2018 21:54:39 +0100 Subject: [PATCH] DEVmodDelete(), change API, #2/2, complete the change Instead of searching and then deleting a given device-model, just delete the given model. The search shall be done somewhere else. Don't free the model struct itself, this shall be done by the invoker himself. Don't free the device instrance list, this shall be done by the invoker himself. As a consequence, most DEVmodDelete() functions collapse almost completely. This change is of no consequence, because DEVmodDelete() is currently nowhere used. --- src/include/ngspice/devdefs.h | 4 +- src/include/ngspice/dllitf.h | 2 +- src/include/ngspice/mifproto.h | 4 +- .../devices/adms/admst/ngspiceMODULEext.h.xml | 2 +- .../adms/admst/ngspiceMODULEmdel.c.xml | 30 ++-------- src/xspice/icm/dlmain.c | 6 +- src/xspice/mif/mifdestr.c | 19 ++++-- src/xspice/mif/mifmdelete.c | 58 ++++--------------- 8 files changed, 36 insertions(+), 89 deletions(-) diff --git a/src/include/ngspice/devdefs.h b/src/include/ngspice/devdefs.h index 711751ff2..942ae68ad 100644 --- a/src/include/ngspice/devdefs.h +++ b/src/include/ngspice/devdefs.h @@ -71,8 +71,8 @@ typedef struct SPICEdev { /* subroutine to call on acceptance of a timepoint */ void (*DEVdestroy)(GENmodel**); /* subroutine to destroy all models and instances */ - int (*DEVmodDelete)(GENmodel**,IFuid,GENmodel*); - /* subroutine to delete a model and all instances */ + int (*DEVmodDelete)(GENmodel*); + /* subroutine to delete a model */ int (*DEVdelete)(GENinstance*); /* subroutine to delete an instance */ int (*DEVsetic)(GENmodel*,CKTcircuit*); diff --git a/src/include/ngspice/dllitf.h b/src/include/ngspice/dllitf.h index ea2e14325..1353cdc75 100644 --- a/src/include/ngspice/dllitf.h +++ b/src/include/ngspice/dllitf.h @@ -27,7 +27,7 @@ struct coreInfo_t { int ((*dllitf_MIFtrunc)(GENmodel *, CKTcircuit *, double *)); int ((*dllitf_MIFconvTest)(GENmodel *, CKTcircuit *)); int ((*dllitf_MIFdelete)(GENinstance *)); - int ((*dllitf_MIFmDelete)(GENmodel **, IFuid, GENmodel *)); + int ((*dllitf_MIFmDelete)(GENmodel *)); void ((*dllitf_MIFdestroy)(GENmodel **)); char * ((*dllitf_MIFgettok)(char **)); char * ((*dllitf_MIFget_token)(char **, Mif_Token_Type_t *)); diff --git a/src/include/ngspice/mifproto.h b/src/include/ngspice/mifproto.h index a2e1959a3..cf39adf19 100644 --- a/src/include/ngspice/mifproto.h +++ b/src/include/ngspice/mifproto.h @@ -129,9 +129,7 @@ extern int MIFdelete( ); extern int MIFmDelete( - GENmodel **inModel, - IFuid modname, - GENmodel *model + GENmodel *gen_model ); extern void MIFdestroy( diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml index 086635087..9a8516782 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml @@ -46,7 +46,7 @@ extern int $(module)acLoad(GENmodel *,CKTcircuit*); extern int $(module)convTest(GENmodel *,CKTcircuit*); extern int $(module)delete(GENinstance*); extern int $(module)getic(GENmodel*,CKTcircuit*); -extern int $(module)mDelete(GENmodel**,IFuid,GENmodel*); +extern int $(module)mDelete(GENmodel*); extern int $(module)noise(int,int,GENmodel*,CKTcircuit*,Ndata*,double*); extern int $(module)pzLoad(GENmodel*,CKTcircuit*,SPcomplex*); extern int $(module)trunc(GENmodel*,CKTcircuit*,double*); diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEmdel.c.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEmdel.c.xml index 2dc128974..849aaf938 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEmdel.c.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEmdel.c.xml @@ -45,33 +45,11 @@ #include "ngspice/sperror.h" #include "ngspice/suffix.h" -int $(module)mDelete(GENmodel **inModel, IFuid modname, GENmodel *kill) +int +$(module)mDelete(GENmodel *gen_model) { - $(module)model **model = ($(module)model**)inModel; - $(module)model *modfast =($(module)model*)kill; - $(module)instance *here; - $(module)instance *prev = NULL; - $(module)model **oldmod; - - oldmod = model; - for (; *model; model = &((*model)->$(module)nextModel)) { - if ((*model)->$(module)modName == modname || - (modfast && *model == modfast)) - goto delgot; - oldmod = model; - } - - return(E_NOMOD); - - delgot: - *oldmod = (*model)->$(module)nextModel; /* cut deleted device out of list */ - for (here = (*model)->$(module)instances; here; here = here->$(module)nextInstance) - { if (prev) FREE(prev); - prev = here; - } - if (prev) FREE(prev); - FREE(*model); - return(OK); + NG_IGNORE(gen_model); + return OK; } diff --git a/src/xspice/icm/dlmain.c b/src/xspice/icm/dlmain.c index 9170f0c1f..6dd3732c7 100644 --- a/src/xspice/icm/dlmain.c +++ b/src/xspice/icm/dlmain.c @@ -203,11 +203,9 @@ int MIFdelete( } int MIFmDelete( - GENmodel **inModel, - IFuid modname, - GENmodel *model + GENmodel *gen_model ) { - return (coreitf->dllitf_MIFmDelete)(inModel,modname,model); + return (coreitf->dllitf_MIFmDelete)(gen_model); } void MIFdestroy( diff --git a/src/xspice/mif/mifdestr.c b/src/xspice/mif/mifdestr.c index 73a888493..d9093d75e 100644 --- a/src/xspice/mif/mifdestr.c +++ b/src/xspice/mif/mifdestr.c @@ -63,10 +63,21 @@ void MIFdestroy( /* models from the head of the linked list until */ /* the head is null */ - while(*inModel) { - MIFmDelete(inModel, - (*inModel)->GENmodName, - *inModel); + 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; } diff --git a/src/xspice/mif/mifmdelete.c b/src/xspice/mif/mifmdelete.c index a60adc4ab..e1472696b 100644 --- a/src/xspice/mif/mifmdelete.c +++ b/src/xspice/mif/mifmdelete.c @@ -60,57 +60,19 @@ model structure. It calls MIFdelete as needed to delete all instances of the specified model. */ -int MIFmDelete( - GENmodel **inModel, /* The head of the model list */ - IFuid modname, /* The name of the model to delete */ - GENmodel *kill /* The model structure to be deleted */ -) +int +MIFmDelete(GENmodel *gen_model) { - MIFmodel **model; - MIFmodel *modfast; - MIFmodel **oldmod; - MIFmodel *here = NULL; - - Mif_Boolean_t found; - - int i; - - /* Convert the generic pointers to MIF specific pointers */ - model = (MIFmodel **) inModel; - modfast = (MIFmodel *) kill; - - /* Locate the model by name or pointer and cut it out of the list */ - oldmod = model; - for (found = MIF_FALSE; *model; model = &((*model)->MIFnextModel)) { - if ((*model)->MIFmodName == modname || - (modfast && *model == modfast)) { - here = *model; - *oldmod = (*model)->MIFnextModel; - found = MIF_TRUE; - break; - } - oldmod = model; - } - - if (!found) - return(E_NOMOD); - - while (here->MIFinstances) { - MIFinstance *next_instance = here->MIFinstances->MIFnextInstance; - MIFdelete((GENinstance *) here->MIFinstances); - FREE(here->MIFinstances); - here->MIFinstances = next_instance; - } + MIFmodel *model = (MIFmodel *) gen_model; + int i; /* Free the model params stuff allocated in MIFget_mod */ - for (i = 0; i < here->num_param; i++) { - if (here->param[i]->element) - FREE(here->param[i]->element); - FREE(here->param[i]); + for (i = 0; i < model->num_param; i++) { + if (model->param[i]->element) + FREE(model->param[i]->element); + FREE(model->param[i]); } - FREE(here->param); + FREE(model->param); - /* Free the model and return */ - FREE(here); - return(OK); + return OK; }