Ignore:
Timestamp:
Jan 21, 2007, 4:58:25 PM (19 years ago)
Author:
cinc
Message:

Integration of nomUnInit() with the garbage collector using finalizers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nom/class_c/nomcls.c

    r208 r210  
    4949#include "nomclassmanager.h"
    5050
     51#include "gc.h"
     52
    5153extern NOMClassMgr* NOMClassMgrObject;
    5254
     55static void nomObjectFinalizer(GC_PTR obj, GC_PTR client_data)
     56{
     57  NOMObject* nObj;
     58  nObj=(NOMObject*)obj;
     59
     60  if(nomIsObj(nObj)){
     61    //nomPrintf("Finalizing 0x%x: %s \n", nObj, nObj->mtab->nomClassName);
     62    _nomUnInit(nObj, NULLHANDLE);
     63  }
     64  //else
     65  //nomPrintf("Finalizing 0x%x: no object! \n", nObj);
     66}
    5367
    5468NOM_Scope CORBA_Object NOMLINK impl_NOMClass_nomNew(NOMClass* nomSelf, CORBA_Environment *ev)
     
    5670  NOMClassData* nomThis=NOMClassGetData(nomSelf);
    5771  NOMClassPriv *ncp;
    58   string nObj;
    59  
    60   //nomPrintf("    Entering %s (%x) with nomSelf: 0x%x. nomSelf is: %s.\n",
    61   //        __FUNCTION__, impl_NOMClass_nomNew, nomSelf, nomSelf->mtab->nomClassName);
     72  gchar* nObj;
    6273
    6374  if(!nomSelf)
    6475    return NULLHANDLE;
    65 
    6676
    6777  if(!_ncpObject)
     
    8393  NOMClassPriv *ncp;
    8494  NOMClassData *nomThis = NOMClassGetData(nomSelf);
     95  GC_PTR oldData;
     96  GC_finalization_proc oldFinalizerFunc;
    8597
    8698  ncp=(NOMClassPriv*)_ncpObject;
     
    92104  ((NOMObject*)nomObj)->mtab=ncp->mtab;
    93105
     106  /* Register finalizer if the class uses nomUnInit */
     107  ncp=(NOMClassPriv*)ncp->mtab->nomClsInfo;
     108  if(ncp->ulClassFlags & NOM_FLG_NOMUNINIT_OVERRIDEN){
     109    //nomPrintf("Registering finalizer for %s\n", ((NOMObject*)nomObj)->mtab->nomClassName);
     110    GC_register_finalizer(nomObj,  nomObjectFinalizer, NULL, &oldFinalizerFunc, &oldData);
     111  }
    94112  /* NO call to _nomInit() */
    95113
     
    98116}
    99117
    100 NOM_Scope CORBA_Object NOMLINK impl_NOMClass_nomRenew(NOMClass* nomSelf, const CORBA_Object nomObj, CORBA_Environment *ev)
     118NOM_Scope CORBA_Object NOMLINK impl_NOMClass_nomRenew(NOMClass* nomSelf, const CORBA_Object nomObj,
     119                                                      CORBA_Environment *ev)
    101120{
    102121  _nomRenewNoInit(nomSelf, nomObj, NULLHANDLE);
     
    109128
    110129
    111 NOM_Scope CORBA_string NOMLINK impl_NOMClass_nomAllocate(NOMClass* nomSelf, const CORBA_long ulSize, CORBA_Environment *ev)
    112 {
    113   NOMClassPriv *ncp;
    114   NOMClassData *nomThis = NOMClassGetData(nomSelf);
    115 
    116   ncp=(NOMClassPriv*)_ncpObject;
    117   //  nomPrintf("%s: size %d\n", __FUNCTION__, ulSize);
     130NOM_Scope CORBA_string NOMLINK impl_NOMClass_nomAllocate(NOMClass* nomSelf, const CORBA_long ulSize,
     131                                                         CORBA_Environment *ev)
     132{
     133  /* NOMClassData *nomThis = NOMClassGetData(nomSelf); */
     134
    118135  return NOMMalloc(ulSize);
    119136}
     
    131148
    132149
    133 NOM_Scope void NOMLINK impl_NOMClass_nomSetObjectCreateInfo(NOMClass* nomSelf, const gpointer ncpObject, CORBA_Environment *ev)
     150NOM_Scope void NOMLINK impl_NOMClass_nomSetObjectCreateInfo(NOMClass* nomSelf, const gpointer ncpObject,
     151                                                            CORBA_Environment *ev)
    134152{
    135153  NOMClassData* nomThis=NOMClassGetData(nomSelf);
     
    178196          /* No, not in the list, so register it */
    179197          ncPriv=(NOMClassPriv*)nomSelf->mtab->nomClsInfo;
    180           ncPriv->ulIsMetaClass=1; /* Mark that we are a metaclass */
     198          //ncPriv->ulIsMetaClass=1; /* Mark that we are a metaclass */
     199          ncPriv->ulClassFlags|=NOM_FLG_IS_METACLASS; /* Mark that we are a metaclass */
    181200          _nomRegisterClass(NOMClassMgrObject, nomSelf->mtab, NULLHANDLE);
    182201          /* Register all the methods this class introduces */
     
    193212          if(ncPriv){
    194213#warning !!!!! NOMClass does not have this pointer, this is a bug !!!!!
    195             ncPriv->ulIsMetaClass=0; /* Mark that we are not a metaclass (should be 0 already) */
     214            //ncPriv->ulIsMetaClass=0; /* Mark that we are not a metaclass (should be 0 already) */
     215            ncPriv->ulClassFlags&=~NOM_FLG_IS_METACLASS; /* Mark that we are not a metaclass (should be 0 already) */
    196216            _nomRegisterClass(NOMClassMgrObject, ncPriv->mtab, NULLHANDLE);
    197217
     
    214234
    215235        ncPriv=(NOMClassPriv*)_nomGetObjectCreateInfo(nomSelf, NULLHANDLE);//nomSelf->mtab->nomClsInfo;
    216         ncPriv->ulIsMetaClass=0; /* Mark that we are not a metaclass (should be 0 already) */
     236        // ncPriv->ulIsMetaClass=0; /* Mark that we are not a metaclass (should be 0 already) */
     237        ncPriv->ulClassFlags&=~NOM_FLG_IS_METACLASS; /* Mark that we are not a metaclass (should be 0 already) */
    217238        if(ncPriv){
    218239          gulong a, ulNumIntroducedMethods;
Note: See TracChangeset for help on using the changeset viewer.