From 281d1952c4f20f628d5f83148a6a1ac5a351867f Mon Sep 17 00:00:00 2001 From: rlar Date: Fri, 11 Feb 2011 17:09:40 +0000 Subject: [PATCH] fix a bug when `alter' a vector parameter (VSRC PWL for example) --- ChangeLog | 6 ++++ src/spicelib/devices/cpl/cplmpar.c | 19 +++++++++--- src/spicelib/devices/isrc/isrcpar.c | 41 +++++++++++++------------- src/spicelib/devices/vsrc/vsrcpar.c | 45 ++++++++++++++--------------- 4 files changed, 62 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index c808e1273..f9122ef69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-02-11 Robert Larice + * src/spicelib/devices/cpl/cplmpar.c , + * src/spicelib/devices/isrc/isrcpar.c , + * src/spicelib/devices/vsrc/vsrcpar.c : + fix a bug when `alter' a vector parameter (VSRC PWL for example) + 2011-01-25 Robert Larice * Modified src/include/cmproto.h , * Modified src/xspice/icm/dlmain.c , diff --git a/src/spicelib/devices/cpl/cplmpar.c b/src/spicelib/devices/cpl/cplmpar.c index f2132e516..0adf204fc 100644 --- a/src/spicelib/devices/cpl/cplmpar.c +++ b/src/spicelib/devices/cpl/cplmpar.c @@ -13,28 +13,39 @@ Author: 1992 Charles Hough #include "suffix.h" +static void copy_coeffs(double **dst, IFvalue *value) +{ + if(*dst) + tfree(*dst); + + *dst = TMALLOC(double, value->v.numValue); + + memcpy(*dst, value->v.vec.rVec, value->v.numValue * sizeof(double)); +} + + int CPLmParam(int param, IFvalue *value, GENmodel *inModel) { register CPLmodel *model = (CPLmodel *)inModel; switch(param) { case CPL_R: - model->Rm = value->v.vec.rVec; + copy_coeffs(& model->Rm, value); model->Rm_counter = value->v.numValue; model->Rmgiven = TRUE; break; case CPL_L: - model->Lm = value->v.vec.rVec; + copy_coeffs(& model->Lm, value); model->Lm_counter = value->v.numValue; model->Lmgiven = TRUE; break; case CPL_G: - model->Gm = value->v.vec.rVec; + copy_coeffs(& model->Gm, value); model->Gm_counter = value->v.numValue; model->Gmgiven = TRUE; break; case CPL_C: - model->Cm = value->v.vec.rVec; + copy_coeffs(& model->Cm, value); model->Cm_counter = value->v.numValue; model->Cmgiven = TRUE; break; diff --git a/src/spicelib/devices/isrc/isrcpar.c b/src/spicelib/devices/isrc/isrcpar.c index b75f9e408..f138f8e05 100644 --- a/src/spicelib/devices/isrc/isrcpar.c +++ b/src/spicelib/devices/isrc/isrcpar.c @@ -14,6 +14,19 @@ Modified: 2000 AlansFixes #include "1-f-code.h" +static void copy_coeffs(ISRCinstance *here, IFvalue *value) +{ + if(here->ISRCcoeffs) + tfree(here->ISRCcoeffs); + + here->ISRCcoeffs = TMALLOC(double, value->v.numValue); + here->ISRCfunctionOrder = value->v.numValue; + here->ISRCcoeffsGiven = TRUE; + + memcpy(here->ISRCcoeffs, value->v.vec.rVec, value->v.numValue * sizeof(double)); +} + + /* ARGSUSED */ int ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) @@ -57,33 +70,25 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) if(value->v.numValue <2) return(E_BADPARM); here->ISRCfunctionType = PULSE; here->ISRCfuncTGiven = TRUE; - here->ISRCcoeffs = value->v.vec.rVec; - here->ISRCfunctionOrder = value->v.numValue; - here->ISRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case ISRC_SINE: if(value->v.numValue <2) return(E_BADPARM); here->ISRCfunctionType = SINE; here->ISRCfuncTGiven = TRUE; - here->ISRCcoeffs = value->v.vec.rVec; - here->ISRCfunctionOrder = value->v.numValue; - here->ISRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case ISRC_EXP: if(value->v.numValue <2) return(E_BADPARM); here->ISRCfunctionType = EXP; here->ISRCfuncTGiven = TRUE; - here->ISRCcoeffs = value->v.vec.rVec; - here->ISRCfunctionOrder = value->v.numValue; - here->ISRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case ISRC_PWL: if(value->v.numValue <2) return(E_BADPARM); here->ISRCfunctionType = PWL; here->ISRCfuncTGiven = TRUE; - here->ISRCcoeffs = value->v.vec.rVec; - here->ISRCfunctionOrder = value->v.numValue; - here->ISRCcoeffsGiven = TRUE; + copy_coeffs(here, value); for (i=0;i<((here->ISRCfunctionOrder/2)-1);i++) { if (*(here->ISRCcoeffs+2*(i+1))<=*(here->ISRCcoeffs+2*i)) { @@ -98,17 +103,13 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) if(value->v.numValue <2) return(E_BADPARM); here->ISRCfunctionType = SFFM; here->ISRCfuncTGiven = TRUE; - here->ISRCcoeffs = value->v.vec.rVec; - here->ISRCfunctionOrder = value->v.numValue; - here->ISRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case ISRC_AM: if(value->v.numValue <2) return(E_BADPARM); here->ISRCfunctionType = AM; here->ISRCfuncTGiven = TRUE; - here->ISRCcoeffs = value->v.vec.rVec; - here->ISRCfunctionOrder = value->v.numValue; - here->ISRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case ISRC_D_F1: here->ISRCdF1given = TRUE; @@ -161,9 +162,7 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->ISRCfunctionType = TRNOISE; here->ISRCfuncTGiven = TRUE; - here->ISRCcoeffs = value->v.vec.rVec; - here->ISRCfunctionOrder = value->v.numValue; - here->ISRCcoeffsGiven = TRUE; + copy_coeffs(here, value); NA = here->ISRCcoeffs[0]; // input is rms value TS = here->ISRCcoeffs[1]; // time step diff --git a/src/spicelib/devices/vsrc/vsrcpar.c b/src/spicelib/devices/vsrc/vsrcpar.c index b12356d87..4ca4963a9 100644 --- a/src/spicelib/devices/vsrc/vsrcpar.c +++ b/src/spicelib/devices/vsrc/vsrcpar.c @@ -14,6 +14,19 @@ Modified: 2000 AlansFixes #include "1-f-code.h" +static void copy_coeffs(VSRCinstance *here, IFvalue *value) +{ + if(here->VSRCcoeffs) + tfree(here->VSRCcoeffs); + + here->VSRCcoeffs = TMALLOC(double, value->v.numValue); + here->VSRCfunctionOrder = value->v.numValue; + here->VSRCcoeffsGiven = TRUE; + + memcpy(here->VSRCcoeffs, value->v.vec.rVec, value->v.numValue * sizeof(double)); +} + + /* ARGSUSED */ int VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) @@ -56,30 +69,22 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) case VSRC_PULSE: here->VSRCfunctionType = PULSE; here->VSRCfuncTGiven = TRUE; - here->VSRCcoeffs = value->v.vec.rVec; - here->VSRCfunctionOrder = value->v.numValue; - here->VSRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case VSRC_SINE: here->VSRCfunctionType = SINE; here->VSRCfuncTGiven = TRUE; - here->VSRCcoeffs = value->v.vec.rVec; - here->VSRCfunctionOrder = value->v.numValue; - here->VSRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case VSRC_EXP: here->VSRCfunctionType = EXP; here->VSRCfuncTGiven = TRUE; - here->VSRCcoeffs = value->v.vec.rVec; - here->VSRCfunctionOrder = value->v.numValue; - here->VSRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case VSRC_PWL: here->VSRCfunctionType = PWL; here->VSRCfuncTGiven = TRUE; - here->VSRCcoeffs = value->v.vec.rVec; - here->VSRCfunctionOrder = value->v.numValue; - here->VSRCcoeffsGiven = TRUE; + copy_coeffs(here, value); for(i=0;i<(here->VSRCfunctionOrder/2)-1;i++) { if(*(here->VSRCcoeffs+2*(i+1))<=*(here->VSRCcoeffs+2*i)) { @@ -118,17 +123,13 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) case VSRC_SFFM: here->VSRCfunctionType = SFFM; here->VSRCfuncTGiven = TRUE; - here->VSRCcoeffs = value->v.vec.rVec; - here->VSRCfunctionOrder = value->v.numValue; - here->VSRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case VSRC_AM: if(value->v.numValue <2) return(E_BADPARM); here->VSRCfunctionType = AM; here->VSRCfuncTGiven = TRUE; - here->VSRCcoeffs = value->v.vec.rVec; - here->VSRCfunctionOrder = value->v.numValue; - here->VSRCcoeffsGiven = TRUE; + copy_coeffs(here, value); break; case VSRC_D_F1: here->VSRCdF1given = TRUE; @@ -180,9 +181,7 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->VSRCfunctionType = TRNOISE; here->VSRCfuncTGiven = TRUE; - here->VSRCcoeffs = value->v.vec.rVec; - here->VSRCfunctionOrder = value->v.numValue; - here->VSRCcoeffsGiven = TRUE; + copy_coeffs(here, value); NA = here->VSRCcoeffs[0]; // input is rms value TS = here->VSRCcoeffs[1]; // time step @@ -215,9 +214,7 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->VSRCfunctionType = TRRANDOM; here->VSRCfuncTGiven = TRUE; - here->VSRCcoeffs = value->v.vec.rVec; - here->VSRCfunctionOrder = value->v.numValue; - here->VSRCcoeffsGiven = TRUE; + copy_coeffs(here, value); rndtype = (int)here->VSRCcoeffs[0]; // type of random function TS = here->VSRCcoeffs[1]; // time step