Changeset 230 for cpp


Ignore:
Timestamp:
04/25/14 16:15:30 (11 years ago)
Author:
Maciej Komosinski
Message:

Detects invalid ParamEntry? when accessing ParamEntry?-based Params in DEBUG mode

Location:
cpp/frams/param
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/param/param.cpp

    r197 r230  
    558558//////////////////////////////// PARAM ////////////////////////////////////
    559559
     560#ifdef DEBUG
     561void SimpleAbstractParam::sanityCheck(int i)
     562{
     563ParamEntry *pe=entry(i);
     564
     565const char* t=pe->type;
     566const char* err=NULL;
     567
     568if (*t=='p')
     569        {
     570        if (pe->fun1==NULL)
     571                err="no procedure defined";
     572        }
     573else
     574        {
     575        if (!(pe->flags & PARAM_READONLY))
     576                { //write access
     577                if ((pe->fun2==NULL)&&(pe->offset==PARAM_ILLEGAL_OFFSET))
     578                        err="no field defined (GETONLY without PARAM_READONLY?)";
     579                }
     580        }
     581if (err!=NULL)
     582        FMprintf("SimpleAbstractParam","sanityCheck", FMLV_ERROR,
     583                 "Invalid ParamEntry for %s.%s (%s)", getName(), pe->id, err);
     584}       
     585#endif
     586
    560587void *SimpleAbstractParam::getTarget(int i)
    561588{
     
    566593///////// get
    567594
     595#ifdef DEBUG
     596#define SANITY_CHECK(i) sanityCheck(i)
     597#else
     598#define SANITY_CHECK(i)
     599#endif
     600
    568601long SimpleAbstractParam::getInt(int i)
    569602{
     603        SANITY_CHECK(i);
    570604        ExtValue v;
    571605        ParamEntry *pe = entry(i);
     
    584618double SimpleAbstractParam::getDouble(int i)
    585619{
     620        SANITY_CHECK(i);
    586621        ExtValue v;
    587622        ParamEntry *pe = entry(i);
     
    600635SString SimpleAbstractParam::getString(int i)
    601636{
     637        SANITY_CHECK(i);
    602638        ExtValue v;
    603639        ParamEntry *pe = entry(i);
     
    616652ExtObject SimpleAbstractParam::getObject(int i)
    617653{
     654        SANITY_CHECK(i);
    618655        ExtValue v;
    619656        ParamEntry *pe = entry(i);
     
    632669ExtValue SimpleAbstractParam::getExtValue(int i)
    633670{
     671        SANITY_CHECK(i);
    634672        ExtValue v;
    635673        ParamEntry *pe = entry(i);
     
    651689int SimpleAbstractParam::setInt(int i, long x)
    652690{
     691        SANITY_CHECK(i);
    653692        ExtValue v;
    654693        ParamEntry *pe = entry(i);
     
    686725int SimpleAbstractParam::setDouble(int i, double x)
    687726{
     727        SANITY_CHECK(i);
    688728        ExtValue v;
    689729        ParamEntry *pe = entry(i);
     
    721761int SimpleAbstractParam::setString(int i, const SString& x)
    722762{
     763        SANITY_CHECK(i);
    723764        ExtValue v;
    724765        SString vs;
     
    761802int SimpleAbstractParam::setObject(int i, const ExtObject& x)
    762803{
     804        SANITY_CHECK(i);
    763805        ExtValue v;
    764806        ParamEntry *pe = entry(i);
     
    782824int SimpleAbstractParam::setExtValue(int i, const ExtValue& x)
    783825{
     826        SANITY_CHECK(i);
    784827        ParamEntry *pe = entry(i);
    785828        if (pe->flags&PARAM_READONLY) return PSET_RONLY;
     
    801844void SimpleAbstractParam::call(int i, ExtValue *args, ExtValue *ret)
    802845{
     846        SANITY_CHECK(i);
    803847        ParamEntry *pe = entry(i);
    804848        if (!pe) return;
  • cpp/frams/param/param.h

    r197 r230  
    157157
    158158        static const char* SERIALIZATION_PREFIX;
     159
     160#ifdef DEBUG
     161        virtual void sanityCheck(int i) {}
     162#endif
    159163};
    160164
     
    170174#define FIELDOFFSET(_fld_) ((long)((char*)(&((FIELDSTRUCT*)&MakeCodeGuardHappy)->_fld_)-((char*)((FIELDSTRUCT*)&MakeCodeGuardHappy))))
    171175
     176#ifdef DEBUG
     177#define PARAM_ILLEGAL_OFFSET ((long)0xdeadbeef)
     178#else
     179#define PARAM_ILLEGAL_OFFSET 0
     180#endif
     181
    172182#define FIELD(_fld_) FIELDOFFSET(_fld_),0,0
    173183#define LONGOFFSET(_o_) (_o_),0,0
    174 #define PROCEDURE(_proc_) 0,(void*)PROCOFFSET(_proc_),0
    175 #define STATICPROCEDURE(_proc_) 0,(void*)STATICPROCOFFSET(_proc_),0
    176 #define GETSET(_proc_) 0,(void*)GETOFFSET(get_ ## _proc_),(void*)SETOFFSET(set_ ## _proc_)
     184#define PROCEDURE(_proc_) PARAM_ILLEGAL_OFFSET,(void*)PROCOFFSET(_proc_),0
     185#define STATICPROCEDURE(_proc_) PARAM_ILLEGAL_OFFSET,(void*)STATICPROCOFFSET(_proc_),0
     186#define GETSET(_proc_) PARAM_ILLEGAL_OFFSET,(void*)GETOFFSET(get_ ## _proc_),(void*)SETOFFSET(set_ ## _proc_)
    177187#define GETFIELD(_proc_) FIELDOFFSET(_proc_),(void*)GETOFFSET(get_ ## _proc_),0
    178188#define SETFIELD(_proc_) FIELDOFFSET(_proc_),0,(void*)SETOFFSET(set_ ## _proc_)
    179 #define GETONLY(_proc_) 0,(void*)GETOFFSET(get_ ## _proc_),0
    180 #define SETONLY(_proc_) 0,0,(void*)SETOFFSET(set_ ## _proc_)
     189#define GETONLY(_proc_) PARAM_ILLEGAL_OFFSET,(void*)GETOFFSET(get_ ## _proc_),0
     190#define SETONLY(_proc_) PARAM_ILLEGAL_OFFSET,0,(void*)SETOFFSET(set_ ## _proc_)
    181191
    182192#define PARAMPROCARGS ExtValue* args,ExtValue* ret
     
    271281        virtual void setDefault(bool numericonly = false);
    272282        virtual void setDefault(int i, bool numericonly = false);
     283
     284#ifdef DEBUG
     285        void sanityCheck(int i);
     286#endif
    273287};
    274288
Note: See TracChangeset for help on using the changeset viewer.