[omniORB] Update : OmniORB3.01 - Reducing memory leaks - patch 3

Jeroen.Dobbelaere@MMR.be Jeroen.Dobbelaere@MMR.be
Fri, 15 Sep 2000 17:28:27 +0100


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C01F31.FA0B2750
Content-Type: text/plain;
	charset="ISO-8859-1"

And here is the version of patch 3 without using stl
(patch 2 and 4 don't use stl)

Greetings,
--
Jeroen Dobbelaere
Software Design Engineer
Micro-Matic Research <http://www.mmr.be>

 <<patch3-no-stl.patch>> 


------_=_NextPart_000_01C01F31.FA0B2750
Content-Type: application/octet-stream;
	name="patch3-no-stl.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="patch3-no-stl.patch"

*** omni/include/omniORB3/CORBA.h	Fri Aug 18 15:09:20 2000
--- omni_test/include/omniORB3/CORBA.h	Fri Sep 15 15:08:37 2000
***************
*** 1397,1406 ****
--- 1397,1449 ----
      void operator>>=3D(MemBufferedStream&) const;
      void operator<<=3D(MemBufferedStream&);
      size_t _NP_alignedSize(size_t) const;
    };
 =20
+   =
//////////////////////////////////////////////////////////////////////
+   /////////////////// Registration of static objects =
///////////////////
+   =
//////////////////////////////////////////////////////////////////////
+=20
+   class _CleanUpObject_Base
+   {
+   public:
+     _CleanUpObject_Base() {}
+     virtual ~_CleanUpObject_Base() { };
+   };
+=20
+   template <typename T>
+   class _CleanUpObject : public _CleanUpObject_Base
+   {
+   public:
+     _CleanUpObject(T* tmp) : m_object(tmp) {}
+     virtual ~_CleanUpObject() { delete m_object; }
+=20
+   private:
+     T* m_object;
+   };
+=20
+   extern void =
_register_cleanupobject_for_autodestruction(_CleanUpObject_Base*);
+=20
+   // Function Template to register a CORBA::Object for auto =
destruction
+   template <typename T>
+   T* _register_corba_object_for_autodestruction(T* obj)
+   {
+     _CleanUpObject_Base* tmp =3D new =
_CleanUpObject<CORBA::Object>(obj);
+     _register_cleanupobject_for_autodestruction(tmp);
+=20
+     return obj;
+   }
+=20
+   // Function Template to register an object for auto destruction
+   template <typename T>
+   T* _register_other_object_for_autodestruction(T* obj)
+   {
+     _CleanUpObject_Base* tmp =3D new _CleanUpObject<T>(obj);
+     _register_cleanupobject_for_autodestruction(tmp);
+=20
+     return obj;
+   }
 =20
  #ifdef HAS_Cplusplus_Namespace
  _CORBA_MODULE_END
 =20
  _CORBA_MODULE CORBA
*** omni/src/lib/OmniORB2/omniidl_be/cxx/skel/template.py	Fri Aug 18 =
15:09:14 2000
--- omni_test/src/lib/OmniORB2/omniidl_be/cxx/skel/template.py	Fri Sep =
15 15:10:44 2000
***************
*** 145,155 ****
  @name@::_nil()
  {
    static @objref_name@* _the_nil_ptr =3D 0;
    if( !_the_nil_ptr ) {
      omni::nilRefLock().lock();
!   if( !_the_nil_ptr )  _the_nil_ptr =3D new @objref_name@;
      omni::nilRefLock().unlock();
    }
    return _the_nil_ptr;
  }
 =20
--- 145,155 ----
  @name@::_nil()
  {
    static @objref_name@* _the_nil_ptr =3D 0;
    if( !_the_nil_ptr ) {
      omni::nilRefLock().lock();
!   if( !_the_nil_ptr )  _the_nil_ptr =3D =
CORBA::_register_corba_object_for_autodestruction(new @objref_name@);
      omni::nilRefLock().unlock();
    }
    return _the_nil_ptr;
  }
 =20
*** omni/src/lib/OmniORB2/orbcore/omniInternal.cc	Fri Aug 18 15:09:12 =
2000
--- omni_test/src/lib/OmniORB2/orbcore/omniInternal.cc	Fri Sep 15 =
17:17:44 2000
***************
*** 1040,1044 ****
--- 1040,1152 ----
      // static initialisation.
      omni::nilRefLock();
    }
    static static_initialiser the_instance;
  };
+=20
+=20
+ // track other static objects, for destruction afterwards
+ // class that tracks the created (static) exceptions, needed for =
cleanup later...
+ // provide a Container without using stl (for compilers which don't =
support it)
+ #define TTPTR_CONTAINER_CHUNKSIZE (1024)
+=20
+ class CleanUpObject_Base_Container
+ {
+ public:
+   struct Chunk
+   {
+     typedef CORBA::_CleanUpObject_Base* Type;
+     Type             m_data[TTPTR_CONTAINER_CHUNKSIZE];
+     Chunk*           m_previous;
+=20
+     Chunk(Chunk* prev) : m_previous(prev) { }
+   };
+=20
+ public:
+   CleanUpObject_Base_Container()
+   {
+     m_last =3D 0;
+     m_entry =3D 0;
+   }
+=20
+   ~CleanUpObject_Base_Container()
+   {
+     Chunk* p =3D m_last;
+     while(p !=3D 0)
+       {
+ 	Chunk* prev =3D p->m_previous;
+ 	delete p;
+ 	p =3D prev;
+       }
+   }
+=20
+   void reverse_delete()
+   {
+     // should only be called once
+=20
+     unsigned long i =3D m_entry;
+     Chunk* p =3D m_last;
+     while(p !=3D 0)
+       {
+ 	while(i !=3D 0)
+ 	  {
+ 	    --i;
+ 	    delete p->m_data[i];
+ 	  }
+ =09
+ 	i=3DTTPTR_CONTAINER_CHUNKSIZE;
+=20
+ 	Chunk* prev =3D p->m_previous;
+=20
+ 	delete p;
+ 	p =3D prev;
+       }
+    =20
+     // and reinitialise (just for safety)
+     m_last =3D 0;
+     m_entry =3D 0;
+   }
+=20
+   void push_back(CORBA::_CleanUpObject_Base* p)
+   {
+     if((m_last =3D=3D 0) || (m_entry =3D=3D =
TTPTR_CONTAINER_CHUNKSIZE))
+       {
+ 	m_last =3Dnew Chunk(m_last);
+ 	m_entry =3D 0;
+       }
+=20
+     m_last->m_data[m_entry] =3D p;
+     ++m_entry;
+   }
+=20
+ private:
+   Chunk*        m_last;
+   unsigned long m_entry; // next entry to be filled.
+ };
+=20
+ namespace CORBA
+ {
+   //  registering function for static objects
+   class TrackCleanUpObjects
+   {
+   public:
+     TrackCleanUpObjects() {}
+     ~TrackCleanUpObjects() { delete_all(); }
+    =20
+     void attach(CORBA::_CleanUpObject_Base* rhs) { =
m_table.push_back(rhs); }
+    =20
+     void delete_all()=20
+     {
+       m_table.reverse_delete();
+     }
+    =20
+   private:
+     CleanUpObject_Base_Container   m_table;
+   };
+  =20
+   void =
_register_cleanupobject_for_autodestruction(_CleanUpObject_Base* obj)
+   {
+     static TrackCleanUpObjects local_trackOtherObjects;
+=20
+     local_trackOtherObjects.attach(obj);
+   }
+ }

------_=_NextPart_000_01C01F31.FA0B2750--