[omniORB] A patch for omniidl2

Harri Pasanen harri.pasanen@trema.com
Thu, 20 Jan 2000 13:33:03 +0100


Hi,

I've implemented the following patch against omniidl2.  Motivation for
the patch was a linking problem when dll-files were created from idl
generated code (Win-NT).

What it does:

Modified exception class constructor so that it is not inlined.
Previously it caused problems on NT, as the constructor refers 
to static class variables.  When the exception class was instantiated in
another dll, due to inlining it referred to the the static class
variables.  Those variables from the other dll were not 
found at link time.

Example:

A.idl that defines an exception, is compiled to A.dll

B.idl has an interface that raises the exception from A, 
and is also compiled to B.dll

Previously, B.dll would not link.  Visual C++ requires that static class
member variables have  __declspec(dllimport) definition in front if
those are imported from a dll.

In Omniidl2 generated code there is a macro USE_stub_in_nt_dll for that
purpose, but we  cannot define that macro when compiling code generated
from B.idl, as B.hh also has its own static member variables that can't
have it defined when compiling BSK.cpp.  As B.hh includes A.hh, we would
need to have USE_stub_in_nt_dll defined only for A.hh when included from
B.hh, but not for B.hh itself.

To get around this problem I moved the exception constructor to the .cc
file, so that it is not inlined.  This way a class static variable from
another DLL or shared lib is never accessed directly.

This might even be beneficial for Unix shared libs. A collegue tells me
it is not a good idea in general to refer to static variables in other
shared libraries.  

I'm not familiar enough with omniidl2 to say if this issue only applies
to  exceptions, or if there are other places to patch.

Regards,

Harri Pasanen


--8<-----8<------8<-----8<----8<-----8<------8<-----8<-----8<-----

*** o2be_exception.cc   Thu Jan 20 10:54:21 2000
---
/work/harri/src/omniORB_280/src/tool/omniidl2/omniORB2_be/o2be_exception.ccT
ue Sep 14 18:57:30 1999
***************
*** 212,218 ****
    }

    IND(s); s << "\n";
!   IND(s); s << uqname() << "();\n";
    IND(s); s << uqname() << "(const " << uqname() << " &);\n";
    {
      UTL_ScopeActiveIterator i(this, UTL_Scope::IK_decls);
--- 212,223 ----
    }

    IND(s); s << "\n";
!   IND(s); s << uqname() << "() {\n";
!   INC_INDENT_LEVEL();
!   IND(s); s << "pd_insertToAnyFn    = insertToAnyFn;\n";
!   IND(s); s << "pd_insertToAnyFnNCP = insertToAnyFnNCP;\n";
!   DEC_INDENT_LEVEL();
!   IND(s); s << "}\n";
    IND(s); s << uqname() << "(const " << uqname() << " &);\n";
    {
      UTL_ScopeActiveIterator i(this, UTL_Scope::IK_decls);
***************
*** 330,342 ****
    IND(s); s << "CORBA::Exception::insertExceptionToAnyNCP "
            << fqname() << "::insertToAnyFnNCP = 0;\n\n";

-   IND(s); s << fqname() << "::" << uqname() << "()\n";
-   IND(s); s << "{\n";
-   INC_INDENT_LEVEL();
-   IND(s); s << "pd_insertToAnyFn    = insertToAnyFn;\n";
-   IND(s); s << "pd_insertToAnyFnNCP = insertToAnyFnNCP;\n";
-   DEC_INDENT_LEVEL();
-   IND(s); s << "}\n\n";

    IND(s); s << fqname() << "::" << uqname()
            << "(const " << fqname() << " &_s) :
CORBA::UserException(_s) \n";
--- 335,340 ----