+++ /dev/null
-\r
-/* Support for dynamic loading of extension modules */\r
-\r
-#include "Python.h"\r
-\r
-/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is\r
- supported on this platform. configure will then compile and link in one\r
- of the dynload_*.c files, as appropriate. We will call a function in\r
- those modules to get a function pointer to the module's init function.\r
-*/\r
-#ifdef HAVE_DYNAMIC_LOADING\r
-\r
-#include "importdl.h"\r
-\r
-extern dl_funcptr _PyImport_GetDynLoadFunc(const char *name,\r
- const char *shortname,\r
- const char *pathname, FILE *fp);\r
-\r
-\r
-\r
-PyObject *\r
-_PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp)\r
-{\r
- PyObject *m;\r
- char *lastdot, *shortname, *packagecontext, *oldcontext;\r
- dl_funcptr p;\r
-\r
- if ((m = _PyImport_FindExtension(name, pathname)) != NULL) {\r
- Py_INCREF(m);\r
- return m;\r
- }\r
- lastdot = strrchr(name, '.');\r
- if (lastdot == NULL) {\r
- packagecontext = NULL;\r
- shortname = name;\r
- }\r
- else {\r
- packagecontext = name;\r
- shortname = lastdot+1;\r
- }\r
-\r
- p = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp);\r
- if (PyErr_Occurred())\r
- return NULL;\r
- if (p == NULL) {\r
- PyErr_Format(PyExc_ImportError,\r
- "dynamic module does not define init function (init%.200s)",\r
- shortname);\r
- return NULL;\r
- }\r
- oldcontext = _Py_PackageContext;\r
- _Py_PackageContext = packagecontext;\r
- (*p)();\r
- _Py_PackageContext = oldcontext;\r
- if (PyErr_Occurred())\r
- return NULL;\r
-\r
- m = PyDict_GetItemString(PyImport_GetModuleDict(), name);\r
- if (m == NULL) {\r
- PyErr_SetString(PyExc_SystemError,\r
- "dynamic module not initialized properly");\r
- return NULL;\r
- }\r
- /* Remember the filename as the __file__ attribute */\r
- if (PyModule_AddStringConstant(m, "__file__", pathname) < 0)\r
- PyErr_Clear(); /* Not important enough to report */\r
-\r
- if (_PyImport_FixupExtension(name, pathname) == NULL)\r
- return NULL;\r
- if (Py_VerboseFlag)\r
- PySys_WriteStderr(\r
- "import %s # dynamically loaded from %s\n",\r
- name, pathname);\r
- Py_INCREF(m);\r
- return m;\r
-}\r
-\r
-#endif /* HAVE_DYNAMIC_LOADING */\r