Changeset 391 for python/trunk/Python/dynload_shlib.c
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Python/dynload_shlib.c
r10 r391 28 28 #endif 29 29 30 #if ((defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__)) \ 31 || (defined(__OS2__) && defined(__KLIBC__)) 30 #if ((defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__)) || defined(PYOS_OS2) 32 31 #define LEAD_UNDERSCORE "_" 33 32 #else … … 38 37 const struct filedescr _PyImport_DynLoadFiletab[] = { 39 38 #ifdef __CYGWIN__ 40 41 39 {".dll", "rb", C_EXTENSION}, 40 {"module.dll", "rb", C_EXTENSION}, 42 41 #else 43 #if (defined(PYOS_OS2) && defined(PYCC_GCC)) || (defined(__OS2__) && defined(__KLIBC__))44 45 42 #if defined(PYOS_OS2) && defined(PYCC_GCC) 43 {".pyd", "rb", C_EXTENSION}, 44 {".dll", "rb", C_EXTENSION}, 46 45 #else 47 46 #ifdef __VMS 48 49 50 51 47 {".exe", "rb", C_EXTENSION}, 48 {".EXE", "rb", C_EXTENSION}, 49 {"module.exe", "rb", C_EXTENSION}, 50 {"MODULE.EXE", "rb", C_EXTENSION}, 52 51 #else 53 54 52 {".so", "rb", C_EXTENSION}, 53 {"module.so", "rb", C_EXTENSION}, 55 54 #endif 56 55 #endif 57 56 #endif 58 57 {0, 0} 59 58 }; 60 59 61 60 static struct { 62 61 dev_t dev; 63 62 #ifdef __VMS 64 63 ino_t ino[3]; 65 64 #else 66 65 ino_t ino; 67 66 #endif 68 67 void *handle; 69 68 } handles[128]; 70 69 static int nhandles = 0; … … 72 71 73 72 dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, 74 73 const char *pathname, FILE *fp) 75 74 { 76 77 78 79 80 75 dl_funcptr p; 76 void *handle; 77 char funcname[258]; 78 char pathbuf[260]; 79 int dlopenflags=0; 81 80 82 83 84 85 86 81 if (strchr(pathname, '/') == NULL) { 82 /* Prefix bare filename with "./" */ 83 PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname); 84 pathname = pathbuf; 85 } 87 86 88 PyOS_snprintf(funcname, sizeof(funcname), 89 87 PyOS_snprintf(funcname, sizeof(funcname), 88 LEAD_UNDERSCORE "init%.200s", shortname); 90 89 91 92 93 94 95 96 97 98 99 100 101 102 103 104 90 if (fp != NULL) { 91 int i; 92 struct stat statb; 93 fstat(fileno(fp), &statb); 94 for (i = 0; i < nhandles; i++) { 95 if (statb.st_dev == handles[i].dev && 96 statb.st_ino == handles[i].ino) { 97 p = (dl_funcptr) dlsym(handles[i].handle, 98 funcname); 99 return p; 100 } 101 } 102 if (nhandles < 128) { 103 handles[nhandles].dev = statb.st_dev; 105 104 #ifdef __VMS 106 107 108 105 handles[nhandles].ino[0] = statb.st_ino[0]; 106 handles[nhandles].ino[1] = statb.st_ino[1]; 107 handles[nhandles].ino[2] = statb.st_ino[2]; 109 108 #else 110 109 handles[nhandles].ino = statb.st_ino; 111 110 #endif 112 113 111 } 112 } 114 113 115 114 #if !(defined(PYOS_OS2) && defined(PYCC_GCC)) 116 115 dlopenflags = PyThreadState_GET()->interp->dlopenflags; 117 116 #endif 118 117 119 120 PySys_WriteStderr("dlopen(\"%s\", %x);\n", pathname, 121 118 if (Py_VerboseFlag) 119 PySys_WriteStderr("dlopen(\"%s\", %x);\n", pathname, 120 dlopenflags); 122 121 123 122 #ifdef __VMS 124 125 126 127 128 129 PyOS_snprintf(pathbuf, sizeof(pathbuf), "python_module_%-.200s", 130 131 123 /* VMS currently don't allow a pathname, use a logical name instead */ 124 /* Concatenate 'python_module_' and shortname */ 125 /* so "import vms.bar" will use the logical python_module_bar */ 126 /* As C module use only one name space this is probably not a */ 127 /* important limitation */ 128 PyOS_snprintf(pathbuf, sizeof(pathbuf), "python_module_%-.200s", 129 shortname); 130 pathname = pathbuf; 132 131 #endif 133 132 134 133 #if (defined(PYOS_OS2) && defined(PYCC_GCC)) 135 136 137 134 // resolve unixroot 135 if (_realrealpath( pathname, pathbuf, sizeof(pathbuf))!=0) 136 pathname = pathbuf; 138 137 #endif 139 138 140 139 handle = dlopen(pathname, dlopenflags); 141 140 142 143 144 145 146 147 148 149 150 151 152 141 if (handle == NULL) { 142 const char *error = dlerror(); 143 if (error == NULL) 144 error = "unknown dlopen() error"; 145 PyErr_SetString(PyExc_ImportError, error); 146 return NULL; 147 } 148 if (fp != NULL && nhandles < 128) 149 handles[nhandles++].handle = handle; 150 p = (dl_funcptr) dlsym(handle, funcname); 151 return p; 153 152 }
Note:
See TracChangeset
for help on using the changeset viewer.