AIX, xlC, and C++ Modules
Gary Duzan
gduzan at gte.com
Fri Nov 12 18:20:02 EST 1999
While working on a port of the new OmniORBpy stuff to AIX, I
came across an interesting issue with python's module loader.
importdl.c uses the load() call on AIX to do the loading, which
does fine with C and a fair amount of C++. However, the C++ module
I was trying to load includes static variables with constructors,
and AIX's load() call doesn't handle them properly. To do so, you
have to go to the C++ side of the house and call loadAndInit(),
which is otherwise identical but does the initialization properly.
I'll include the changes that work for me below. I also tried
reverting to dlopen(), but this seemed not to resolve the
Py_InitModule symbol correctly, leading to a quick core dump.
The patch enclosed fixes the problem for me. If anyone else
can suggest a better alternative, I'd be glad to hear it.
Setup: AIX 4.2.1, C Set++ (xlC) 3.1.4, --with_thread, CC=xlC_r.
Gary Duzan
GTE Laboratories
-------------- next part --------------
--- Python-1.5.2/Python/importdl.c Wed Jan 27 12:53:10 1999
+++ Python-1.5.2/Python/importdl.c.new Fri Nov 12 17:50:50 1999
@@ -178,7 +178,12 @@
#define DYNAMIC_LINK
#define SHORT_EXT ".so"
#define LONG_EXT "module.so"
+#ifdef USE_SHLIB
+#include <dlfcn.h>
+#else
#include <sys/ldr.h>
+#include "/usr/lpp/xlC/include/load.h"
+#endif
typedef void (*dl_funcptr)();
#define _DL_FUNCPTR_DEFINED
static int aix_getoldmodules(void **);
@@ -458,7 +463,7 @@
p = (dl_funcptr) dlsym(handle, funcname);
}
#endif /* USE_SHLIB */
-#ifdef _AIX
+#if defined(_AIX) && !defined(USE_SHLIB)
/*
-- Invoke load() with L_NOAUTODEFER leaving the imported symbols
-- of the shared module unresolved. Thus we have to resolve them
@@ -473,7 +478,8 @@
if (!staticmodlistptr)
if (aix_getoldmodules(&staticmodlistptr) == -1)
return NULL;
- p = (dl_funcptr) load(pathname, L_NOAUTODEFER, 0);
+ /* p = (dl_funcptr) load(pathname, L_NOAUTODEFER, 0); */
+ p = (dl_funcptr) loadAndInit(pathname, L_NOAUTODEFER, 0);
if (p == NULL) {
aix_loaderror(pathname);
return NULL;
@@ -877,7 +883,7 @@
}
-#ifdef _AIX
+#if defined(_AIX) && !defined(USE_SHLIB)
#include <ctype.h> /* for isdigit() */
#include <errno.h> /* for global errno */
More information about the Python-list
mailing list