Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(363)

Delta Between Two Patch Sets: PC/getpathp.c

Issue 14843: support define_macros / undef_macros in setup.cfg
Left Patch Set: Created 12 months ago
Right Patch Set: Created 11 months, 1 week ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « PC/VS9.0/pyproject.vsprops ('k') | PCbuild/_bz2.vcxproj » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 1
2 /* Return the initial module search path. */ 2 /* Return the initial module search path. */
3 /* Used by DOS, OS/2, Windows 3.1, Windows 95/98, Windows NT. */ 3 /* Used by DOS, OS/2, Windows 3.1, Windows 95/98, Windows NT. */
4 4
5 /* ---------------------------------------------------------------- 5 /* ----------------------------------------------------------------
6 PATH RULES FOR WINDOWS: 6 PATH RULES FOR WINDOWS:
7 This describes how sys.path is formed on Windows. It describes the 7 This describes how sys.path is formed on Windows. It describes the
8 functionality, not the implementation (ie, the order in which these 8 functionality, not the implementation (ie, the order in which these
9 are actually fetched is different) 9 are actually fetched is different)
10 10
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 progpath[0] = '\0'; 416 progpath[0] = '\0';
417 break; 417 break;
418 } 418 }
419 path = delim + 1; 419 path = delim + 1;
420 } 420 }
421 } 421 }
422 else 422 else
423 progpath[0] = '\0'; 423 progpath[0] = '\0';
424 } 424 }
425 425
426 static int
427 find_env_config_value(FILE * env_file, const wchar_t * key, wchar_t * value)
428 {
429 int result = 0; /* meaning not found */
430 char buffer[MAXPATHLEN*2+1]; /* allow extra for key, '=', etc. */
431
432 fseek(env_file, 0, SEEK_SET);
433 while (!feof(env_file)) {
434 char * p = fgets(buffer, MAXPATHLEN*2, env_file);
435 wchar_t tmpbuffer[MAXPATHLEN*2+1];
436 PyObject * decoded;
437 int n;
438
439 if (p == NULL)
440 break;
441 n = strlen(p);
442 if (p[n - 1] != '\n') {
443 /* line has overflowed - bail */
444 break;
445 }
446 if (p[0] == '#') /* Comment - skip */
447 continue;
448 decoded = PyUnicode_DecodeUTF8(buffer, n, "surrogateescape");
449 if (decoded != NULL) {
450 Py_ssize_t k;
451 k = PyUnicode_AsWideChar(decoded,
452 tmpbuffer, MAXPATHLEN * 2);
453 Py_DECREF(decoded);
454 if (k >= 0) {
455 wchar_t * tok = wcstok(tmpbuffer, L" \t\r\n");
456 if ((tok != NULL) && !wcscmp(tok, key)) {
457 tok = wcstok(NULL, L" \t");
458 if ((tok != NULL) && !wcscmp(tok, L"=")) {
459 tok = wcstok(NULL, L"\r\n");
460 if (tok != NULL) {
461 wcsncpy(value, tok, MAXPATHLEN);
462 result = 1;
463 break;
464 }
465 }
466 }
467 }
468 }
469 }
470 return result;
471 }
472
473 static void 426 static void
474 calculate_path(void) 427 calculate_path(void)
475 { 428 {
476 wchar_t argv0_path[MAXPATHLEN+1]; 429 wchar_t argv0_path[MAXPATHLEN+1];
477 wchar_t *buf; 430 wchar_t *buf;
478 size_t bufsz; 431 size_t bufsz;
479 wchar_t *pythonhome = Py_GetPythonHome(); 432 wchar_t *pythonhome = Py_GetPythonHome();
480 wchar_t *envpath = NULL; 433 wchar_t *envpath = NULL;
481 434
482 #ifdef MS_WINDOWS 435 #ifdef MS_WINDOWS
(...skipping 14 matching lines...) Expand all
497 envpath = wenvpath; 450 envpath = wenvpath;
498 if (r == (size_t)-1 || r >= MAXPATHLEN) 451 if (r == (size_t)-1 || r >= MAXPATHLEN)
499 envpath = NULL; 452 envpath = NULL;
500 } 453 }
501 #endif 454 #endif
502 455
503 get_progpath(); 456 get_progpath();
504 /* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */ 457 /* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */
505 wcscpy(argv0_path, progpath); 458 wcscpy(argv0_path, progpath);
506 reduce(argv0_path); 459 reduce(argv0_path);
507
508 /* Search for an environment configuration file, first in the
509 executable's directory and then in the parent directory.
510 If found, open it for use when searching for prefixes.
511 */
512
513 {
514 wchar_t tmpbuffer[MAXPATHLEN+1];
515 wchar_t *env_cfg = L"pyvenv.cfg";
516 FILE * env_file = NULL;
517
518 wcscpy(tmpbuffer, argv0_path);
519 join(tmpbuffer, env_cfg);
520 env_file = _Py_wfopen(tmpbuffer, L"r");
521 if (env_file == NULL) {
522 errno = 0;
523 reduce(tmpbuffer);
524 reduce(tmpbuffer);
525 join(tmpbuffer, env_cfg);
526 env_file = _Py_wfopen(tmpbuffer, L"r");
527 if (env_file == NULL) {
528 errno = 0;
529 }
530 }
531 if (env_file != NULL) {
532 /* Look for a 'home' variable and set argv0_path to it, if found */
533 if (find_env_config_value(env_file, L"home", tmpbuffer)) {
534 wcscpy(argv0_path, tmpbuffer);
535 }
536 fclose(env_file);
537 env_file = NULL;
538 }
539 }
540
541 if (pythonhome == NULL || *pythonhome == '\0') { 460 if (pythonhome == NULL || *pythonhome == '\0') {
542 if (search_for_prefix(argv0_path, LANDMARK)) 461 if (search_for_prefix(argv0_path, LANDMARK))
543 pythonhome = prefix; 462 pythonhome = prefix;
544 else 463 else
545 pythonhome = NULL; 464 pythonhome = NULL;
546 } 465 }
547 else 466 else
548 wcsncpy(prefix, pythonhome, MAXPATHLEN); 467 wcsncpy(prefix, pythonhome, MAXPATHLEN);
549 468
550 if (envpath && *envpath == '\0') 469 if (envpath && *envpath == '\0')
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 735 hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
817 if (hPython3 != NULL) 736 if (hPython3 != NULL)
818 return 1; 737 return 1;
819 738
820 /* Check sys.prefix\DLLs\python3.dll */ 739 /* Check sys.prefix\DLLs\python3.dll */
821 wcscpy(py3path, Py_GetPrefix()); 740 wcscpy(py3path, Py_GetPrefix());
822 wcscat(py3path, L"\\DLLs\\python3.dll"); 741 wcscat(py3path, L"\\DLLs\\python3.dll");
823 hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 742 hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
824 return hPython3 != NULL; 743 return hPython3 != NULL;
825 } 744 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7