From c3ed42f486235c4e852997cb47d8a3c137f83dad Mon Sep 17 00:00:00 2001 From: rlar Date: Tue, 13 Feb 2018 20:31:49 +0100 Subject: [PATCH] DEVdelete(), change API, #2/2, complete the change Instead of searching and then deleting a given device-instance, just delete the given instance. The search shall be done somewhere else. Don't free the instance struct itself, this shall be done by the invoker. As a consequence most DEVdelete() functions collapse almost completely. This change is of no consequence, because DEVdelete() is currently nowhere used. --- src/include/ngspice/devdefs.h | 2 +- src/include/ngspice/dllitf.h | 2 +- src/include/ngspice/mifproto.h | 4 +- .../devices/adms/admst/ngspiceMODULEdel.c.xml | 24 ++-------- .../devices/adms/admst/ngspiceMODULEext.h.xml | 2 +- src/xspice/icm/dlmain.c | 6 +-- src/xspice/mif/mifdelete.c | 48 ++----------------- src/xspice/mif/mifmdelete.c | 10 ++-- 8 files changed, 17 insertions(+), 81 deletions(-) diff --git a/src/include/ngspice/devdefs.h b/src/include/ngspice/devdefs.h index be1724da1..711751ff2 100644 --- a/src/include/ngspice/devdefs.h +++ b/src/include/ngspice/devdefs.h @@ -73,7 +73,7 @@ typedef struct SPICEdev { /* subroutine to destroy all models and instances */ int (*DEVmodDelete)(GENmodel**,IFuid,GENmodel*); /* subroutine to delete a model and all instances */ - int (*DEVdelete)(GENmodel*,IFuid,GENinstance**); + int (*DEVdelete)(GENinstance*); /* subroutine to delete an instance */ int (*DEVsetic)(GENmodel*,CKTcircuit*); /* routine to pick up device init conds from rhs */ diff --git a/src/include/ngspice/dllitf.h b/src/include/ngspice/dllitf.h index e865c1d8e..ea2e14325 100644 --- a/src/include/ngspice/dllitf.h +++ b/src/include/ngspice/dllitf.h @@ -26,7 +26,7 @@ struct coreInfo_t { int ((*dllitf_MIFmAsk)(CKTcircuit *, GENmodel *, int, IFvalue *)); int ((*dllitf_MIFtrunc)(GENmodel *, CKTcircuit *, double *)); int ((*dllitf_MIFconvTest)(GENmodel *, CKTcircuit *)); - int ((*dllitf_MIFdelete)(GENmodel *, IFuid, GENinstance **)); + int ((*dllitf_MIFdelete)(GENinstance *)); int ((*dllitf_MIFmDelete)(GENmodel **, IFuid, GENmodel *)); void ((*dllitf_MIFdestroy)(GENmodel **)); char * ((*dllitf_MIFgettok)(char **)); diff --git a/src/include/ngspice/mifproto.h b/src/include/ngspice/mifproto.h index cf8e24548..a2e1959a3 100644 --- a/src/include/ngspice/mifproto.h +++ b/src/include/ngspice/mifproto.h @@ -125,9 +125,7 @@ extern int MIFconvTest( ); extern int MIFdelete( - GENmodel *inModel, - IFuid name, - GENinstance **inst + GENinstance *inst ); extern int MIFmDelete( diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEdel.c.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEdel.c.xml index 1cd174dcb..91e67e531 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEdel.c.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEdel.c.xml @@ -45,27 +45,11 @@ #include "ngspice/sperror.h" #include "ngspice/suffix.h" -int $(module)delete(GENmodel *inModel, IFuid name, GENinstance **inInst) +int +$(module)delete(GENinstance *gen_inst) { - $(module)model *model = ($(module)model*)inModel; - $(module)instance **fast =($(module)instance**)inInst; - - $(module)instance **prev = NULL; - $(module)instance *here; - - for (; model; model = model->$(module)nextModel) { - prev = &(model->$(module)instances); - for (here = *prev; here; here = *prev) { - if (here->$(module)name == name || (fast && here == *fast)) { - *prev = here->$(module)nextInstance; - FREE(here); - return(OK); - } - prev = &(here->$(module)nextInstance); - } - } - - return(E_NODEV); + NG_IGNORE(gen_inst); + return OK; } diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml index f7cb5dd5a..086635087 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml @@ -44,7 +44,7 @@ extern int $(module)ask(CKTcircuit *,GENinstance*,int,IFvalue*,IFvalue*); extern int $(module)mAsk(CKTcircuit*,GENmodel *,int, IFvalue*); extern int $(module)acLoad(GENmodel *,CKTcircuit*); extern int $(module)convTest(GENmodel *,CKTcircuit*); -extern int $(module)delete(GENmodel*,IFuid,GENinstance**); +extern int $(module)delete(GENinstance*); extern int $(module)getic(GENmodel*,CKTcircuit*); extern int $(module)mDelete(GENmodel**,IFuid,GENmodel*); extern int $(module)noise(int,int,GENmodel*,CKTcircuit*,Ndata*,double*); diff --git a/src/xspice/icm/dlmain.c b/src/xspice/icm/dlmain.c index 75b1ab341..9170f0c1f 100644 --- a/src/xspice/icm/dlmain.c +++ b/src/xspice/icm/dlmain.c @@ -197,11 +197,9 @@ int MIFconvTest( } int MIFdelete( - GENmodel *inModel, - IFuid name, - GENinstance **inst + GENinstance *inst ) { - return (coreitf->dllitf_MIFdelete)(inModel,name,inst); + return (coreitf->dllitf_MIFdelete)(inst); } int MIFmDelete( diff --git a/src/xspice/mif/mifdelete.c b/src/xspice/mif/mifdelete.c index 8b615133d..890672fae 100644 --- a/src/xspice/mif/mifdelete.c +++ b/src/xspice/mif/mifdelete.c @@ -62,19 +62,8 @@ used by the instance structure. */ int -MIFdelete( - GENmodel *inModel, /* The head of the model list */ - IFuid name, /* The name of the instance to delete */ - GENinstance **inst /* The instance structure to delete */ -) +MIFdelete(GENinstance *gen_inst) { - MIFmodel *model; - MIFinstance **fast; - MIFinstance **prev; - MIFinstance *here=NULL; - - Mif_Boolean_t found; - int i; int j; int k; @@ -83,34 +72,7 @@ MIFdelete( int num_port; int num_inst_var; - /* Convert generic pointers in arg list to MIF specific pointers */ - model = (MIFmodel *) inModel; - fast = (MIFinstance **) inst; - - /*******************************************/ - /* Cut the instance out of the linked list */ - /*******************************************/ - - /* Loop through all models */ - for (found = MIF_FALSE; model; model = model->MIFnextModel) { - prev = &(model->MIFinstances); - /* Loop through all instances of this model */ - for (here = *prev; here; here = here->MIFnextInstance) { - /* If name or pointer matches, cut it out and mark that its found */ - if (here->MIFname == name || (fast && here == *fast)) { - *prev = here->MIFnextInstance; - found = MIF_TRUE; - break; - } - prev = &(here->MIFnextInstance); - } - if (found) - break; - } - - /* Return error if not found */ - if (!found) - return(E_NODEV); + MIFinstance *here = (MIFinstance *) gen_inst; /*******************************************/ /* instance->callback(..., MIF_CB_DESTROY) */ @@ -221,9 +183,5 @@ MIFdelete( if (here->num_conv && here->conv) FREE(here->conv); - - /* Finally, free the instance struct itself */ - FREE(here); - - return(OK); + return OK; } diff --git a/src/xspice/mif/mifmdelete.c b/src/xspice/mif/mifmdelete.c index eebf297ca..a60adc4ab 100644 --- a/src/xspice/mif/mifmdelete.c +++ b/src/xspice/mif/mifmdelete.c @@ -95,13 +95,11 @@ int MIFmDelete( if (!found) return(E_NOMOD); - /* Free the instances under this model if any */ - /* by removing from the head of the linked list */ - /* until the head is null */ while (here->MIFinstances) { - MIFdelete((GENmodel *) here, - here->MIFinstances->MIFname, - (GENinstance **) &(here->MIFinstances)); + MIFinstance *next_instance = here->MIFinstances->MIFnextInstance; + MIFdelete((GENinstance *) here->MIFinstances); + FREE(here->MIFinstances); + here->MIFinstances = next_instance; } /* Free the model params stuff allocated in MIFget_mod */