Browse Source

Fixed bug in memory management when xspice codemodels are used.

pre-master-46
pnenzi 21 years ago
parent
commit
363ffb85e0
  1. 25
      ChangeLog
  2. 5
      src/include/mifproto.h
  3. 6
      src/maths/ni/niiter.c
  4. 8
      src/spicelib/analysis/cktsetup.c
  5. 2
      src/xspice/cm/cmexport.c
  6. 2
      src/xspice/cmpp/writ_ifs.c
  7. 78
      src/xspice/mif/mifsetup.c
  8. 2
      src/xspice/xspice.c

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> 2005-06-30 Paolo Nenzi <p.nenzi@ieee.org>
* src/frontend/resource.c: added IPC stuff * src/frontend/resource.c: added IPC stuff

5
src/include/mifproto.h

@ -81,6 +81,11 @@ extern int MIFsetup(
int *state int *state
); );
extern int MIFunsetup(
GENmodel *inModel,
CKTcircuit *ckt
);
extern int MIFload( extern int MIFload(
GENmodel *inModel, GENmodel *inModel,
CKTcircuit *ckt CKTcircuit *ckt

6
src/maths/ni/niiter.c

@ -68,7 +68,9 @@ NIiter(CKTcircuit *ckt, int maxIter)
return(error); return(error);
} }
} }
OldCKTstate0=(double *)MALLOC((ckt->CKTnumStates+1)*sizeof(double));
// OldCKTstate0=(double *)MALLOC((ckt->CKTnumStates+1)*sizeof(double));
for(;;){ for(;;){
ckt->CKTnoncon=0; ckt->CKTnoncon=0;
#ifdef NEWPRED #ifdef NEWPRED
@ -162,7 +164,7 @@ NIiter(CKTcircuit *ckt, int maxIter)
OldCKTstate0=(double *)MALLOC((ckt->CKTnumStates+1)*sizeof(double)); OldCKTstate0=(double *)MALLOC((ckt->CKTnumStates+1)*sizeof(double));
for(i=0;i<ckt->CKTnumStates;i++) { for(i=0;i<ckt->CKTnumStates;i++) {
*(OldCKTstate0+i) = *(ckt->CKTstate0+i); *(OldCKTstate0+i) = *(ckt->CKTstate0+i);
};
}
startTime = (*(SPfrontEnd->IFseconds))(); startTime = (*(SPfrontEnd->IFseconds))();
SMPsolve(ckt->CKTmatrix,ckt->CKTrhs,ckt->CKTrhsSpare); SMPsolve(ckt->CKTmatrix,ckt->CKTrhs,ckt->CKTrhsSpare);

8
src/spicelib/analysis/cktsetup.c

@ -118,6 +118,7 @@ int
CKTunsetup(CKTcircuit *ckt) CKTunsetup(CKTcircuit *ckt)
{ {
int i, error, e2; int i, error, e2;
CKTnode *node;
error = OK; error = OK;
if (!ckt->CKTisSetup) if (!ckt->CKTisSetup)
@ -127,6 +128,13 @@ CKTunsetup(CKTcircuit *ckt)
tfree(ckt->CKTstates[i]); 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++) { for (i=0;i<DEVmaxnum;i++) {
if ( ((*DEVices[i]).DEVunsetup != NULL) && (ckt->CKThead[i] != NULL) ){ if ( ((*DEVices[i]).DEVunsetup != NULL) && (ckt->CKThead[i] != NULL) ){
e2 = (*((*DEVices[i]).DEVunsetup))(ckt->CKThead[i],ckt); e2 = (*((*DEVices[i]).DEVunsetup))(ckt->CKThead[i],ckt);

2
src/xspice/cm/cmexport.c

@ -19,7 +19,7 @@ struct coreInfo_t coreInfo =
MIFgetMod, MIFgetMod,
MIFgetValue, MIFgetValue,
MIFsetup, MIFsetup,
(int (*)(GENmodel *, CKTcircuit *))empty,
MIFunsetup,
MIFload, MIFload,
MIFmParam, MIFmParam,
MIFask, MIFask,

2
src/xspice/cmpp/writ_ifs.c

@ -920,7 +920,7 @@ static void write_SPICEdev(
fprintf(fp, "MIFmParam, \n"); /* DEVmodParam */ fprintf(fp, "MIFmParam, \n"); /* DEVmodParam */
fprintf(fp, "MIFload, \n"); /* DEVload */ fprintf(fp, "MIFload, \n"); /* DEVload */
fprintf(fp, "MIFsetup, \n"); /* DEVsetup */ fprintf(fp, "MIFsetup, \n"); /* DEVsetup */
fprintf(fp, "NULL, \n"); /* DEVunsetup */
fprintf(fp, "MIFunsetup, \n"); /* DEVunsetup */
fprintf(fp, "NULL, \n"); /* DEVpzSetup */ fprintf(fp, "NULL, \n"); /* DEVpzSetup */
fprintf(fp, "NULL, \n"); /* DEVtemperature */ fprintf(fp, "NULL, \n"); /* DEVtemperature */
fprintf(fp, "MIFtrunc, \n"); /* DEVtrunc */ fprintf(fp, "MIFtrunc, \n"); /* DEVtrunc */

78
src/xspice/mif/mifsetup.c

@ -44,8 +44,6 @@ NON-STANDARD FEATURES
/* #include "prefix.h" */ /* #include "prefix.h" */
#include "ngspice.h" #include "ngspice.h"
#include <stdio.h>
//#include "util.h"
#include "smpdefs.h" #include "smpdefs.h"
#include "devdefs.h" #include "devdefs.h"
#include "sperror.h" #include "sperror.h"
@ -61,7 +59,7 @@ NON-STANDARD FEATURES
extern SPICEdev **DEVices; /* info about all device types */ 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 macro for easy creation of matrix entries/pointers for outputs */
#define TSTALLOC(ptr,first,second) \ #define TSTALLOC(ptr,first,second) \
@ -454,3 +452,77 @@ MIFsetup(
return(OK); 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;
}

2
src/xspice/xspice.c

@ -19,7 +19,7 @@ struct coreInfo_t coreInfo =
MIFgetMod, MIFgetMod,
MIFgetValue, MIFgetValue,
MIFsetup, MIFsetup,
(int (*)(GENmodel *, CKTcircuit *))empty,
MIFunsetup,
MIFload, MIFload,
MIFmParam, MIFmParam,
MIFask, MIFask,

Loading…
Cancel
Save