1 /***********************************************************
2 Copyright (c) 2000, BeOpen.com.
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
7 See the file "Misc/COPYRIGHT" for information on usage and
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9 ******************************************************************/
11 /* Support for dynamic loading of extension modules */
15 /* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
16 supported on this platform. configure will then compile and link in one
17 of the dynload_*.c files, as appropriate. We will call a function in
18 those modules to get a function pointer to the module's init function.
20 #ifdef HAVE_DYNAMIC_LOADING
24 extern dl_funcptr
_PyImport_GetDynLoadFunc(const char *name
,
25 const char *shortname
,
26 const char *pathname
, FILE *fp
);
31 _PyImport_LoadDynamicModule(char *name
, char *pathname
, FILE *fp
)
34 char *lastdot
, *shortname
, *packagecontext
;
37 if ((m
= _PyImport_FindExtension(name
, pathname
)) != NULL
) {
41 lastdot
= strrchr(name
, '.');
42 if (lastdot
== NULL
) {
43 packagecontext
= NULL
;
47 packagecontext
= name
;
48 shortname
= lastdot
+1;
51 p
= _PyImport_GetDynLoadFunc(name
, shortname
, pathname
, fp
);
55 PyErr_Format(PyExc_ImportError
,
56 "dynamic module does not define init function (init%.200s)",
60 _Py_PackageContext
= packagecontext
;
62 _Py_PackageContext
= NULL
;
65 if (_PyImport_FixupExtension(name
, pathname
) == NULL
)
68 m
= PyDict_GetItemString(PyImport_GetModuleDict(), name
);
70 PyErr_SetString(PyExc_SystemError
,
71 "dynamic module not initialized properly");
74 /* Remember the filename as the __file__ attribute */
75 d
= PyModule_GetDict(m
);
76 s
= PyString_FromString(pathname
);
77 if (s
== NULL
|| PyDict_SetItemString(d
, "__file__", s
) != 0)
78 PyErr_Clear(); /* Not important enough to report */
82 "import %s # dynamically loaded from %s\n",
88 #endif /* HAVE_DYNAMIC_LOADING */