Changeset 255 for trunk/nom/src


Ignore:
Timestamp:
Mar 15, 2007, 9:42:22 PM (18 years ago)
Author:
cinc
Message:

Parameter checking for object pointer working.

Location:
trunk/nom/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/nom/src/nombuildclass.c

    r221 r255  
    1616* The Initial Developer of the Original Code is
    1717* netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
    18 * Portions created by the Initial Developer are Copyright (C) 2005-2006
     18* Portions created by the Initial Developer are Copyright (C) 2005-2007
    1919* the Initial Developer. All Rights Reserved.
    2020*
     
    969969                                                  ulMajorVersion, ulMinorVersion);
    970970        if(nomClass){
     971          CORBA_Environment * tempEnv=nomCreateEnvNoObjectCheck();
     972
    971973          DBG_NOMBUILDCLASS(TRUE, "%s: class is 0x%x\n", nomClass->mtab->nomClassName, nomClass);
    972974#if 0
     
    977979          priv_checkForNomUnInitOverride( (NOMClassPriv*)nomClass->mtab->nomClsInfo,  ncpParent);
    978980#endif     
    979           _nomInit((NOMObject*)nomClass, NULLHANDLE);
    980           _nomClassReady(nomClass, NULLHANDLE);
     981          /* Make sure the env is marked that we don't chek the object pointer. This would fail
     982             because the class isn't registered yet. */
     983          _nomInit((NOMObject*)nomClass, tempEnv);
     984          _nomClassReady(nomClass, tempEnv);
    981985        }
    982986
     
    993997
    994998      if(nomClass){
    995         _nomInit((NOMObject*)nomClass, NULLHANDLE);
    996         _nomClassReady(nomClass, NULLHANDLE);
     999        CORBA_Environment * tempEnv=nomCreateEnvNoObjectCheck();
     1000        /* Make sure the env is marked that we don't chek the object pointer. This would fail
     1001           because the class isn't registered yet. */
     1002        _nomInit((NOMObject*)nomClass, tempEnv);
     1003        _nomClassReady(nomClass, tempEnv);
    9971004      }
    9981005      return nomClass;
     
    10881095
    10891096  if(nomClass){
     1097    CORBA_Environment * tempEnv=nomCreateEnvNoObjectCheck();
     1098
    10901099    /* Mark the class as using nomUnInit() if any parent did that. We just have to
    10911100       check the flag and the flag of the parent class. This information is important
     
    10941103    priv_checkForNomUnInitOverride( (NOMClassPriv*)nomClass->mtab->nomClsInfo,  ncpParent);
    10951104   
    1096     _nomInit(nomClass, NULLHANDLE);
    1097     _nomClassReady(nomClass, NULLHANDLE);
     1105    /* Make sure the env is marked that we don't chek the object pointer. This would fail
     1106       because the class isn't registered yet. */
     1107    _nomInit(nomClass, tempEnv);
     1108    _nomClassReady(nomClass, tempEnv);
    10981109  }
    10991110  return nomClass;
  • trunk/nom/src/nombuildnomcls.c

    r221 r255  
    1616* The Initial Developer of the Original Code is
    1717* netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
    18 * Portions created by the Initial Developer are Copyright (C) 2005-2006
     18* Portions created by the Initial Developer are Copyright (C) 2005-2007
    1919* the Initial Developer. All Rights Reserved.
    2020*
  • trunk/nom/src/nombuildnomobj.c

    r221 r255  
    1616* The Initial Developer of the Original Code is
    1717* netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
    18 * Portions created by the Initial Developer are Copyright (C) 2005-2006
     18* Portions created by the Initial Developer are Copyright (C) 2005-2007
    1919* the Initial Developer. All Rights Reserved.
    2020*
  • trunk/nom/src/nomdebug.c

    r94 r255  
    1616* The Initial Developer of the Original Code is
    1717* netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
    18 * Portions created by the Initial Developer are Copyright (C) 2005-2006
     18* Portions created by the Initial Developer are Copyright (C) 2005-2007
    1919* the Initial Developer. All Rights Reserved.
    2020*
     
    5555//#include "cwsomcls.h"
    5656extern NOMClassMgr* NOMClassMgrObject;
    57 
     57extern gboolean fInitialized;
     58
     59NOMEXTERN void NOMLINK nomPrintObjectPointerErrorMsg(NOMObject*  nomObject, gchar *chrClsName, gchar* chrMethodName)
     60{
     61  if(!nomObject)
     62    g_warning("The object used to call the method %s is not valid. A NULL pointer was given.", chrMethodName);
     63  else{
     64    if(!nomIsObj(nomObject))
     65      g_warning("The object used to call the method %s is not a valid NOM object. ", chrMethodName);
     66    else
     67      g_warning("The object used to call the method %s is not valid for this method. The object must be some instance of class %s (or of a subclass) but is a %s.", chrMethodName, chrClsName, NOMObject_nomGetClassName(nomObject, NULLHANDLE));
     68  }
     69}
     70
     71/*
     72  This function prints some more info about the object error. It's used for generic checks which
     73  always return NULL which isn't always correct.
     74 */
     75static void nomPrintAdditionalErrorMsg(void)
     76{
     77  g_message("Note that NULL is returned for the call (if the method returns a value). This may not be correct. Use the NOMPARMCHECK() macro to specify default return values for methods.");
     78}
     79
     80/* Function to check if  NOMObject is valid before calling a method on it. Note that we don't have to check
     81   the instance class here using nomIsA*(). */
     82NOMEXTERN gboolean NOMLINK nomCheckNOMObjectPtr(NOMObject *nomSelf, NOMClass* nomClass, gchar* chrMethodName, CORBA_Environment *ev)
     83{
     84  /* Not initialized yet, so object check won't work. This means the three core NOM classes are not
     85     yet created.*/
     86  if(!fInitialized)
     87    return TRUE;
     88 
     89  if(ev && (ev->fFlags & NOMENV_FLG_DONT_CHECK_OBJECT))
     90    return TRUE;
     91
     92  //  g_message("In %s with %s %px nomClass: %px (%s)", __FUNCTION__, chrMethodName, nomSelf, nomClass, nomClass->mtab->nomClassName);
     93  if(!nomIsObj(nomSelf))
     94    {
     95      nomPrintObjectPointerErrorMsg(nomSelf, nomClass->mtab->nomClassName, chrMethodName);
     96      nomPrintAdditionalErrorMsg();
     97      return FALSE;
     98    }
     99  return TRUE;
     100}
     101
     102#include <string.h>
     103/* Function to check if an object is valid before calling a method on it */
     104NOMEXTERN gboolean NOMLINK nomCheckObjectPtr(NOMObject *nomSelf, NOMClass* nomClass, gchar* chrMethodName, CORBA_Environment *ev)
     105{
     106  /* Not initialized yet, so object check won't work. This means the three core NOM classes are not
     107     yet created.*/
     108  if(!fInitialized)
     109    return TRUE;
     110
     111  //if(strstr( chrMethodName, "nomIsObj"))
     112  //return TRUE;
     113
     114  if(ev && (ev->fFlags & NOMENV_FLG_DONT_CHECK_OBJECT))
     115    return TRUE;
     116
     117  //  g_message("In %s with %s %px nomClass: %px (%s)", __FUNCTION__, chrMethodName, nomSelf, nomClass, nomClass->mtab->nomClassName);
     118  if(!nomIsObj(nomSelf) || !_nomIsANoClsCheck(nomSelf, nomClass, NULLHANDLE))
     119    {
     120      nomPrintObjectPointerErrorMsg(nomSelf, nomClass->mtab->nomClassName, chrMethodName);
     121      nomPrintAdditionalErrorMsg();
     122      return FALSE;
     123    }
     124  return TRUE;
     125}
     126
     127NOMEXTERN CORBA_Environment* NOMLINK nomCreateEnvNoObjectCheck(void)
     128{
     129  CORBA_Environment * tempEnv=(CORBA_Environment*)NOMMalloc(sizeof(CORBA_Environment));
     130  if(tempEnv)
     131    tempEnv->fFlags|=NOMENV_FLG_DONT_CHECK_OBJECT;
     132  return tempEnv;
     133}
     134 
    58135static void dumpClassFunc(GQuark gquark, gpointer data, gpointer user_data)
    59136{
  • trunk/nom/src/nomtkinit.c

    r219 r255  
    6161NOMClassMgr* NOMClassMgrObject=NULLHANDLE; /* Referenced from different files */
    6262
     63gboolean fInitialized=FALSE;
     64
    6365/********************************************************/
    6466/*   Toolkit functions, exported                        */
     
    131133  NOMClassPriv* ncPriv;
    132134  NOMClass* nomCls;
     135  //  NOMClassMgr *NOMClassMgrObject_priv;
    133136#if 0
    134137  NOMObject *nomObj;
     
    162165
    163166#ifdef DEBUG_NOMENVNEW
    164   nomPrintf("%s: NOMClassMgrObject: %x \n", __FUNCTION__, NOMClassMgrObject);
     167  nomPrintf("%s: NOMClassMgrObject: %x (%x)\n", __FUNCTION__, NOMClassMgrObject, pGlobalNomEnv->defaultMetaClass);
    165168#endif
    166169
     
    196199  _nomTestFunc_NOMTest2(nomTst2Obj, NULLHANDLE);
    197200#endif
     201  /* This must be done last! */
     202  //  NOMClassMgrObject=NOMClassMgrObject_priv;
     203
     204  fInitialized=TRUE;
    198205
    199206  return NOMClassMgrObject;
Note: See TracChangeset for help on using the changeset viewer.