+++ /dev/null
-\r
-/* Support for dynamic loading of extension modules */\r
-\r
-#include "Python.h"\r
-#include "importdl.h"\r
-\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-\r
-#if defined(__NetBSD__)\r
-#include <sys/param.h>\r
-#if (NetBSD < 199712)\r
-#include <nlist.h>\r
-#include <link.h>\r
-#define dlerror() "error in dynamic linking"\r
-#endif\r
-#endif /* NetBSD */\r
-\r
-#ifdef HAVE_DLFCN_H\r
-#include <dlfcn.h>\r
-#else\r
-#if defined(PYOS_OS2) && defined(PYCC_GCC)\r
-#include "dlfcn.h"\r
-#endif\r
-#endif\r
-\r
-#if (defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__)\r
-#define LEAD_UNDERSCORE "_"\r
-#else\r
-#define LEAD_UNDERSCORE ""\r
-#endif\r
-\r
-\r
-const struct filedescr _PyImport_DynLoadFiletab[] = {\r
-#ifdef __CYGWIN__\r
- {".dll", "rb", C_EXTENSION},\r
- {"module.dll", "rb", C_EXTENSION},\r
-#else\r
-#if defined(PYOS_OS2) && defined(PYCC_GCC)\r
- {".pyd", "rb", C_EXTENSION},\r
- {".dll", "rb", C_EXTENSION},\r
-#else\r
-#ifdef __VMS\r
- {".exe", "rb", C_EXTENSION},\r
- {".EXE", "rb", C_EXTENSION},\r
- {"module.exe", "rb", C_EXTENSION},\r
- {"MODULE.EXE", "rb", C_EXTENSION},\r
-#else\r
- {".so", "rb", C_EXTENSION},\r
- {"module.so", "rb", C_EXTENSION},\r
-#endif\r
-#endif\r
-#endif\r
- {0, 0}\r
-};\r
-\r
-static struct {\r
- dev_t dev;\r
-#ifdef __VMS\r
- ino_t ino[3];\r
-#else\r
- ino_t ino;\r
-#endif\r
- void *handle;\r
-} handles[128];\r
-static int nhandles = 0;\r
-\r
-\r
-dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,\r
- const char *pathname, FILE *fp)\r
-{\r
- dl_funcptr p;\r
- void *handle;\r
- char funcname[258];\r
- char pathbuf[260];\r
- int dlopenflags=0;\r
-\r
- if (strchr(pathname, '/') == NULL) {\r
- /* Prefix bare filename with "./" */\r
- PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname);\r
- pathname = pathbuf;\r
- }\r
-\r
- PyOS_snprintf(funcname, sizeof(funcname),\r
- LEAD_UNDERSCORE "init%.200s", shortname);\r
-\r
- if (fp != NULL) {\r
- int i;\r
- struct stat statb;\r
- fstat(fileno(fp), &statb);\r
- for (i = 0; i < nhandles; i++) {\r
- if (statb.st_dev == handles[i].dev &&\r
- statb.st_ino == handles[i].ino) {\r
- p = (dl_funcptr) dlsym(handles[i].handle,\r
- funcname);\r
- return p;\r
- }\r
- }\r
- if (nhandles < 128) {\r
- handles[nhandles].dev = statb.st_dev;\r
-#ifdef __VMS\r
- handles[nhandles].ino[0] = statb.st_ino[0];\r
- handles[nhandles].ino[1] = statb.st_ino[1];\r
- handles[nhandles].ino[2] = statb.st_ino[2];\r
-#else\r
- handles[nhandles].ino = statb.st_ino;\r
-#endif\r
- }\r
- }\r
-\r
-#if !(defined(PYOS_OS2) && defined(PYCC_GCC))\r
- dlopenflags = PyThreadState_GET()->interp->dlopenflags;\r
-#endif\r
-\r
- if (Py_VerboseFlag)\r
- PySys_WriteStderr("dlopen(\"%s\", %x);\n", pathname,\r
- dlopenflags);\r
-\r
-#ifdef __VMS\r
- /* VMS currently don't allow a pathname, use a logical name instead */\r
- /* Concatenate 'python_module_' and shortname */\r
- /* so "import vms.bar" will use the logical python_module_bar */\r
- /* As C module use only one name space this is probably not a */\r
- /* important limitation */\r
- PyOS_snprintf(pathbuf, sizeof(pathbuf), "python_module_%-.200s",\r
- shortname);\r
- pathname = pathbuf;\r
-#endif\r
-\r
- handle = dlopen(pathname, dlopenflags);\r
-\r
- if (handle == NULL) {\r
- const char *error = dlerror();\r
- if (error == NULL)\r
- error = "unknown dlopen() error";\r
- PyErr_SetString(PyExc_ImportError, error);\r
- return NULL;\r
- }\r
- if (fp != NULL && nhandles < 128)\r
- handles[nhandles++].handle = handle;\r
- p = (dl_funcptr) dlsym(handle, funcname);\r
- return p;\r
-}\r