dynamic loading on SunOS 4.1

Guido.van.Rossum@cwi.nl
Mon, 31 Jan 1994 13:03:38 +0100

I've had a number of complaints about using shared libraries on SunOS
4.1. I now believe that this is caused by the GNU loader which
doesn't handle shared libraries. The configure script detects the
presence of <dlfnc.h> and tells the import.c file, which then attempts
to use shared libraries.

Would the people who have these problems be so kind to try out the
following (yes *unofficial*) patch to configure and Python/import.c?
It adds a test for the dlopen() function and turns on use of shared
libraries only if that exists as well. Let me know if it works!

(A quicker work-around would be to simply #undef HAVE_DLFNC_H in
config.h.)

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>

===================================================================
RCS file: /hosts/voorn/ufs/guido/python-RCS/new/RCS/configure,v
retrieving revision 1.2.4.13
diff -c -r1.2.4.13 configure
*** 1.2.4.13 1994/01/18 15:54:52
--- configure 1994/01/31 11:57:59
***************
*** 1129,1135 ****


# checks for library functions
! for func in clock ftime gettimeofday getpeername getpgrp getpid getwd lstat nice readlink select setsid setpgid setpgrp siginterrupt symlink tcgetpgrp tcsetpgrp times uname waitpid
do
trfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
echo checking for ${func}
--- 1155,1161 ----


# checks for library functions
! for func in clock dlopen ftime gettimeofday getpeername getpgrp getpid getwd lstat nice readlink select setsid setpgid setpgrp siginterrupt symlink tcgetpgrp tcsetpgrp times uname waitpid
do
trfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
echo checking for ${func}
===================================================================
RCS file: /hosts/voorn/ufs/guido/python-RCS/new/Python/RCS/import.c,v
retrieving revision 2.30.2.7
diff -c -r2.30.2.7 import.c
*** 2.30.2.7 1994/01/12 09:53:19
--- import.c 1994/01/31 11:52:10
***************
*** 50,78 ****

#ifdef WITH_SGI_DL
#define USE_DL
- #undef HAVE_DLFCN_H
#endif

#ifdef WITH_DL_DLD
#define USE_DL
- #undef HAVE_DLFCN_H
#endif

! #ifdef HAVE_DLFCN_H
#define USE_DL
#endif

#ifdef USE_DL

! #ifdef HAVE_DLFCN_H
#include <dlfcn.h>
typedef void (*dl_funcptr)();
#ifndef RTLD_NOW
#define RTLD_NOW 2
#endif
! #else /* !HAVE_DLFCN_H */
#include "dl.h"
! #endif /* !HAVE_DLFCN_H */

extern char *getprogramname();

--- 50,77 ----

#ifdef WITH_SGI_DL
#define USE_DL
#endif

#ifdef WITH_DL_DLD
#define USE_DL
#endif

! #if !defined(USE_DL) && defined(HAVE_DLFCN_H) && defined(HAVE_DLOPEN)
! #define USE_SHLIB
#define USE_DL
#endif

#ifdef USE_DL

! #ifdef USE_SHLIB
#include <dlfcn.h>
typedef void (*dl_funcptr)();
#ifndef RTLD_NOW
#define RTLD_NOW 2
#endif
! #else /* !USE_SHLIB */
#include "dl.h"
! #endif /* !USE_SHLIB */

extern char *getprogramname();

***************
*** 128,138 ****
enum filetype type;
} filetab[] = {
#ifdef USE_DL
! #ifdef HAVE_DLFCN_H
{"module.so", "rb", C_EXTENSION},
! #else /* !HAVE_DLFCN_H */
{"module.o", "rb", C_EXTENSION},
! #endif /* !HAVE_DLFCN_H */
#endif /* USE_DL */
{".py", "r", PY_SOURCE},
{".pyc", "rb", PY_COMPILED},
--- 127,137 ----
enum filetype type;
} filetab[] = {
#ifdef USE_DL
! #ifdef USE_SHLIB
{"module.so", "rb", C_EXTENSION},
! #else /* !USE_SHLIB */
{"module.o", "rb", C_EXTENSION},
! #endif /* !USE_SHLIB */
#endif /* USE_DL */
{".py", "r", PY_SOURCE},
{".pyc", "rb", PY_COMPILED},
***************
*** 304,310 ****
dl_funcptr p;
fclose(fp);
sprintf(funcname, "init%s", name);
! #ifdef HAVE_DLFCN_H
{
/* RTLD_NOW: resolve externals now
(i.e. core dump now if some are missing) */
--- 303,309 ----
dl_funcptr p;
fclose(fp);
sprintf(funcname, "init%s", name);
! #ifdef USE_SHLIB
{
/* RTLD_NOW: resolve externals now
(i.e. core dump now if some are missing) */
***************
*** 315,323 ****
}
p = (dl_funcptr) dlsym(handle, funcname);
}
! #else /* !HAVE_DLFCN_H */
p = dl_loadmod(getprogramname(), namebuf, funcname);
! #endif /* !HAVE_DLFCN_H */
if (p == NULL) {
err_setstr(ImportError,
"dynamic module does not define init function");
--- 314,322 ----
}
p = (dl_funcptr) dlsym(handle, funcname);
}
! #else /* !USE_SHLIB */
p = dl_loadmod(getprogramname(), namebuf, funcname);
! #endif /* !USE_SHLIB */
if (p == NULL) {
err_setstr(ImportError,
"dynamic module does not define init function");