comparison Python/importdl.c @ 61465:e38335d4df91 2.6

Recorded merge of revisions 81029 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines Untabify C files. Will watch buildbots. ........
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 09 May 2010 15:15:40 +0000
parents 19611d101d23
children
comparison
equal deleted inserted replaced
61461:b6e03ca8a206 61465:e38335d4df91
11 #ifdef HAVE_DYNAMIC_LOADING 11 #ifdef HAVE_DYNAMIC_LOADING
12 12
13 #include "importdl.h" 13 #include "importdl.h"
14 14
15 extern dl_funcptr _PyImport_GetDynLoadFunc(const char *name, 15 extern dl_funcptr _PyImport_GetDynLoadFunc(const char *name,
16 const char *shortname, 16 const char *shortname,
17 const char *pathname, FILE *fp); 17 const char *pathname, FILE *fp);
18 18
19 19
20 20
21 PyObject * 21 PyObject *
22 _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp) 22 _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp)
23 { 23 {
24 PyObject *m; 24 PyObject *m;
25 char *lastdot, *shortname, *packagecontext, *oldcontext; 25 char *lastdot, *shortname, *packagecontext, *oldcontext;
26 dl_funcptr p; 26 dl_funcptr p;
27 27
28 if ((m = _PyImport_FindExtension(name, pathname)) != NULL) { 28 if ((m = _PyImport_FindExtension(name, pathname)) != NULL) {
29 Py_INCREF(m); 29 Py_INCREF(m);
30 return m; 30 return m;
31 } 31 }
32 lastdot = strrchr(name, '.'); 32 lastdot = strrchr(name, '.');
33 if (lastdot == NULL) { 33 if (lastdot == NULL) {
34 packagecontext = NULL; 34 packagecontext = NULL;
35 shortname = name; 35 shortname = name;
36 } 36 }
37 else { 37 else {
38 packagecontext = name; 38 packagecontext = name;
39 shortname = lastdot+1; 39 shortname = lastdot+1;
40 } 40 }
41 41
42 p = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp); 42 p = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp);
43 if (PyErr_Occurred()) 43 if (PyErr_Occurred())
44 return NULL; 44 return NULL;
45 if (p == NULL) { 45 if (p == NULL) {
46 PyErr_Format(PyExc_ImportError, 46 PyErr_Format(PyExc_ImportError,
47 "dynamic module does not define init function (init%.200s)", 47 "dynamic module does not define init function (init%.200s)",
48 shortname); 48 shortname);
49 return NULL; 49 return NULL;
50 } 50 }
51 oldcontext = _Py_PackageContext; 51 oldcontext = _Py_PackageContext;
52 _Py_PackageContext = packagecontext; 52 _Py_PackageContext = packagecontext;
53 (*p)(); 53 (*p)();
54 _Py_PackageContext = oldcontext; 54 _Py_PackageContext = oldcontext;
55 if (PyErr_Occurred()) 55 if (PyErr_Occurred())
56 return NULL; 56 return NULL;
57 57
58 m = PyDict_GetItemString(PyImport_GetModuleDict(), name); 58 m = PyDict_GetItemString(PyImport_GetModuleDict(), name);
59 if (m == NULL) { 59 if (m == NULL) {
60 PyErr_SetString(PyExc_SystemError, 60 PyErr_SetString(PyExc_SystemError,
61 "dynamic module not initialized properly"); 61 "dynamic module not initialized properly");
62 return NULL; 62 return NULL;
63 } 63 }
64 /* Remember the filename as the __file__ attribute */ 64 /* Remember the filename as the __file__ attribute */
65 if (PyModule_AddStringConstant(m, "__file__", pathname) < 0) 65 if (PyModule_AddStringConstant(m, "__file__", pathname) < 0)
66 PyErr_Clear(); /* Not important enough to report */ 66 PyErr_Clear(); /* Not important enough to report */
67 67
68 if (_PyImport_FixupExtension(name, pathname) == NULL) 68 if (_PyImport_FixupExtension(name, pathname) == NULL)
69 return NULL; 69 return NULL;
70 if (Py_VerboseFlag) 70 if (Py_VerboseFlag)
71 PySys_WriteStderr( 71 PySys_WriteStderr(
72 "import %s # dynamically loaded from %s\n", 72 "import %s # dynamically loaded from %s\n",
73 name, pathname); 73 name, pathname);
74 Py_INCREF(m); 74 Py_INCREF(m);
75 return m; 75 return m;
76 } 76 }
77 77
78 #endif /* HAVE_DYNAMIC_LOADING */ 78 #endif /* HAVE_DYNAMIC_LOADING */