Kaydet (Commit) 25df8adb authored tarafından Michael Stahl's avatar Michael Stahl

cli_ure: adapt destructors in cli_uno library to "C++/CLI"

commit 4b56d82c converted the cli_uno
library from "Managed C++" to "C++/CLI", but forgot one detail:

The destructors on "ref" classes were mapped to Finalize() methods in
the old syntax, but the new one maps them to Dispose() methods, which
are only invoked on stack-allocated objects.  Presumably this omission
results in leaking of native C++ UNO objects.

Reading the C++/CLI documentation i get the impression that:
1) the destructor should explicitly call the finalizer
2) the CLR will not call the finalizer itself iff the destructor is
   invoked

http://msdn.microsoft.com/en-us/library/ms235315.aspx
http://msdn.microsoft.com/en-us/library/ke3a209d%28v=vs.110%29.aspx

Change-Id: I509d9b69a399c3d7d6597060ab9b7c78c5916e11
Reviewed-on: https://gerrit.libreoffice.org/11132Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
Tested-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst 64c187b8
...@@ -47,13 +47,17 @@ inline Cli_environment::Cli_environment() ...@@ -47,13 +47,17 @@ inline Cli_environment::Cli_environment()
#endif #endif
} }
Cli_environment::~Cli_environment() Cli_environment::~Cli_environment() ///< IDisposable Cli_environment::Dispose()
{
this->!Cli_environment(); // call finalizer
}
Cli_environment::!Cli_environment() ///< Cli_environment::Finalize()
{ {
OSL_ENSURE(_numRegisteredObjects == 0, OSL_ENSURE(_numRegisteredObjects == 0,
"cli uno bridge: CLI environment contains unrevoked objects"); "cli uno bridge: CLI environment contains unrevoked objects");
} }
System::Object^ Cli_environment::registerInterface( System::Object^ Cli_environment::registerInterface(
System::Object^ obj, System::String^ oid) System::Object^ obj, System::String^ oid)
{ {
......
...@@ -56,6 +56,7 @@ public: ...@@ -56,6 +56,7 @@ public:
inline Cli_environment(); inline Cli_environment();
~Cli_environment(); ~Cli_environment();
!Cli_environment();
/** /**
Registers an UNO object as being mapped by this bridge. The resulting Registers an UNO object as being mapped by this bridge. The resulting
......
...@@ -87,7 +87,13 @@ UnoInterfaceInfo::UnoInterfaceInfo(Bridge const * bridge, uno_Interface* unoI, ...@@ -87,7 +87,13 @@ UnoInterfaceInfo::UnoInterfaceInfo(Bridge const * bridge, uno_Interface* unoI,
} }
} }
} }
UnoInterfaceInfo::~UnoInterfaceInfo()
UnoInterfaceInfo::~UnoInterfaceInfo() ///< IDisposable UnoInterfaceInfo::Dispose()
{
this->!UnoInterfaceInfo(); // call finalizer
}
UnoInterfaceInfo::!UnoInterfaceInfo() ///< UnoInterfaceInfo::Finalize()
{ {
//accessing unmanaged objects is ok. //accessing unmanaged objects is ok.
m_bridge->m_uno_env->revokeInterface( m_bridge->m_uno_env->revokeInterface(
...@@ -124,7 +130,12 @@ UnoInterfaceProxy::UnoInterfaceProxy( ...@@ -124,7 +130,12 @@ UnoInterfaceProxy::UnoInterfaceProxy(
} }
UnoInterfaceProxy::~UnoInterfaceProxy() UnoInterfaceProxy::~UnoInterfaceProxy() ///< IDisposable UnoInterfaceProxy::Dispose()
{
this->!UnoInterfaceProxy(); // call finalizer
}
UnoInterfaceProxy::!UnoInterfaceProxy() ///< UnoInterfaceProxy::Finalize()
{ {
#if OSL_DEBUG_LEVEL >= 2 #if OSL_DEBUG_LEVEL >= 2
sd::Trace::WriteLine(System::String::Format( sd::Trace::WriteLine(System::String::Format(
...@@ -140,7 +151,6 @@ UnoInterfaceProxy::~UnoInterfaceProxy() ...@@ -140,7 +151,6 @@ UnoInterfaceProxy::~UnoInterfaceProxy()
m_bridge->release(); m_bridge->release();
} }
System::Object^ UnoInterfaceProxy::create( System::Object^ UnoInterfaceProxy::create(
Bridge * bridge, Bridge * bridge,
uno_Interface * pUnoI, uno_Interface * pUnoI,
......
...@@ -46,6 +46,8 @@ public: ...@@ -46,6 +46,8 @@ public:
UnoInterfaceInfo(Bridge const * bridge, uno_Interface* unoI, UnoInterfaceInfo(Bridge const * bridge, uno_Interface* unoI,
typelib_InterfaceTypeDescription* td); typelib_InterfaceTypeDescription* td);
~UnoInterfaceInfo(); ~UnoInterfaceInfo();
!UnoInterfaceInfo();
uno_Interface * m_unoI; // wrapped interface uno_Interface * m_unoI; // wrapped interface
System::Type ^ m_type; System::Type ^ m_type;
typelib_InterfaceTypeDescription* m_typeDesc; typelib_InterfaceTypeDescription* m_typeDesc;
...@@ -112,6 +114,7 @@ public: ...@@ -112,6 +114,7 @@ public:
void addUnoInterface(uno_Interface* pUnoI, void addUnoInterface(uno_Interface* pUnoI,
typelib_InterfaceTypeDescription* pTd); typelib_InterfaceTypeDescription* pTd);
~UnoInterfaceProxy(); ~UnoInterfaceProxy();
!UnoInterfaceProxy();
/** /**
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment