2 /* Support for dynamic loading of extension modules */
6 /* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
7 supported on this platform. configure will then compile and link in one
8 of the dynload_*.c files, as appropriate. We will call a function in
9 those modules to get a function pointer to the module's init function.
11 #ifdef HAVE_DYNAMIC_LOADING
15 extern dl_funcptr
_PyImport_GetDynLoadFunc(const char *name
,
16 const char *shortname
,
17 const char *pathname
, FILE *fp
);
22 _PyImport_LoadDynamicModule(char *name
, char *pathname
, FILE *fp
)
25 char *lastdot
, *shortname
, *packagecontext
, *oldcontext
;
28 if ((m
= _PyImport_FindExtension(name
, pathname
)) != NULL
) {
32 lastdot
= strrchr(name
, '.');
33 if (lastdot
== NULL
) {
34 packagecontext
= NULL
;
38 packagecontext
= name
;
39 shortname
= lastdot
+1;
42 p
= _PyImport_GetDynLoadFunc(name
, shortname
, pathname
, fp
);
46 PyErr_Format(PyExc_ImportError
,
47 "dynamic module does not define init function (init%.200s)",
51 oldcontext
= _Py_PackageContext
;
52 _Py_PackageContext
= packagecontext
;
54 _Py_PackageContext
= oldcontext
;
58 m
= PyDict_GetItemString(PyImport_GetModuleDict(), name
);
60 PyErr_SetString(PyExc_SystemError
,
61 "dynamic module not initialized properly");
64 /* Remember the filename as the __file__ attribute */
65 if (PyModule_AddStringConstant(m
, "__file__", pathname
) < 0)
66 PyErr_Clear(); /* Not important enough to report */
68 if (_PyImport_FixupExtension(name
, pathname
) == NULL
)
72 "import %s # dynamically loaded from %s\n",
78 #endif /* HAVE_DYNAMIC_LOADING */