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.
This commit is contained in:
parent
b17ee71576
commit
3cd81295a8
|
|
@ -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*);
|
||||
|
|
|
|||
|
|
@ -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 *));
|
||||
|
|
|
|||
|
|
@ -129,9 +129,7 @@ extern int MIFdelete(
|
|||
);
|
||||
|
||||
extern int MIFmDelete(
|
||||
GENmodel **inModel,
|
||||
IFuid modname,
|
||||
GENmodel *model
|
||||
GENmodel *gen_model
|
||||
);
|
||||
|
||||
extern void MIFdestroy(
|
||||
|
|
|
|||
|
|
@ -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*);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
</admst:template>
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue