Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 847a996

Browse files
committed
Patch from M.-A. Lemburg:
Python on UNIX now trusts PYTHONHOME unconditionally Modules/getpath.c: Landmark changed to os.py. Setting PYTHONHOME now unconditionally sets sys.prefix (and sys.exec_prefix). No further checks are done whether the standard lib can be found in that location or not. This is in sync with the PC subdir getpath implementations. PC/getpathp.c: Landmark changed to os.py. PC/os2vacpp/getpathp.c: Landmark changed to os.py. Note: BAW's checkin on exceptions.c eliminates earlier concerns about a bogus PYTHONHOME value leading to a core dump. Instead it causes a useless sys.path and prevents imports.
1 parent b80a777 commit 847a996

3 files changed

Lines changed: 27 additions & 29 deletions

File tree

Modules/getpath.c

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ PERFORMANCE OF THIS SOFTWARE.
8787
* Modules/Setup. If the landmark is found, we're done.
8888
*
8989
* For the remaining steps, the prefix landmark will always be
90-
* lib/python$VERSION/string.py and the exec_prefix will always be
90+
* lib/python$VERSION/os.py and the exec_prefix will always be
9191
* lib/python$VERSION/lib-dynload, where $VERSION is Python's version
9292
* number as supplied by the Makefile. Note that this means that no more
9393
* build directory checking is performed; if the first step did not find
@@ -150,7 +150,7 @@ PERFORMANCE OF THIS SOFTWARE.
150150
#endif
151151

152152
#ifndef LANDMARK
153-
#define LANDMARK "string.py"
153+
#define LANDMARK "os.py"
154154
#endif
155155

156156
static char prefix[MAXPATHLEN+1];
@@ -265,6 +265,18 @@ search_for_prefix(argv0_path, home)
265265
int n;
266266
char *vpath;
267267

268+
/* If PYTHONHOME is set, we believe it unconditionally */
269+
if (home) {
270+
char *delim;
271+
strcpy(prefix, home);
272+
delim = strchr(prefix, DELIM);
273+
if (delim)
274+
*delim = '\0';
275+
joinpath(prefix, lib_python);
276+
joinpath(prefix, LANDMARK);
277+
return 1;
278+
}
279+
268280
/* Check to see if argv[0] is in the build directory */
269281
strcpy(prefix, argv0_path);
270282
joinpath(prefix, "Modules/Setup");
@@ -290,19 +302,6 @@ search_for_prefix(argv0_path, home)
290302
return -1;
291303
}
292304

293-
if (home) {
294-
/* Check $PYTHONHOME */
295-
char *delim;
296-
strcpy(prefix, home);
297-
delim = strchr(prefix, DELIM);
298-
if (delim)
299-
*delim = '\0';
300-
joinpath(prefix, lib_python);
301-
joinpath(prefix, LANDMARK);
302-
if (ismodule(prefix))
303-
return 1;
304-
}
305-
306305
/* Search from argv0_path, until root is found */
307306
strcpy(prefix, argv0_path);
308307
do {
@@ -334,16 +333,8 @@ search_for_exec_prefix(argv0_path, home)
334333
{
335334
int n;
336335

337-
/* Check to see if argv[0] is in the build directory */
338-
strcpy(exec_prefix, argv0_path);
339-
joinpath(exec_prefix, "Modules/Setup");
340-
if (isfile(exec_prefix)) {
341-
reduce(exec_prefix);
342-
return -1;
343-
}
344-
336+
/* If PYTHONHOME is set, we believe it unconditionally */
345337
if (home) {
346-
/* Check $PYTHONHOME */
347338
char *delim;
348339
delim = strchr(home, DELIM);
349340
if (delim)
@@ -352,10 +343,17 @@ search_for_exec_prefix(argv0_path, home)
352343
strcpy(exec_prefix, home);
353344
joinpath(exec_prefix, lib_python);
354345
joinpath(exec_prefix, "lib-dynload");
355-
if (isdir(exec_prefix))
356346
return 1;
357347
}
358348

349+
/* Check to see if argv[0] is in the build directory */
350+
strcpy(exec_prefix, argv0_path);
351+
joinpath(exec_prefix, "Modules/Setup");
352+
if (isfile(exec_prefix)) {
353+
reduce(exec_prefix);
354+
return -1;
355+
}
356+
359357
/* Search from argv0_path, until root is found */
360358
strcpy(exec_prefix, argv0_path);
361359
do {

PC/getpathp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ PERFORMANCE OF THIS SOFTWARE.
5353
5454
* We attempt to locate the "Python Home" - if the PYTHONHOME env var
5555
is set, we believe it. Otherwise, we use the path of our host .EXE's
56-
to try and locate our "landmark" (lib\\string.py) and deduce our home.
56+
to try and locate our "landmark" (lib\\os.py) and deduce our home.
5757
- If we DO have a Python Home: The relevant sub-directories (Lib,
5858
plat-win, lib-tk, etc) are based on the Python Home
5959
- If we DO NOT have a Python Home, the core Python Path is
@@ -110,7 +110,7 @@ PERFORMANCE OF THIS SOFTWARE.
110110
*/
111111

112112
#ifndef LANDMARK
113-
#define LANDMARK "lib\\string.py"
113+
#define LANDMARK "lib\\os.py"
114114
#endif
115115

116116
static char prefix[MAXPATHLEN+1];

PC/os2vacpp/getpathp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ extern BOOL PyWin_IsWin32s();
6868
*
6969
* Otherwise, if there is a PYTHONPATH environment variable, we return that.
7070
*
71-
* Otherwise we try to find $progpath/lib/string.py, and if found, then
71+
* Otherwise we try to find $progpath/lib/os.py, and if found, then
7272
* root is $progpath/lib, and we return Python path as compiled PYTHONPATH
7373
* with all "./lib" replaced by $root (as above).
7474
*
7575
*/
7676

7777
#ifndef LANDMARK
78-
#define LANDMARK "lib\\string.py"
78+
#define LANDMARK "lib\\os.py"
7979
#endif
8080

8181
static char prefix[MAXPATHLEN+1];

0 commit comments

Comments
 (0)