diff options
Diffstat (limited to 'Python/importdl.c')
| -rw-r--r-- | Python/importdl.c | 64 |
1 files changed, 20 insertions, 44 deletions
diff --git a/Python/importdl.c b/Python/importdl.c index 9caed45..14c9be8 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -22,21 +22,12 @@ PyObject * _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) { PyObject *m; - PyObject *path; char *lastdot, *shortname, *packagecontext, *oldcontext; - dl_funcptr p0; - PyObject* (*p)(void); - struct PyModuleDef *def; - PyObject *result; + dl_funcptr p; - path = PyUnicode_DecodeFSDefault(pathname); - if (path == NULL) - return NULL; - - if ((m = _PyImport_FindExtensionUnicode(name, path)) != NULL) { + if ((m = _PyImport_FindExtension(name, pathname)) != NULL) { Py_INCREF(m); - result = m; - goto finally; + return m; } lastdot = strrchr(name, '.'); if (lastdot == NULL) { @@ -48,55 +39,40 @@ _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) shortname = lastdot+1; } - p0 = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp); - p = (PyObject*(*)(void))p0; + p = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp); if (PyErr_Occurred()) - goto error; + return NULL; if (p == NULL) { PyErr_Format(PyExc_ImportError, - "dynamic module does not define init function (PyInit_%.200s)", + "dynamic module does not define init function (init%.200s)", shortname); - goto error; + return NULL; } oldcontext = _Py_PackageContext; _Py_PackageContext = packagecontext; - m = (*p)(); + (*p)(); _Py_PackageContext = oldcontext; - if (m == NULL) - goto error; + if (PyErr_Occurred()) + return NULL; - if (PyErr_Occurred()) { - Py_DECREF(m); - PyErr_Format(PyExc_SystemError, - "initialization of %s raised unreported exception", - shortname); - goto error; + m = PyDict_GetItemString(PyImport_GetModuleDict(), name); + if (m == NULL) { + PyErr_SetString(PyExc_SystemError, + "dynamic module not initialized properly"); + return NULL; } - - /* Remember pointer to module init function. */ - def = PyModule_GetDef(m); - def->m_base.m_init = p; - /* Remember the filename as the __file__ attribute */ - if (PyModule_AddObject(m, "__file__", path) < 0) + if (PyModule_AddStringConstant(m, "__file__", pathname) < 0) PyErr_Clear(); /* Not important enough to report */ - else - Py_INCREF(path); - if (_PyImport_FixupExtensionUnicode(m, name, path) < 0) - goto error; + if (_PyImport_FixupExtension(name, pathname) == NULL) + return NULL; if (Py_VerboseFlag) PySys_WriteStderr( "import %s # dynamically loaded from %s\n", name, pathname); - result = m; - goto finally; - -error: - result = NULL; -finally: - Py_DECREF(path); - return result; + Py_INCREF(m); + return m; } #endif /* HAVE_DYNAMIC_LOADING */ |
