diff options
Diffstat (limited to 'Python/dynload_shlib.c')
-rw-r--r-- | Python/dynload_shlib.c | 111 |
1 files changed, 61 insertions, 50 deletions
diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c index c51f97a..17ebab1 100644 --- a/Python/dynload_shlib.c +++ b/Python/dynload_shlib.c @@ -2,7 +2,6 @@ /* Support for dynamic loading of extension modules */ #include "Python.h" -#include "pycore_pystate.h" #include "importdl.h" #include <sys/types.h> @@ -19,6 +18,10 @@ #ifdef HAVE_DLFCN_H #include <dlfcn.h> +#else +#if defined(PYOS_OS2) && defined(PYCC_GCC) +#include "dlfcn.h" +#endif #endif #if (defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__) @@ -27,38 +30,44 @@ #define LEAD_UNDERSCORE "" #endif -/* The .so extension module ABI tag, supplied by the Makefile via - Makefile.pre.in and configure. This is used to discriminate between - incompatible .so files so that extensions for different Python builds can - live in the same directory. E.g. foomodule.cpython-32.so -*/ -const char *_PyImport_DynLoadFiletab[] = { +const struct filedescr _PyImport_DynLoadFiletab[] = { #ifdef __CYGWIN__ - ".dll", -#else /* !__CYGWIN__ */ - "." SOABI ".so", -#ifdef ALT_SOABI - "." ALT_SOABI ".so", + {".dll", "rb", C_EXTENSION}, + {"module.dll", "rb", C_EXTENSION}, +#else +#if defined(PYOS_OS2) && defined(PYCC_GCC) + {".pyd", "rb", C_EXTENSION}, + {".dll", "rb", C_EXTENSION}, +#else +#ifdef __VMS + {".exe", "rb", C_EXTENSION}, + {".EXE", "rb", C_EXTENSION}, + {"module.exe", "rb", C_EXTENSION}, + {"MODULE.EXE", "rb", C_EXTENSION}, +#else + {".so", "rb", C_EXTENSION}, + {"module.so", "rb", C_EXTENSION}, +#endif #endif - ".abi" PYTHON_ABI_STRING ".so", - ".so", -#endif /* __CYGWIN__ */ - NULL, +#endif + {0, 0} }; static struct { dev_t dev; +#ifdef __VMS + ino_t ino[3]; +#else ino_t ino; +#endif void *handle; } handles[128]; static int nhandles = 0; -dl_funcptr -_PyImport_FindSharedFuncptr(const char *prefix, - const char *shortname, - const char *pathname, FILE *fp) +dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, + const char *pathname, FILE *fp) { dl_funcptr p; void *handle; @@ -73,56 +82,58 @@ _PyImport_FindSharedFuncptr(const char *prefix, } PyOS_snprintf(funcname, sizeof(funcname), - LEAD_UNDERSCORE "%.20s_%.200s", prefix, shortname); + LEAD_UNDERSCORE "init%.200s", shortname); if (fp != NULL) { int i; - struct _Py_stat_struct status; - if (_Py_fstat(fileno(fp), &status) == -1) - return NULL; + struct stat statb; + fstat(fileno(fp), &statb); for (i = 0; i < nhandles; i++) { - if (status.st_dev == handles[i].dev && - status.st_ino == handles[i].ino) { + if (statb.st_dev == handles[i].dev && + statb.st_ino == handles[i].ino) { p = (dl_funcptr) dlsym(handles[i].handle, funcname); return p; } } if (nhandles < 128) { - handles[nhandles].dev = status.st_dev; - handles[nhandles].ino = status.st_ino; + handles[nhandles].dev = statb.st_dev; +#ifdef __VMS + handles[nhandles].ino[0] = statb.st_ino[0]; + handles[nhandles].ino[1] = statb.st_ino[1]; + handles[nhandles].ino[2] = statb.st_ino[2]; +#else + handles[nhandles].ino = statb.st_ino; +#endif } } - dlopenflags = _PyInterpreterState_Get()->dlopenflags; +#if !(defined(PYOS_OS2) && defined(PYCC_GCC)) + dlopenflags = PyThreadState_GET()->interp->dlopenflags; +#endif + + if (Py_VerboseFlag) + PySys_WriteStderr("dlopen(\"%s\", %x);\n", pathname, + dlopenflags); + +#ifdef __VMS + /* VMS currently don't allow a pathname, use a logical name instead */ + /* Concatenate 'python_module_' and shortname */ + /* so "import vms.bar" will use the logical python_module_bar */ + /* As C module use only one name space this is probably not a */ + /* important limitation */ + PyOS_snprintf(pathbuf, sizeof(pathbuf), "python_module_%-.200s", + shortname); + pathname = pathbuf; +#endif handle = dlopen(pathname, dlopenflags); if (handle == NULL) { - PyObject *mod_name; - PyObject *path; - PyObject *error_ob; const char *error = dlerror(); if (error == NULL) error = "unknown dlopen() error"; - error_ob = PyUnicode_FromString(error); - if (error_ob == NULL) - return NULL; - mod_name = PyUnicode_FromString(shortname); - if (mod_name == NULL) { - Py_DECREF(error_ob); - return NULL; - } - path = PyUnicode_FromString(pathname); - if (path == NULL) { - Py_DECREF(error_ob); - Py_DECREF(mod_name); - return NULL; - } - PyErr_SetImportError(error_ob, mod_name, path); - Py_DECREF(error_ob); - Py_DECREF(mod_name); - Py_DECREF(path); + PyErr_SetString(PyExc_ImportError, error); return NULL; } if (fp != NULL && nhandles < 128) |