]> granicus.if.org Git - python/commitdiff
Cleanup patches from Greg Stein:
authorGuido van Rossum <guido@python.org>
Wed, 22 Dec 1999 14:09:35 +0000 (14:09 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 22 Dec 1999 14:09:35 +0000 (14:09 +0000)
* in import.c, #ifdef out references to dynamic loading based on
  HAVE_DYNAMIC_LOADING

* clean out the platform-specific crud from importdl.c.
  [ maybe fold this function into import.c and drop the importdl.c file? Greg.]

* change GetDynLoadFunc's "funcname" parameter to "shortname". change
  "name" to "fqname" for clarification.

* each GetDynLoadFunc now creates its own funcname value.

  WARNING: as I mentioned previously, we may run into an issue with a
  missing "_" on some platforms. Testing will show this pretty quickly,
  however.

* move pathname munging into dynload_shlib.c

Python/dynload_aix.c
Python/dynload_beos.c
Python/dynload_dl.c
Python/dynload_hpux.c
Python/dynload_mac.c
Python/dynload_next.c
Python/dynload_os2.c
Python/dynload_shlib.c
Python/dynload_win.c
Python/import.c
Python/importdl.c

index f8f431754d42bb82240b4c14b23c7c1d248ad895..0e271521aa11524d47293b129464bcd7d0184e78 100644 (file)
@@ -202,7 +202,7 @@ aix_loaderror(pathname)
 }
 
 
-dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                                    const char *pathname, FILE *fp)
 {
        dl_funcptr p;
index 4b4a49a57da964044fbc5e917d9a15c17330fa01..717d5a9510a85a2f945f8dfd2859e708b58abbb5 100644 (file)
@@ -185,13 +185,14 @@ static void beos_add_dyn( char *name, image_id id )
 
 
 
-dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                                    const char *pathname, FILE *fp)
 {
        dl_funcptr p;
        image_id the_id;
        status_t retval;
        char fullpath[PATH_MAX];
+       char funcname[258];
 
        if( Py_VerboseFlag ) {
                printf( "load_add_on( %s )\n", pathname );
@@ -236,6 +237,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
                return NULL;
        }
 
+       sprintf(funcname, "init%.200s", shortname);
        if( Py_VerboseFlag ) {
                printf( "get_image_symbol( %s )\n", funcname );
        }
@@ -274,7 +276,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
        /* Save the module name and image ID for later so we can clean up
         * gracefully.
         */
-       beos_add_dyn( name, the_id );
+       beos_add_dyn( fqname, the_id );
 
        return p;
 }
index 3b445ceb4f2f623cc5c824d34b516965989f7857..45dcff740ab61e20ed2723ec059e181025f8abb9 100644 (file)
@@ -46,8 +46,11 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
 };
 
 
-dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                                    const char *pathname, FILE *fp)
 {
+       char funcname[258];
+
+       sprintf(funcname, "init%.200s", shortname);
        return dl_loadmod(Py_GetProgramName(), pathname, funcname);
 }
index 4379cbee212ab300978a42b7655ddd3e801f5dfb..b8a5ffce2383001bd13e3a0565b5f41a9e57ce5d 100644 (file)
@@ -37,6 +37,11 @@ PERFORMANCE OF THIS SOFTWARE.
 #include "Python.h"
 #include "importdl.h"
 
+#if defined(__hp9000s300)
+#define FUNCNAME_PATTERN "_init%.200s"
+#else
+#define FUNCNAME_PATTERN "init%.200s"
+#endif
 
 const struct filedescr _PyImport_DynLoadFiletab[] = {
        {".sl", "rb", C_EXTENSION},
@@ -44,12 +49,13 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
        {0, 0}
 };
 
-dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                                    const char *pathname, FILE *fp)
 {
        dl_funcptr p;
        shl_t lib;
        int flags;
+       char funcname[258];
 
        flags = BIND_FIRST | BIND_DEFERRED;
        if (Py_VerboseFlag) {
@@ -67,6 +73,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
                PyErr_SetString(PyExc_ImportError, buf);
                return NULL;
        }
+       sprintf(funcname, FUNCNAME_PATTERN, shortname);
        if (Py_VerboseFlag)
                printf("shl_findsym %s\n", funcname);
        shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p);
index 91619956e99ab62f6ad25ad258b2116de9e46c72..58c57d507417c7955fe55b2451c46c47ae8ff980 100644 (file)
@@ -59,10 +59,11 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
 };
 
 
-dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                                    const char *pathname, FILE *fp)
 {
        dl_funcptr p;
+       char funcname[258];
 
        /*
        ** Dynamic loading of CFM shared libraries on the Mac.  The
@@ -121,6 +122,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
                return NULL;
        }
        /* Locate the address of the correct init function */
+       sprintf(funcname, "init%.200s", shortname);
        err = FindSymbol(connID, Pstring(funcname), &symAddr, &class);
        if ( err ) {
                sprintf(buf, "%s: %.200s",
index bcb9e4bb372f3db0d8d380b044a486b1d50a9ca6..5088b059d8c8bb1070ced095a8ae3d2c4a1a1c16 100644 (file)
@@ -68,10 +68,13 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
        {0, 0}
 };
 
-dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                                    const char *pathname, FILE *fp)
 {
        dl_funcptr p = NULL;
+       char funcname[258];
+
+       sprintf(funcname, "_init%.200s", shortname);
 
 #ifdef USE_RLD
        {
index 6090c3300ba2fcffd88c593bf05973499b4a2a27..528e7dc6006b13f9196291cd706b4702bbbe2b7a 100644 (file)
@@ -45,13 +45,14 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
        {0, 0}
 };
 
-dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                                    const char *pathname, FILE *fp)
 {
        dl_funcptr p;
        APIRET  rc;
        HMODULE hDLL;
        char failreason[256];
+       char funcname[258];
 
        rc = DosLoadModule(failreason,
                           sizeof(failreason),
@@ -67,6 +68,7 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
                return NULL;
        }
 
+       sprintf(funcname, "init%.200s", shortname);
        rc = DosQueryProcAddr(hDLL, 0L, funcname, &p);
        if (rc != NO_ERROR)
                p = NULL; /* Signify Failure to Acquire Entrypoint */
index d3c5a6ee34aae332735dfb502b033525a94df5b1..2823bbbd5aa0f78c7644b4f08fe83179c5f55bef 100644 (file)
@@ -65,11 +65,22 @@ static struct {
 static int nhandles = 0;
 
 
-dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                                    const char *pathname, FILE *fp)
 {
        dl_funcptr p;
        void *handle;
+       char funcname[258];
+       char pathbuf[260];
+
+       if (strchr(pathname, '/') == NULL) {
+               /* Prefix bare filename with "./" */
+               sprintf(pathbuf, "./%-.255s", pathname);
+               pathname = pathbuf;
+       }
+
+       /* ### should there be a leading underscore for some platforms? */
+       sprintf(funcname, "init%.200s", shortname);
 
        if (fp != NULL) {
                int i;
index 9e68cac35d9a3888359010faa2c9587d5b3ba2bf..08a2a895fe38c26f5f620a8bd17d8d7a470b25d2 100644 (file)
@@ -49,10 +49,13 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
 };
 
 
-dl_funcptr _PyImport_GetDynLoadFunc(const char *name, const char *funcname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                                    const char *pathname, FILE *fp)
 {
        dl_funcptr p;
+       char funcname[258];
+
+       sprintf(funcname, "init%.200s", shortname);
 
 #ifdef MS_WIN32
        {
index e10463b28835801f79c4701c944a870a4b39d17b..bce1b57888c58db1d4ad47bd2845dff36462c405 100644 (file)
@@ -1234,9 +1234,11 @@ load_module(name, fp, buf, type)
                m = load_compiled_module(name, buf, fp);
                break;
 
+#ifdef HAVE_DYNAMIC_LOADING
        case C_EXTENSION:
                m = _PyImport_LoadDynamicModule(name, buf, fp);
                break;
+#endif
 
 #ifdef macintosh
        case PY_RESOURCE:
@@ -2158,6 +2160,8 @@ imp_load_compiled(self, args)
        return m;
 }
 
+#ifdef HAVE_DYNAMIC_LOADING
+
 static PyObject *
 imp_load_dynamic(self, args)
        PyObject *self;
@@ -2180,6 +2184,8 @@ imp_load_dynamic(self, args)
        return m;
 }
 
+#endif /* HAVE_DYNAMIC_LOADING */
+
 static PyObject *
 imp_load_source(self, args)
        PyObject *self;
@@ -2330,7 +2336,9 @@ static PyMethodDef imp_methods[] = {
        {"is_builtin",          imp_is_builtin,         1},
        {"is_frozen",           imp_is_frozen,          1},
        {"load_compiled",       imp_load_compiled,      1},
+#ifdef HAVE_DYNAMIC_LOADING
        {"load_dynamic",        imp_load_dynamic,       1},
+#endif
        {"load_package",        imp_load_package,       1},
 #ifdef macintosh
        {"load_resource",       imp_load_resource,      1},
index 6b3eccc98fecbb32681981f947ef78fac5b726aa..8dd14b86021b790b39e2ce496a18c37ae4a51ade 100644 (file)
@@ -30,59 +30,22 @@ PERFORMANCE OF THIS SOFTWARE.
 ******************************************************************/
 
 /* Support for dynamic loading of extension modules */
-/* If no dynamic linking is supported, this file still generates some code! */
 
 #include "Python.h"
-#include "importdl.h"
-
-/* Explanation of some of the the various #defines used by dynamic linking...
 
-   symbol      -- defined for:
-
-   HAVE_DYNAMIC_LOADING -- any kind of dynamic linking (from ./configure)
-   USE_SHLIB   -- SunOS or IRIX 5 (SVR4?) shared libraries
-   _AIX                -- AIX style dynamic linking
-   __NetBSD__  -- NetBSD shared libraries
-                  (assuming dlerror() was introduced between 1.2 and 1.3)
-   __BEOS__ -- BeOS shared libraries - defined by the compiler
+/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
+   supported on this platform. configure will then compile and link in one
+   of the dynload_*.c files, as appropriate. We will call a function in
+   those modules to get a function pointer to the module's init function.
 */
-
-/* Configure dynamic linking */
-
 #ifdef HAVE_DYNAMIC_LOADING
 
+#include "importdl.h"
+
 extern dl_funcptr _PyImport_GetDynLoadFunc(const char *name,
-                                          const char *funcname,
+                                          const char *shortname,
                                           const char *pathname, FILE *fp);
 
-/* ### given NeXT, is WITH_DYLD not necessary? */
-
-#if defined(__hp9000s300) || (defined(__NetBSD__) || defined(__FreeBSD__)) && !defined(__ELF__) || defined(__OpenBSD__) || defined(__BORLANDC__) || defined(NeXT) || defined(WITH_DYLD)
-#define FUNCNAME_PATTERN "_init%.200s"
-#else
-#define FUNCNAME_PATTERN "init%.200s"
-#endif
-
-/* ### temporary, for setting USE_SHLIB */
-#if defined(__NetBSD__) && (NetBSD < 199712)
-#define USE_SHLIB
-#else
-#if defined(HAVE_DLOPEN) || defined(M_UNIX)
-#define USE_SHLIB
-#endif
-#endif
-#ifdef _AIX
-#undef USE_SHLIB
-#endif
-#ifdef __BEOS__
-#undef USE_SHLIB
-#endif
-
-#endif /* HAVE_DYNAMIC_LOADING */
-
-#ifdef NO_DYNAMIC_LINK
-#undef HAVE_DYNAMIC_LOADING
-#endif
 
 
 PyObject *
@@ -91,24 +54,9 @@ _PyImport_LoadDynamicModule(name, pathname, fp)
        char *pathname;
        FILE *fp;
 {
-#ifndef HAVE_DYNAMIC_LOADING
-       PyErr_SetString(PyExc_ImportError,
-                       "dynamically linked modules not supported");
-       return NULL;
-#else
        PyObject *m, *d, *s;
-       char funcname[258];
        char *lastdot, *shortname, *packagecontext;
-       dl_funcptr p = NULL;
-
-#ifdef USE_SHLIB
-       char pathbuf[260];
-       if (strchr(pathname, '/') == NULL) {
-               /* Prefix bare filename with "./" */
-               sprintf(pathbuf, "./%-.255s", pathname);
-               pathname = pathbuf;
-       }
-#endif /* USE_SHLIB */
+       dl_funcptr p;
 
        if ((m = _PyImport_FindExtension(name, pathname)) != NULL) {
                Py_INCREF(m);
@@ -123,15 +71,14 @@ _PyImport_LoadDynamicModule(name, pathname, fp)
                packagecontext = name;
                shortname = lastdot+1;
        }
-       sprintf(funcname, FUNCNAME_PATTERN, shortname);
 
-       p = _PyImport_GetDynLoadFunc(name, funcname, pathname, fp);
+       p = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp);
        if (PyErr_Occurred())
                return NULL;
        if (p == NULL) {
                PyErr_Format(PyExc_ImportError,
-                  "dynamic module does not define init function (%.200s)",
-                            funcname);
+                  "dynamic module does not define init function (init%.200s)",
+                            shortname);
                return NULL;
        }
        _Py_PackageContext = packagecontext;
@@ -160,5 +107,6 @@ _PyImport_LoadDynamicModule(name, pathname, fp)
                        name, pathname);
        Py_INCREF(m);
        return m;
-#endif /* HAVE_DYNAMIC_LOADING */
 }
+
+#endif /* HAVE_DYNAMIC_LOADING */