13
13
#include "importdl.h"
15
15
extern dl_funcptr _PyImport_GetDynLoadFunc(const char *name,
16
const char *shortname,
17
const char *pathname, FILE *fp);
16
const char *shortname,
17
const char *pathname, FILE *fp);
22
22
_PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp)
26
char *lastdot, *shortname, *packagecontext, *oldcontext;
29
struct PyModuleDef *def;
31
if ((m = _PyImport_FindExtension(name, pathname)) != NULL) {
35
lastdot = strrchr(name, '.');
36
if (lastdot == NULL) {
37
packagecontext = NULL;
41
packagecontext = name;
42
shortname = lastdot+1;
45
p0 = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp);
46
p = (PyObject*(*)(void))p0;
50
PyErr_Format(PyExc_ImportError,
51
"dynamic module does not define init function (PyInit_%.200s)",
55
oldcontext = _Py_PackageContext;
56
_Py_PackageContext = packagecontext;
58
_Py_PackageContext = oldcontext;
62
if (PyErr_Occurred()) {
64
PyErr_Format(PyExc_SystemError,
65
"initialization of %s raised unreported exception",
70
/* Remember pointer to module init function. */
71
def = PyModule_GetDef(m);
72
def->m_base.m_init = p;
74
/* Remember the filename as the __file__ attribute */
75
path = PyUnicode_DecodeFSDefault(pathname);
76
if (PyModule_AddObject(m, "__file__", path) < 0)
77
PyErr_Clear(); /* Not important enough to report */
79
if (_PyImport_FixupExtension(m, name, pathname) < 0)
83
"import %s # dynamically loaded from %s\n",
26
char *lastdot, *shortname, *packagecontext, *oldcontext;
29
struct PyModuleDef *def;
31
if ((m = _PyImport_FindExtension(name, pathname)) != NULL) {
35
lastdot = strrchr(name, '.');
36
if (lastdot == NULL) {
37
packagecontext = NULL;
41
packagecontext = name;
42
shortname = lastdot+1;
45
p0 = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp);
46
p = (PyObject*(*)(void))p0;
50
PyErr_Format(PyExc_ImportError,
51
"dynamic module does not define init function (PyInit_%.200s)",
55
oldcontext = _Py_PackageContext;
56
_Py_PackageContext = packagecontext;
58
_Py_PackageContext = oldcontext;
62
if (PyErr_Occurred()) {
64
PyErr_Format(PyExc_SystemError,
65
"initialization of %s raised unreported exception",
70
/* Remember pointer to module init function. */
71
def = PyModule_GetDef(m);
72
def->m_base.m_init = p;
74
/* Remember the filename as the __file__ attribute */
75
path = PyUnicode_DecodeFSDefault(pathname);
76
if (PyModule_AddObject(m, "__file__", path) < 0)
77
PyErr_Clear(); /* Not important enough to report */
79
if (_PyImport_FixupExtension(m, name, pathname) < 0)
83
"import %s # dynamically loaded from %s\n",
88
88
#endif /* HAVE_DYNAMIC_LOADING */