Changeset 388 for python/vendor/current/PC/os2vacpp
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- Location:
- python/vendor/current/PC/os2vacpp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/PC/os2vacpp/getpathp.c
r2 r388 56 56 57 57 static int 58 is_sep(char ch) 58 is_sep(char ch) /* determine if "ch" is a separator character */ 59 59 { 60 60 #ifdef ALTSEP 61 61 return ch == SEP || ch == ALTSEP; 62 62 #else 63 63 return ch == SEP; 64 64 #endif 65 65 } … … 69 69 reduce(char *dir) 70 70 { 71 72 73 74 75 } 76 71 int i = strlen(dir); 72 while (i > 0 && !is_sep(dir[i])) 73 --i; 74 dir[i] = '\0'; 75 } 76 77 77 78 78 static int 79 79 exists(char *filename) 80 80 { 81 82 81 struct stat buf; 82 return stat(filename, &buf) == 0; 83 83 } 84 84 … … 96 96 join(char *buffer, char *stuff) 97 97 { 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 98 int n, k; 99 if (is_sep(stuff[0])) 100 n = 0; 101 else { 102 n = strlen(buffer); 103 if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN) 104 buffer[n++] = SEP; 105 } 106 if (n > MAXPATHLEN) 107 Py_FatalError("buffer overflow in getpathp.c's joinpath()"); 108 k = strlen(stuff); 109 if (n + k > MAXPATHLEN) 110 k = MAXPATHLEN - n; 111 strncpy(buffer+n, stuff, k); 112 buffer[n+k] = '\0'; 113 113 } 114 114 … … 117 117 search_for_prefix(char *argv0_path, char *landmark) 118 118 { 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 119 int n; 120 121 /* Search from argv0_path, until root is found */ 122 strcpy(prefix, argv0_path); 123 do { 124 n = strlen(prefix); 125 join(prefix, landmark); 126 if (exists(prefix)) { 127 prefix[n] = '\0'; 128 return 1; 129 } 130 prefix[n] = '\0'; 131 reduce(prefix); 132 } while (prefix[0]); 133 return 0; 134 134 } 135 135 … … 148 148 getpythonregpath(HKEY keyBase, BOOL bWin32s) 149 149 { 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 RegQueryInfoKey(newKey, NULL, NULL, NULL, NULL, NULL, NULL, 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 150 HKEY newKey = 0; 151 DWORD nameSize = 0; 152 DWORD dataSize = 0; 153 DWORD numEntries = 0; 154 LONG rc; 155 char *retval = NULL; 156 char *dataBuf; 157 const char keyPrefix[] = "Software\\Python\\PythonCore\\"; 158 const char keySuffix[] = "\\PythonPath"; 159 int versionLen; 160 char *keyBuf; 161 162 // Tried to use sysget("winver") but here is too early :-( 163 versionLen = strlen(PyWin_DLLVersionString); 164 // alloca == no free required, but memory only local to fn. 165 // also no heap fragmentation! Am I being silly? 166 keyBuf = alloca(sizeof(keyPrefix)-1 + versionLen + sizeof(keySuffix)); // chars only, plus 1 NULL. 167 // lots of constants here for the compiler to optimize away :-) 168 memcpy(keyBuf, keyPrefix, sizeof(keyPrefix)-1); 169 memcpy(keyBuf+sizeof(keyPrefix)-1, PyWin_DLLVersionString, versionLen); 170 memcpy(keyBuf+sizeof(keyPrefix)-1+versionLen, keySuffix, sizeof(keySuffix)); // NULL comes with this one! 171 172 rc=RegOpenKey(keyBase, 173 keyBuf, 174 &newKey); 175 if (rc==ERROR_SUCCESS) { 176 RegQueryInfoKey(newKey, NULL, NULL, NULL, NULL, NULL, NULL, 177 &numEntries, &nameSize, &dataSize, NULL, NULL); 178 } 179 if (bWin32s && numEntries==0 && dataSize==0) { 180 /* must hardcode for Win32s */ 181 numEntries = 1; 182 dataSize = 511; 183 } 184 if (numEntries) { 185 /* Loop over all subkeys. */ 186 /* Win32s doesnt know how many subkeys, so we do 187 it twice */ 188 char keyBuf[MAX_PATH+1]; 189 int index = 0; 190 int off = 0; 191 for(index=0;;index++) { 192 long reqdSize = 0; 193 DWORD rc = RegEnumKey(newKey, 194 index, keyBuf, MAX_PATH+1); 195 if (rc) break; 196 rc = RegQueryValue(newKey, keyBuf, NULL, &reqdSize); 197 if (rc) break; 198 if (bWin32s && reqdSize==0) reqdSize = 512; 199 dataSize += reqdSize + 1; /* 1 for the ";" */ 200 } 201 dataBuf = malloc(dataSize+1); 202 if (dataBuf==NULL) 203 return NULL; /* pretty serious? Raise error? */ 204 /* Now loop over, grabbing the paths. 205 Subkeys before main library */ 206 for(index=0;;index++) { 207 int adjust; 208 long reqdSize = dataSize; 209 DWORD rc = RegEnumKey(newKey, 210 index, keyBuf,MAX_PATH+1); 211 if (rc) break; 212 rc = RegQueryValue(newKey, 213 keyBuf, dataBuf+off, &reqdSize); 214 if (rc) break; 215 if (reqdSize>1) { 216 /* If Nothing, or only '\0' copied. */ 217 adjust = strlen(dataBuf+off); 218 dataSize -= adjust; 219 off += adjust; 220 dataBuf[off++] = ';'; 221 dataBuf[off] = '\0'; 222 dataSize--; 223 } 224 } 225 /* Additionally, win32s doesnt work as expected, so 226 the specific strlen() is required for 3.1. */ 227 rc = RegQueryValue(newKey, "", dataBuf+off, &dataSize); 228 if (rc==ERROR_SUCCESS) { 229 if (strlen(dataBuf)==0) 230 free(dataBuf); 231 else 232 retval = dataBuf; /* caller will free */ 233 } 234 else 235 free(dataBuf); 236 } 237 238 if (newKey) 239 RegCloseKey(newKey); 240 return retval; 241 241 } 242 242 #endif /* MS_WIN32 */ … … 245 245 get_progpath(void) 246 246 { 247 248 249 250 251 #ifdef MS_WIN32 252 253 254 #endif 255 256 257 258 259 260 261 262 247 extern char *Py_GetProgramName(void); 248 char *path = getenv("PATH"); 249 char *prog = Py_GetProgramName(); 250 251 #ifdef MS_WIN32 252 if (GetModuleFileName(NULL, progpath, MAXPATHLEN)) 253 return; 254 #endif 255 if (prog == NULL || *prog == '\0') 256 prog = "python"; 257 258 /* If there is no slash in the argv0 path, then we have to 259 * assume python is on the user's $PATH, since there's no 260 * other way to find a directory to start the search from. If 261 * $PATH isn't exported, you lose. 262 */ 263 263 #ifdef ALTSEP 264 264 if (strchr(prog, SEP) || strchr(prog, ALTSEP)) 265 265 #else 266 267 #endif 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 266 if (strchr(prog, SEP)) 267 #endif 268 strcpy(progpath, prog); 269 else if (path) { 270 while (1) { 271 char *delim = strchr(path, DELIM); 272 273 if (delim) { 274 int len = delim - path; 275 strncpy(progpath, path, len); 276 *(progpath + len) = '\0'; 277 } 278 else 279 strcpy(progpath, path); 280 281 join(progpath, prog); 282 if (exists(progpath)) 283 break; 284 285 if (!delim) { 286 progpath[0] = '\0'; 287 break; 288 } 289 path = delim + 1; 290 } 291 } 292 else 293 progpath[0] = '\0'; 294 294 } 295 295 … … 297 297 calculate_path(void) 298 298 { 299 300 301 302 303 304 #ifdef MS_WIN32 305 306 307 308 309 310 machinepath = getpythonregpath(HKEY_CLASSES_ROOT, TRUE); 311 312 313 314 315 316 #endif 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 } 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 bufsz = 1; 358 359 360 361 362 363 364 365 366 367 368 369 370 #ifdef MS_WIN32 371 372 373 374 375 #endif 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 #ifdef MS_WIN32 398 399 400 401 402 403 404 405 406 407 408 #endif 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 299 char argv0_path[MAXPATHLEN+1]; 300 char *buf; 301 int bufsz; 302 char *pythonhome = Py_GetPythonHome(); 303 char *envpath = Py_GETENV("PYTHONPATH"); 304 #ifdef MS_WIN32 305 char *machinepath, *userpath; 306 307 /* Are we running under Windows 3.1(1) Win32s? */ 308 if (PyWin_IsWin32s()) { 309 /* Only CLASSES_ROOT is supported */ 310 machinepath = getpythonregpath(HKEY_CLASSES_ROOT, TRUE); 311 userpath = NULL; 312 } else { 313 machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, FALSE); 314 userpath = getpythonregpath(HKEY_CURRENT_USER, FALSE); 315 } 316 #endif 317 318 get_progpath(); 319 strcpy(argv0_path, progpath); 320 reduce(argv0_path); 321 if (pythonhome == NULL || *pythonhome == '\0') { 322 if (search_for_prefix(argv0_path, LANDMARK)) 323 pythonhome = prefix; 324 else 325 pythonhome = NULL; 326 } 327 else { 328 char *delim; 329 330 strcpy(prefix, pythonhome); 331 332 /* Extract Any Optional Trailing EXEC_PREFIX */ 333 /* e.g. PYTHONHOME=<prefix>:<exec_prefix> */ 334 delim = strchr(prefix, DELIM); 335 if (delim) { 336 *delim = '\0'; 337 strcpy(exec_prefix, delim+1); 338 } else 339 strcpy(exec_prefix, EXEC_PREFIX); 340 } 341 342 if (envpath && *envpath == '\0') 343 envpath = NULL; 344 345 /* We need to construct a path from the following parts: 346 (1) the PYTHONPATH environment variable, if set; 347 (2) for Win32, the machinepath and userpath, if set; 348 (3) the PYTHONPATH config macro, with the leading "." 349 of each component replaced with pythonhome, if set; 350 (4) the directory containing the executable (argv0_path). 351 The length calculation calculates #3 first. 352 */ 353 354 /* Calculate size of return buffer */ 355 if (pythonhome != NULL) { 356 char *p; 357 bufsz = 1; 358 for (p = PYTHONPATH; *p; p++) { 359 if (*p == DELIM) 360 bufsz++; /* number of DELIM plus one */ 361 } 362 bufsz *= strlen(pythonhome); 363 } 364 else 365 bufsz = 0; 366 bufsz += strlen(PYTHONPATH) + 1; 367 if (envpath != NULL) 368 bufsz += strlen(envpath) + 1; 369 bufsz += strlen(argv0_path) + 1; 370 #ifdef MS_WIN32 371 if (machinepath) 372 bufsz += strlen(machinepath) + 1; 373 if (userpath) 374 bufsz += strlen(userpath) + 1; 375 #endif 376 377 module_search_path = buf = malloc(bufsz); 378 if (buf == NULL) { 379 /* We can't exit, so print a warning and limp along */ 380 fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n"); 381 if (envpath) { 382 fprintf(stderr, "Using default static $PYTHONPATH.\n"); 383 module_search_path = envpath; 384 } 385 else { 386 fprintf(stderr, "Using environment $PYTHONPATH.\n"); 387 module_search_path = PYTHONPATH; 388 } 389 return; 390 } 391 392 if (envpath) { 393 strcpy(buf, envpath); 394 buf = strchr(buf, '\0'); 395 *buf++ = DELIM; 396 } 397 #ifdef MS_WIN32 398 if (machinepath) { 399 strcpy(buf, machinepath); 400 buf = strchr(buf, '\0'); 401 *buf++ = DELIM; 402 } 403 if (userpath) { 404 strcpy(buf, userpath); 405 buf = strchr(buf, '\0'); 406 *buf++ = DELIM; 407 } 408 #endif 409 if (pythonhome == NULL) { 410 strcpy(buf, PYTHONPATH); 411 buf = strchr(buf, '\0'); 412 } 413 else { 414 char *p = PYTHONPATH; 415 char *q; 416 int n; 417 for (;;) { 418 q = strchr(p, DELIM); 419 if (q == NULL) 420 n = strlen(p); 421 else 422 n = q-p; 423 if (p[0] == '.' && is_sep(p[1])) { 424 strcpy(buf, pythonhome); 425 buf = strchr(buf, '\0'); 426 p++; 427 n--; 428 } 429 strncpy(buf, p, n); 430 buf += n; 431 if (q == NULL) 432 break; 433 *buf++ = DELIM; 434 p = q+1; 435 } 436 } 437 if (argv0_path) { 438 *buf++ = DELIM; 439 strcpy(buf, argv0_path); 440 buf = strchr(buf, '\0'); 441 } 442 *buf = '\0'; 443 443 } 444 444 … … 449 449 Py_GetPath(void) 450 450 { 451 452 453 454 451 if (!module_search_path) 452 calculate_path(); 453 454 return module_search_path; 455 455 } 456 456 … … 458 458 Py_GetPrefix(void) 459 459 { 460 461 462 463 460 if (!module_search_path) 461 calculate_path(); 462 463 return prefix; 464 464 } 465 465 … … 467 467 Py_GetExecPrefix(void) 468 468 { 469 470 471 472 469 if (!module_search_path) 470 calculate_path(); 471 472 return exec_prefix; 473 473 } 474 474 … … 476 476 Py_GetProgramFullPath(void) 477 477 { 478 479 480 481 482 } 478 if (!module_search_path) 479 calculate_path(); 480 481 return progpath; 482 } -
python/vendor/current/PC/os2vacpp/makefile
r2 r388 204 204 $(PATHOBJ)\StructModule.obj \ 205 205 $(PATHOBJ)\TimeModule.obj \ 206 $(PATHOBJ)\ThreadModule.obj \ 207 $(PATHOBJ)\YUVConvert.obj 206 $(PATHOBJ)\ThreadModule.obj 208 207 209 208 # Standalone Parser Generator Program (Shares Some of Python's Modules) … … 1114 1113 $(PY_INCLUDE)\python.h $(PY_INCLUDE)\pythonrun.h $(PY_INCLUDE)\rangeobject.h \ 1115 1114 $(PY_INCLUDE)\sliceobject.h $(PY_INCLUDE)\stringobject.h \ 1116 $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h \ 1117 $(PY_MODULES)\yuv.h 1115 $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h 1118 1116 1119 1117 syslogmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \ … … 1198 1196 $(PY_INCLUDE)\sliceobject.h $(PY_INCLUDE)\stringobject.h \ 1199 1197 $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h 1200 1201 yuvconvert.obj: $(PY_MODULES)\yuv.h1202 1198 1203 1199 zlibmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h $(PY_INCLUDE)\classobject.h \ … … 1697 1693 $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \ 1698 1694 $(PY_INCLUDE)\tupleobject.h 1699 1700 getmtime.obj: pyconfig.h1701 1695 1702 1696 getplatform.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \ -
python/vendor/current/PC/os2vacpp/makefile.omk
r2 r388 165 165 StructModule.obj \ 166 166 TimeModule.obj \ 167 ThreadModule.obj \ 168 YUVConvert.obj 167 ThreadModule.obj 169 168 170 169 # Omitted Modules (and Description/Reason): … … 804 803 moduleobject.h mymalloc.h myproto.h object.h objimpl.h pydebug.h \ 805 804 pyerrors.h pyfpe.h pystate.h python.h pythonrun.h rangeobject.h \ 806 sliceobject.h stringobject.h sysmodule.h traceback.h tupleobject.h \ 807 yuv.h 805 sliceobject.h stringobject.h sysmodule.h traceback.h tupleobject.h 808 806 809 807 syslogmodule.obj: abstract.h ceval.h classobject.h cobject.h \ … … 854 852 pythonrun.h rangeobject.h sliceobject.h stringobject.h sysmodule.h \ 855 853 traceback.h tupleobject.h 856 857 yuvconvert.obj: yuv.h858 854 859 855 zlibmodule.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \ … … 1160 1156 stringobject.h sysmodule.h traceback.h tupleobject.h 1161 1157 1162 getmtime.obj: pyconfig.h1163 1164 1158 getplatform.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \ 1165 1159 pyconfig.h dictobject.h fileobject.h floatobject.h funcobject.h \ -
python/vendor/current/PC/os2vacpp/python.def
r2 r388 7 7 ; Data 8 8 PyCFunction_Type 9 PyCapsule_Type 9 10 PyCObject_Type 10 11 PyClass_Type … … 76 77 _Py_ZeroStruct 77 78 _Py_abstract_hack 79 _Py_capsule_hack 78 80 _Py_cobject_hack 79 81 _Py_re_syntax … … 90 92 PyCFunction_GetSelf 91 93 PyCFunction_New 94 PyCapsule_GetContext 95 PyCapsule_GetDestructor 96 PyCapsule_GetName 97 PyCapsule_GetPointer 98 PyCapsule_Import 99 PyCapsule_IsValid 100 PyCapsule_New 101 PyCapsule_SetContext 102 PyCapsule_SetDestructor 103 PyCapsule_SetName 104 PyCapsule_SetPointer 92 105 PyCObject_AsVoidPtr 93 106 PyCObject_FromVoidPtrAndDesc … … 285 298 PyOS_AfterFork 286 299 PyOS_FiniInterrupts 287 PyOS_GetLastModificationTime288 300 PyOS_InitInterrupts 289 301 PyOS_InterruptOccurred … … 370 382 PyThreadState_New 371 383 PyThreadState_Swap 372 PyThread__exit_thread373 384 PyThread_acquire_lock 374 385 PyThread_allocate_lock
Note:
See TracChangeset
for help on using the changeset viewer.