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.
This commit is contained in:
rlar 2018-02-13 20:31:49 +01:00
parent e0f1e5a3de
commit c3ed42f486
8 changed files with 17 additions and 81 deletions

View File

@ -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 */

View File

@ -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 **));

View File

@ -125,9 +125,7 @@ extern int MIFconvTest(
);
extern int MIFdelete(
GENmodel *inModel,
IFuid name,
GENinstance **inst
GENinstance *inst
);
extern int MIFmDelete(

View File

@ -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;
}
</admst:template>

View File

@ -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*);

View File

@ -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(

View File

@ -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;
}

View File

@ -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 */