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

Delta Between Two Patch Sets: PC/getpathp.c

Issue 3871: cross and native build of python for mingw32 with distutils
Left Patch Set: Created 7 years, 3 months ago
Right Patch Set: Created 7 years, 2 months 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Objects/exceptions.c ('k') | PC/msvcrtmodule.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 * with a semicolon separated path prior to calling Py_Initialize. 87 * with a semicolon separated path prior to calling Py_Initialize.
88 */ 88 */
89 89
90 #ifndef LANDMARK 90 #ifndef LANDMARK
91 #define LANDMARK L"lib\\os.py" 91 #define LANDMARK L"lib\\os.py"
92 #endif 92 #endif
93 93
94 static wchar_t prefix[MAXPATHLEN+1]; 94 static wchar_t prefix[MAXPATHLEN+1];
95 static wchar_t progpath[MAXPATHLEN+1]; 95 static wchar_t progpath[MAXPATHLEN+1];
96 static wchar_t dllpath[MAXPATHLEN+1]; 96 static wchar_t dllpath[MAXPATHLEN+1];
97 static wchar_t mingw_dynload_path[MAXPATHLEN+1];
97 static wchar_t *module_search_path = NULL; 98 static wchar_t *module_search_path = NULL;
98 99
99 100
100 static int 101 static int
101 is_sep(wchar_t ch) /* determine if "ch" is a separator character */ 102 is_sep(wchar_t ch) /* determine if "ch" is a separator character */
102 { 103 {
103 #ifdef ALTSEP 104 #ifdef ALTSEP
104 return ch == SEP || ch == ALTSEP; 105 return ch == SEP || ch == ALTSEP;
105 #else 106 #else
106 return ch == SEP; 107 return ch == SEP;
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 } 501 }
501 } 502 }
502 503
503 /* close */ 504 /* close */
504 pclose(fp); 505 pclose(fp);
505 } 506 }
506 507
507 return 1; 508 return 1;
508 } 509 }
509 510
511 void get_mingw_path(wchar_t *destination, int size)
512 {
513 static wchar_t mingw_path[MAXPATHLEN+1]={0};
514
515 //mingw64 path is mounted under /mingw in msys
516 if (wcslen(mingw_path)==0)
517 if (!mingw_posix2win_path(L"/mingw", mingw_path, sizeof(mingw_pa th)))
518 mingw_posix2win_path(L"/", mingw_path, sizeof(mingw_path ));
519
520 if (wcslen(mingw_path)>=0) {
521 wcsncat(destination, mingw_path, size);
522 }
523 }
524
510 void get_mingw_lib_path(wchar_t *destination, int size) 525 void get_mingw_lib_path(wchar_t *destination, int size)
511 { 526 {
512 » static wchar_t mingw_base_path[MAXPATHLEN+1]={0}; 527 » wchar_t mingw_base_path[MAXPATHLEN+1]={0};
513 528
514 //mingw64 path is mounted under /mingw in msys 529 get_mingw_path(mingw_base_path, sizeof(mingw_base_path));
515 if (wcslen(mingw_base_path)==0) {
516 » » if (!mingw_posix2win_path(L"/mingw", mingw_base_path, sizeof(min gw_base_path)))
517 » » » mingw_posix2win_path(L"/", mingw_base_path, sizeof(mingw _base_path));
518 » }
519 530
520 if (wcslen(mingw_base_path)>=0) { 531 if (wcslen(mingw_base_path)>=0) {
521 » » wcsncat(destination, mingw_base_path, size); 532 » » wcsncpy(destination, mingw_base_path, size);
522 wcsncat(destination, L"/lib", size); 533 wcsncat(destination, L"/lib", size);
523 } 534 }
524 } 535 }
525 536
537 void get_mingw_os_test_path(wchar_t *destination, int size)
538 {
539 wchar_t mingw_py_path[MAXPATHLEN+1]={0};
540
541 swprintf(mingw_py_path, L"lib/python%d.%d/", PY_MAJOR_VERSION,PY_MINOR_VERSI ON);
542
543 wcsncpy(destination, mingw_py_path, size);
544 wcsncat(destination, L"os.py", size);
545 }
546
526 void get_mingw_python_path(wchar_t *destination, int size) 547 void get_mingw_python_path(wchar_t *destination, int size)
527 { 548 {
528 wchar_t mingw_lib_path[MAXPATHLEN+1]={0}; 549 wchar_t mingw_lib_path[MAXPATHLEN+1]={0};
529 wchar_t mingw_py_path[MAXPATHLEN+1]={0}; 550 wchar_t mingw_py_path[MAXPATHLEN+1]={0};
530 551
531 get_mingw_lib_path(mingw_lib_path, sizeof(mingw_lib_path)); 552 get_mingw_lib_path(mingw_lib_path, sizeof(mingw_lib_path));
532 553
533 swprintf(mingw_py_path, L"/python%d%d", PY_MAJOR_VERSION,PY_MINOR_VERSION); 554 swprintf(mingw_py_path, L"/python%d.%d", PY_MAJOR_VERSION,PY_MINOR_VERSION);
534 555
535 if (wcslen(mingw_lib_path)>=0) { 556 if (wcslen(mingw_lib_path)>=0) {
536 » » wcsncat(destination, mingw_lib_path, size); 557 » » wcsncpy(destination, mingw_lib_path, size);
537 wcsncat(destination, mingw_py_path, size); 558 wcsncat(destination, mingw_py_path, size);
538 } 559 }
539 } 560 }
540 561
541 void get_mingw_libdynload_path(wchar_t *destination, int size) 562 void get_mingw_libdynload_path(wchar_t *destination, int size)
542 { 563 {
543 wchar_t mingw_lib_path[MAXPATHLEN+1]={0}; 564 wchar_t mingw_lib_path[MAXPATHLEN+1]={0};
544 wchar_t mingw_dynload_path[MAXPATHLEN+1]={0};
545 565
546 get_mingw_python_path(mingw_lib_path, sizeof(mingw_lib_path)); 566 get_mingw_python_path(mingw_lib_path, sizeof(mingw_lib_path));
547 567
548 if (wcslen(mingw_lib_path)>=0) { 568 if (wcslen(mingw_lib_path)>=0) {
549 » » wcsncat(destination, mingw_lib_path, size); 569 » » wcsncpy(destination, mingw_lib_path, size);
550 wcsncat(destination, L"/lib-dynload", size); 570 wcsncat(destination, L"/lib-dynload", size);
551 } 571 }
552 } 572 }
553 573
554 static void 574 static void
555 calculate_path(void) 575 calculate_path(void)
556 { 576 {
557 wchar_t argv0_path[MAXPATHLEN+1]; 577 wchar_t argv0_path[MAXPATHLEN+1];
558 wchar_t *buf; 578 wchar_t *buf;
559 size_t bufsz; 579 size_t bufsz;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 671
652 skiphome = pythonhome==NULL ? 0 : 1; 672 skiphome = pythonhome==NULL ? 0 : 1;
653 673
654 # ifdef __MINGW32__ 674 # ifdef __MINGW32__
655 wchar_t mingw_lib_path[MAXPATHLEN+1]={0}; 675 wchar_t mingw_lib_path[MAXPATHLEN+1]={0};
656 get_mingw_lib_path(mingw_lib_path, sizeof(mingw_lib_path)); 676 get_mingw_lib_path(mingw_lib_path, sizeof(mingw_lib_path));
657 677
658 wchar_t mingw_python_path[MAXPATHLEN+1]={0}; 678 wchar_t mingw_python_path[MAXPATHLEN+1]={0};
659 get_mingw_python_path(mingw_python_path, sizeof(mingw_python_path)); 679 get_mingw_python_path(mingw_python_path, sizeof(mingw_python_path));
660 680
661 wchar_t mingw_dynload_path[MAXPATHLEN+1]={0};
662 get_mingw_libdynload_path(mingw_dynload_path, sizeof(mingw_dynload_path) ); 681 get_mingw_libdynload_path(mingw_dynload_path, sizeof(mingw_dynload_path) );
663 # endif 682 # endif
664 683
665 #ifdef Py_ENABLE_SHARED 684 #ifdef Py_ENABLE_SHARED
666 machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, skiphome); 685 machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, skiphome);
667 userpath = getpythonregpath(HKEY_CURRENT_USER, skiphome); 686 userpath = getpythonregpath(HKEY_CURRENT_USER, skiphome);
668 #endif 687 #endif
669 /* We only use the default relative PYTHONPATH if we havent 688 /* We only use the default relative PYTHONPATH if we havent
670 anything better to use! */ 689 anything better to use! */
671 skipdefault = envpath!=NULL || pythonhome!=NULL || \ 690 skipdefault = envpath!=NULL || pythonhome!=NULL || \
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 buf = wcschr(buf, L'\0'); 801 buf = wcschr(buf, L'\0');
783 *buf++ = DELIM; 802 *buf++ = DELIM;
784 } 803 }
785 804
786 if (wcslen(mingw_dynload_path)>0) { 805 if (wcslen(mingw_dynload_path)>0) {
787 wcscpy(buf, mingw_dynload_path); 806 wcscpy(buf, mingw_dynload_path);
788 buf = wcschr(buf, L'\0'); 807 buf = wcschr(buf, L'\0');
789 *buf++ = DELIM; 808 *buf++ = DELIM;
790 } 809 }
791 810
792 » » search_for_prefix(mingw_python_path, L"os.py"); 811 » » wchar_t mingw_path[MAXPATHLEN+1]={0};
812 » » wchar_t os_test_path[MAXPATHLEN+1]={0};
813
814 » » get_mingw_path(mingw_path, sizeof(mingw_path));
815 » » get_mingw_os_test_path(os_test_path, sizeof(os_test_path));
816
817 » » search_for_prefix(mingw_path, os_test_path);
793 } 818 }
794 #endif 819 #endif
795 if (pythonhome == NULL) { 820 if (pythonhome == NULL) {
796 if (!skipdefault) { 821 if (!skipdefault) {
797 wcscpy(buf, PYTHONPATH); 822 wcscpy(buf, PYTHONPATH);
798 buf = wcschr(buf, L'\0'); 823 buf = wcschr(buf, L'\0');
799 } 824 }
800 } 825 }
801 #else 826 #else
802 if (pythonhome == NULL) { 827 if (pythonhome == NULL) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 Py_GetPrefix(void) 928 Py_GetPrefix(void)
904 { 929 {
905 if (!module_search_path) 930 if (!module_search_path)
906 calculate_path(); 931 calculate_path();
907 return prefix; 932 return prefix;
908 } 933 }
909 934
910 wchar_t * 935 wchar_t *
911 Py_GetExecPrefix(void) 936 Py_GetExecPrefix(void)
912 { 937 {
938 if (wcslen(mingw_dynload_path)>0)
939 return mingw_dynload_path;
940
913 return Py_GetPrefix(); 941 return Py_GetPrefix();
914 } 942 }
915 943
916 wchar_t * 944 wchar_t *
917 Py_GetProgramFullPath(void) 945 Py_GetProgramFullPath(void)
918 { 946 {
919 if (!module_search_path) 947 if (!module_search_path)
920 calculate_path(); 948 calculate_path();
921 return progpath; 949 return progpath;
922 } 950 }
(...skipping 25 matching lines...) Expand all
948 hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 976 hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
949 if (hPython3 != NULL) 977 if (hPython3 != NULL)
950 return 1; 978 return 1;
951 979
952 /* Check sys.prefix\DLLs\python3.dll */ 980 /* Check sys.prefix\DLLs\python3.dll */
953 wcscpy(py3path, Py_GetPrefix()); 981 wcscpy(py3path, Py_GetPrefix());
954 wcscat(py3path, L"\\DLLs\\python3.dll"); 982 wcscat(py3path, L"\\DLLs\\python3.dll");
955 hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 983 hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
956 return hPython3 != NULL; 984 return hPython3 != NULL;
957 } 985 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+