Fixed bug in memory management when xspice codemodels are used.
This commit is contained in:
parent
122f08d65a
commit
363ffb85e0
25
ChangeLog
25
ChangeLog
|
|
@ -1,3 +1,28 @@
|
|||
2005-08-04 Paolo Nenzi <p.nenzi@ieee.org>
|
||||
|
||||
* Fixed a bug in memory management of xspice/ngspice that caused
|
||||
segmentation fault for codemodels that adds their own states to
|
||||
the state vector. Changes supplied by Hitoshi Tanaka
|
||||
(HDA01055@nifty.com):
|
||||
|
||||
* src/math/ni/niiter.c: removed the first malloc for OldCKTstate0
|
||||
since the number of states can be alteres by xspice code models.
|
||||
This was already addressed in the past but this line remained.
|
||||
|
||||
* src/xspice/mif/mifsetup.c: added MIFunsetup() to conform to spice3f
|
||||
devices model interface (xspice was based on spice3c1).
|
||||
|
||||
* src/xspice/xspice.c, src/xspice/cm/cmexport.c,
|
||||
src/xspice/cmpp/writ_ifs.c: changed the entry corresponding to the
|
||||
unsetup function from NULL to MIFunsetup.
|
||||
|
||||
* src/include/mifproto.h: added prototype for MIFunsetup.
|
||||
|
||||
* src/spicelib/analysis/cktsetup.c: cleared node if initial condition
|
||||
o nodeset are given to fix a segfaults on second run of xspice
|
||||
netlists.
|
||||
|
||||
|
||||
2005-06-30 Paolo Nenzi <p.nenzi@ieee.org>
|
||||
|
||||
* src/frontend/resource.c: added IPC stuff
|
||||
|
|
|
|||
|
|
@ -81,6 +81,11 @@ extern int MIFsetup(
|
|||
int *state
|
||||
);
|
||||
|
||||
extern int MIFunsetup(
|
||||
GENmodel *inModel,
|
||||
CKTcircuit *ckt
|
||||
);
|
||||
|
||||
extern int MIFload(
|
||||
GENmodel *inModel,
|
||||
CKTcircuit *ckt
|
||||
|
|
|
|||
|
|
@ -68,7 +68,9 @@ NIiter(CKTcircuit *ckt, int maxIter)
|
|||
return(error);
|
||||
}
|
||||
}
|
||||
OldCKTstate0=(double *)MALLOC((ckt->CKTnumStates+1)*sizeof(double));
|
||||
|
||||
// OldCKTstate0=(double *)MALLOC((ckt->CKTnumStates+1)*sizeof(double));
|
||||
|
||||
for(;;){
|
||||
ckt->CKTnoncon=0;
|
||||
#ifdef NEWPRED
|
||||
|
|
@ -162,7 +164,7 @@ NIiter(CKTcircuit *ckt, int maxIter)
|
|||
OldCKTstate0=(double *)MALLOC((ckt->CKTnumStates+1)*sizeof(double));
|
||||
for(i=0;i<ckt->CKTnumStates;i++) {
|
||||
*(OldCKTstate0+i) = *(ckt->CKTstate0+i);
|
||||
};
|
||||
}
|
||||
|
||||
startTime = (*(SPfrontEnd->IFseconds))();
|
||||
SMPsolve(ckt->CKTmatrix,ckt->CKTrhs,ckt->CKTrhsSpare);
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ int
|
|||
CKTunsetup(CKTcircuit *ckt)
|
||||
{
|
||||
int i, error, e2;
|
||||
CKTnode *node;
|
||||
|
||||
error = OK;
|
||||
if (!ckt->CKTisSetup)
|
||||
|
|
@ -127,6 +128,13 @@ CKTunsetup(CKTcircuit *ckt)
|
|||
tfree(ckt->CKTstates[i]);
|
||||
}
|
||||
|
||||
/* added by HT 050802*/
|
||||
for(node=ckt->CKTnodes;node;node=node->next){
|
||||
if(node->icGiven || node->nsGiven) {
|
||||
node->ptr=0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<DEVmaxnum;i++) {
|
||||
if ( ((*DEVices[i]).DEVunsetup != NULL) && (ckt->CKThead[i] != NULL) ){
|
||||
e2 = (*((*DEVices[i]).DEVunsetup))(ckt->CKThead[i],ckt);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ struct coreInfo_t coreInfo =
|
|||
MIFgetMod,
|
||||
MIFgetValue,
|
||||
MIFsetup,
|
||||
(int (*)(GENmodel *, CKTcircuit *))empty,
|
||||
MIFunsetup,
|
||||
MIFload,
|
||||
MIFmParam,
|
||||
MIFask,
|
||||
|
|
|
|||
|
|
@ -920,7 +920,7 @@ static void write_SPICEdev(
|
|||
fprintf(fp, "MIFmParam, \n"); /* DEVmodParam */
|
||||
fprintf(fp, "MIFload, \n"); /* DEVload */
|
||||
fprintf(fp, "MIFsetup, \n"); /* DEVsetup */
|
||||
fprintf(fp, "NULL, \n"); /* DEVunsetup */
|
||||
fprintf(fp, "MIFunsetup, \n"); /* DEVunsetup */
|
||||
fprintf(fp, "NULL, \n"); /* DEVpzSetup */
|
||||
fprintf(fp, "NULL, \n"); /* DEVtemperature */
|
||||
fprintf(fp, "MIFtrunc, \n"); /* DEVtrunc */
|
||||
|
|
|
|||
|
|
@ -44,8 +44,6 @@ NON-STANDARD FEATURES
|
|||
|
||||
/* #include "prefix.h" */
|
||||
#include "ngspice.h"
|
||||
#include <stdio.h>
|
||||
//#include "util.h"
|
||||
#include "smpdefs.h"
|
||||
#include "devdefs.h"
|
||||
#include "sperror.h"
|
||||
|
|
@ -61,7 +59,7 @@ NON-STANDARD FEATURES
|
|||
|
||||
extern SPICEdev **DEVices; /* info about all device types */
|
||||
|
||||
|
||||
Mif_Boolean_t mif_UNSET=MIF_TRUE;
|
||||
|
||||
/* define macro for easy creation of matrix entries/pointers for outputs */
|
||||
#define TSTALLOC(ptr,first,second) \
|
||||
|
|
@ -454,3 +452,77 @@ MIFsetup(
|
|||
|
||||
return(OK);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
MIFunsetup(GENmodel *inModel,CKTcircuit *ckt)
|
||||
{
|
||||
MIFmodel *model;
|
||||
MIFinstance *here;
|
||||
Mif_Smp_Ptr_t *smp_data_out;
|
||||
Mif_Smp_Ptr_t *smp_data_cntl;
|
||||
Mif_Port_Type_t type,in_type,out_type;
|
||||
Mif_Cntl_Src_Type_t cntl_src_type;
|
||||
int num_conn,num_port,i,j;
|
||||
|
||||
|
||||
for (model = (MIFmodel *)inModel; model != NULL;
|
||||
model = model->MIFnextModel)
|
||||
{
|
||||
for(here = model->MIFinstances; here != NULL;
|
||||
here = here->MIFnextInstance)
|
||||
{
|
||||
num_conn=here->num_conn;
|
||||
for(i = 0; i < num_conn; i++) {
|
||||
|
||||
// if the connection is null, skip to next connection
|
||||
if(here->conn[i]->is_null) continue;
|
||||
|
||||
// prepare things for convenient access later
|
||||
num_port = here->conn[i]->size;
|
||||
|
||||
// loop through all ports on this connection
|
||||
for(j = 0; j < num_port; j++) {
|
||||
|
||||
// Skip if port is digital or user-defined type
|
||||
type = here->conn[i]->port[j]->type;
|
||||
|
||||
// determine the type of this output port
|
||||
out_type = here->conn[i]->port[j]->type;
|
||||
|
||||
// create a pointer to the smp data for quick access
|
||||
smp_data_out = &(here->conn[i]->port[j]->smp_data);
|
||||
|
||||
// determine the type of this input port
|
||||
in_type = here->conn[i]->port[j]->type;
|
||||
cntl_src_type = MIFget_cntl_src_type(in_type, out_type);
|
||||
|
||||
switch(cntl_src_type)
|
||||
{
|
||||
case MIF_VCVS:
|
||||
case MIF_ICVS:
|
||||
case -1:
|
||||
if(smp_data_out->branch)
|
||||
{
|
||||
CKTdltNNum(ckt, smp_data_out->branch);
|
||||
smp_data_out->branch = 0;
|
||||
}
|
||||
|
||||
if(smp_data_out->ibranch)
|
||||
{
|
||||
CKTdltNNum(ckt, smp_data_out->ibranch);
|
||||
smp_data_out->ibranch = 0;
|
||||
}
|
||||
here->initialized=MIF_FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//printf("MIFunsetup completed.\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ struct coreInfo_t coreInfo =
|
|||
MIFgetMod,
|
||||
MIFgetValue,
|
||||
MIFsetup,
|
||||
(int (*)(GENmodel *, CKTcircuit *))empty,
|
||||
MIFunsetup,
|
||||
MIFload,
|
||||
MIFmParam,
|
||||
MIFask,
|
||||
|
|
|
|||
Loading…
Reference in New Issue