Mercurial > cpython-lru_cache-weakref
comparison Python/dynload_shlib.c @ 61467:f197407bdba2 3.1
Recorded merge of revisions 81032 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r81032 | antoine.pitrou | 2010-05-09 17:52:27 +0200 (dim., 09 mai 2010) | 9 lines
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 16:14:21 +0000 |
| parents | 94f64f11fdd0 |
| children | 5e33b27c71a8 |
comparison
equal
deleted
inserted
replaced
| 61459:f8c19c5f5dd2 | 61467:f197407bdba2 |
|---|---|
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 | 33 |
| 34 const struct filedescr _PyImport_DynLoadFiletab[] = { | 34 const struct filedescr _PyImport_DynLoadFiletab[] = { |
| 35 #ifdef __CYGWIN__ | 35 #ifdef __CYGWIN__ |
| 36 {".dll", "rb", C_EXTENSION}, | 36 {".dll", "rb", C_EXTENSION}, |
| 37 {"module.dll", "rb", C_EXTENSION}, | 37 {"module.dll", "rb", C_EXTENSION}, |
| 38 #else | 38 #else |
| 39 #if defined(PYOS_OS2) && defined(PYCC_GCC) | 39 #if defined(PYOS_OS2) && defined(PYCC_GCC) |
| 40 {".pyd", "rb", C_EXTENSION}, | 40 {".pyd", "rb", C_EXTENSION}, |
| 41 {".dll", "rb", C_EXTENSION}, | 41 {".dll", "rb", C_EXTENSION}, |
| 42 #else | 42 #else |
| 43 #ifdef __VMS | 43 #ifdef __VMS |
| 44 {".exe", "rb", C_EXTENSION}, | 44 {".exe", "rb", C_EXTENSION}, |
| 45 {".EXE", "rb", C_EXTENSION}, | 45 {".EXE", "rb", C_EXTENSION}, |
| 46 {"module.exe", "rb", C_EXTENSION}, | 46 {"module.exe", "rb", C_EXTENSION}, |
| 47 {"MODULE.EXE", "rb", C_EXTENSION}, | 47 {"MODULE.EXE", "rb", C_EXTENSION}, |
| 48 #else | 48 #else |
| 49 {".so", "rb", C_EXTENSION}, | 49 {".so", "rb", C_EXTENSION}, |
| 50 {"module.so", "rb", C_EXTENSION}, | 50 {"module.so", "rb", C_EXTENSION}, |
| 51 #endif | 51 #endif |
| 52 #endif | 52 #endif |
| 53 #endif | 53 #endif |
| 54 {0, 0} | 54 {0, 0} |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 static struct { | 57 static struct { |
| 58 dev_t dev; | 58 dev_t dev; |
| 59 #ifdef __VMS | 59 #ifdef __VMS |
| 60 ino_t ino[3]; | 60 ino_t ino[3]; |
| 61 #else | 61 #else |
| 62 ino_t ino; | 62 ino_t ino; |
| 63 #endif | 63 #endif |
| 64 void *handle; | 64 void *handle; |
| 65 } handles[128]; | 65 } handles[128]; |
| 66 static int nhandles = 0; | 66 static int nhandles = 0; |
| 67 | 67 |
| 68 | 68 |
| 69 dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, | 69 dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, |
| 70 const char *pathname, FILE *fp) | 70 const char *pathname, FILE *fp) |
| 71 { | 71 { |
| 72 dl_funcptr p; | 72 dl_funcptr p; |
| 73 void *handle; | 73 void *handle; |
| 74 char funcname[258]; | 74 char funcname[258]; |
| 75 char pathbuf[260]; | 75 char pathbuf[260]; |
| 76 int dlopenflags=0; | 76 int dlopenflags=0; |
| 77 | 77 |
| 78 if (strchr(pathname, '/') == NULL) { | 78 if (strchr(pathname, '/') == NULL) { |
| 79 /* Prefix bare filename with "./" */ | 79 /* Prefix bare filename with "./" */ |
| 80 PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname); | 80 PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname); |
| 81 pathname = pathbuf; | 81 pathname = pathbuf; |
| 82 } | 82 } |
| 83 | 83 |
| 84 PyOS_snprintf(funcname, sizeof(funcname), | 84 PyOS_snprintf(funcname, sizeof(funcname), |
| 85 LEAD_UNDERSCORE "PyInit_%.200s", shortname); | 85 LEAD_UNDERSCORE "PyInit_%.200s", shortname); |
| 86 | 86 |
| 87 if (fp != NULL) { | 87 if (fp != NULL) { |
| 88 int i; | 88 int i; |
| 89 struct stat statb; | 89 struct stat statb; |
| 90 fstat(fileno(fp), &statb); | 90 fstat(fileno(fp), &statb); |
| 91 for (i = 0; i < nhandles; i++) { | 91 for (i = 0; i < nhandles; i++) { |
| 92 if (statb.st_dev == handles[i].dev && | 92 if (statb.st_dev == handles[i].dev && |
| 93 statb.st_ino == handles[i].ino) { | 93 statb.st_ino == handles[i].ino) { |
| 94 p = (dl_funcptr) dlsym(handles[i].handle, | 94 p = (dl_funcptr) dlsym(handles[i].handle, |
| 95 funcname); | 95 funcname); |
| 96 return p; | 96 return p; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 if (nhandles < 128) { | 99 if (nhandles < 128) { |
| 100 handles[nhandles].dev = statb.st_dev; | 100 handles[nhandles].dev = statb.st_dev; |
| 101 #ifdef __VMS | 101 #ifdef __VMS |
| 102 handles[nhandles].ino[0] = statb.st_ino[0]; | 102 handles[nhandles].ino[0] = statb.st_ino[0]; |
| 103 handles[nhandles].ino[1] = statb.st_ino[1]; | 103 handles[nhandles].ino[1] = statb.st_ino[1]; |
| 104 handles[nhandles].ino[2] = statb.st_ino[2]; | 104 handles[nhandles].ino[2] = statb.st_ino[2]; |
| 105 #else | 105 #else |
| 106 handles[nhandles].ino = statb.st_ino; | 106 handles[nhandles].ino = statb.st_ino; |
| 107 #endif | 107 #endif |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 #if !(defined(PYOS_OS2) && defined(PYCC_GCC)) | 111 #if !(defined(PYOS_OS2) && defined(PYCC_GCC)) |
| 112 dlopenflags = PyThreadState_GET()->interp->dlopenflags; | 112 dlopenflags = PyThreadState_GET()->interp->dlopenflags; |
| 113 #endif | 113 #endif |
| 114 | 114 |
| 115 if (Py_VerboseFlag) | 115 if (Py_VerboseFlag) |
| 116 PySys_WriteStderr("dlopen(\"%s\", %x);\n", pathname, | 116 PySys_WriteStderr("dlopen(\"%s\", %x);\n", pathname, |
| 117 dlopenflags); | 117 dlopenflags); |
| 118 | 118 |
| 119 #ifdef __VMS | 119 #ifdef __VMS |
| 120 /* VMS currently don't allow a pathname, use a logical name instead */ | 120 /* VMS currently don't allow a pathname, use a logical name instead */ |
| 121 /* Concatenate 'python_module_' and shortname */ | 121 /* Concatenate 'python_module_' and shortname */ |
| 122 /* so "import vms.bar" will use the logical python_module_bar */ | 122 /* so "import vms.bar" will use the logical python_module_bar */ |
| 123 /* As C module use only one name space this is probably not a */ | 123 /* As C module use only one name space this is probably not a */ |
| 124 /* important limitation */ | 124 /* important limitation */ |
| 125 PyOS_snprintf(pathbuf, sizeof(pathbuf), "python_module_%-.200s", | 125 PyOS_snprintf(pathbuf, sizeof(pathbuf), "python_module_%-.200s", |
| 126 shortname); | 126 shortname); |
| 127 pathname = pathbuf; | 127 pathname = pathbuf; |
| 128 #endif | 128 #endif |
| 129 | 129 |
| 130 handle = dlopen(pathname, dlopenflags); | 130 handle = dlopen(pathname, dlopenflags); |
| 131 | 131 |
| 132 if (handle == NULL) { | 132 if (handle == NULL) { |
| 133 const char *error = dlerror(); | 133 const char *error = dlerror(); |
| 134 if (error == NULL) | 134 if (error == NULL) |
| 135 error = "unknown dlopen() error"; | 135 error = "unknown dlopen() error"; |
| 136 PyErr_SetString(PyExc_ImportError, error); | 136 PyErr_SetString(PyExc_ImportError, error); |
| 137 return NULL; | 137 return NULL; |
| 138 } | 138 } |
| 139 if (fp != NULL && nhandles < 128) | 139 if (fp != NULL && nhandles < 128) |
| 140 handles[nhandles++].handle = handle; | 140 handles[nhandles++].handle = handle; |
| 141 p = (dl_funcptr) dlsym(handle, funcname); | 141 p = (dl_funcptr) dlsym(handle, funcname); |
| 142 return p; | 142 return p; |
| 143 } | 143 } |
