[omniORB] Should omniORBpy require a C++ python interpreter?

Duncan Grisby dgrisby@uk.research.att.com
Fri, 25 Feb 2000 17:19:30 +0000


On Friday 25 February, Bruce Visscher wrote:

> Does omniORBpy require that the python interpreter's main be
> compiled with a C++ compiler (and linked with a C++ linker if
> applicable)?
>
> The reason I ask is because I have seen some discussion on
> comp.lang.python that indicates that if you extend python with C++
> that this might be necessary.

There is a lot of misinformation about C++ and Python around. Many
sources claim that it is necessary to link main() with C++ in order to
support static initialisers, and maybe exceptions. This is sort of
true, but also almost completely irrelevant.

The C++ language specification says that static initialisers are only
guaranteed to run if the main() function is compiled and linked with
C++. Furthermore, they are only guaranteed to run if they are visible
at the time main() is about to be run. The way Python extensions
normally work, dynamic loading with libdl or equivalent, means that
this second condition is not usually true.

So, in fact, no matter how you compile Python, there is no guarantee
that static initialisers will be run. Unfortunately, there are some
things in omniORB which have to be statically initialised so this is a
potential problem. Fortunately, the vast majority of platforms _do_
run static initialisers when they load dynamic libraries. Windows
does, as should any Unix which uses ELF. The only platform I know of
that has a problem is AIX, which requires a patch (thanks to Gary
Duzan) to Python before it works. The patch is in the omniORBpy
distribution (although I need to write something about it in the
release notes).

If there are any platforms where there is no way of running static
initialisers when libraries are dynamically loaded, the solution will
be to build a python executable with the omniORB libraries linked into
it, and a main() compiled with C++. That way, the C++ specification
says the initialisers will be called. I'll be surprised if there are
any modern platforms which require this.

If all this discussion has concerned people who just use the C++ ORB,
but need Python for the new omniidl in omniORB 3, there's no need to
worry. In omniidl, I've been careful to avoid any statically
initialised data, so there's nothing to go wrong.

Cheers,

Duncan.

-- 
 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- http://www.uk.research.att.com/~dpg1 --