From 8de2a5081b41e37c4b104771af7bc4c13f48e852 Mon Sep 17 00:00:00 2001 From: caremoli Date: Mon, 18 May 2009 17:11:32 +0000 Subject: [PATCH] CCAR: add a python module for automatic management of genericobj reference counting. The module is not active by default. It must be imported to activate the automatic reference counting --- src/KERNEL_PY/Makefile.am | 3 ++- src/KERNEL_PY/salome_genericobj.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/KERNEL_PY/salome_genericobj.py diff --git a/src/KERNEL_PY/Makefile.am b/src/KERNEL_PY/Makefile.am index 869e2f913..6b2457c05 100755 --- a/src/KERNEL_PY/Makefile.am +++ b/src/KERNEL_PY/Makefile.am @@ -47,7 +47,8 @@ if CORBA_GEN omnipatch.py \ iparameters.py \ salome_version.py \ - salome_notebook.py + salome_notebook.py \ + salome_genericobj.py endif sharedpkgpython_PYTHON = kernel_shared_modules.py diff --git a/src/KERNEL_PY/salome_genericobj.py b/src/KERNEL_PY/salome_genericobj.py new file mode 100644 index 000000000..053f4ae1b --- /dev/null +++ b/src/KERNEL_PY/salome_genericobj.py @@ -0,0 +1,24 @@ +""" + When imported this module adds to CORBA objref from GenericObj type + automatic management of reference count + The reference count is incremented when the local proxy is created (assignment of __omni_obj attribute) + and is decremented when the local proxy is deleted (call of __del__) + + The GenericObj class for proxy is modified by adding two methods : __del__ and __setattr__ + The module must be imported before any other import of SALOME CORBA module +""" +import omniORB +import SALOME + +def mydel(self): + self.Destroy() + omniORB.CORBA.Object.__del__(self) + +def mysetattr(self,attr,value): + self.__dict__[attr]=value + if attr == "__omni_obj": + self.Register() + +SALOME._objref_GenericObj.__del__=mydel +SALOME._objref_GenericObj.__setattr__=mysetattr + -- 2.39.2