mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
Sigh. More restructuring was needed.
Make an explicit test for whether the prefix is in fact the source directory, and then don't use the registry.
This commit is contained in:
parent
7fb668866d
commit
43ff114d2b
1 changed files with 57 additions and 27 deletions
|
@ -98,6 +98,23 @@ exists(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
ismodule(filename) /* Is module -- check for .pyc/.pyo too */
|
||||||
|
char *filename;
|
||||||
|
{
|
||||||
|
if (exists(filename))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
/* Check for the compiled version of prefix. */
|
||||||
|
if (strlen(filename) < MAXPATHLEN) {
|
||||||
|
strcat(filename, Py_OptimizeFlag ? "o" : "c");
|
||||||
|
if (exists(filename))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
join(buffer, stuff)
|
join(buffer, stuff)
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
@ -131,7 +148,7 @@ search_for_prefix(argv0_path, landmark)
|
||||||
do {
|
do {
|
||||||
n = strlen(prefix);
|
n = strlen(prefix);
|
||||||
join(prefix, landmark);
|
join(prefix, landmark);
|
||||||
if (exists(prefix)) {
|
if (ismodule(prefix)) {
|
||||||
prefix[n] = '\0';
|
prefix[n] = '\0';
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -142,6 +159,22 @@ search_for_prefix(argv0_path, landmark)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MS_WIN32
|
#ifdef MS_WIN32
|
||||||
|
|
||||||
|
#ifndef BUILD_LANDMARK
|
||||||
|
#define BUILD_LANDMARK "PC\\getpathp.c"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int
|
||||||
|
prefixisbuilddir()
|
||||||
|
{
|
||||||
|
int n = strlen(prefix);
|
||||||
|
int ok;
|
||||||
|
join(prefix, BUILD_LANDMARK);
|
||||||
|
ok = exists(prefix);
|
||||||
|
prefix[n] = '\0';
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
#include "malloc.h" // for alloca - see comments below!
|
#include "malloc.h" // for alloca - see comments below!
|
||||||
extern const char *PyWin_DLLVersionString; // a string loaded from the DLL at startup.
|
extern const char *PyWin_DLLVersionString; // a string loaded from the DLL at startup.
|
||||||
|
|
||||||
|
@ -309,18 +342,10 @@ calculate_path()
|
||||||
int bufsz;
|
int bufsz;
|
||||||
char *pythonhome = Py_GetPythonHome();
|
char *pythonhome = Py_GetPythonHome();
|
||||||
char *envpath = getenv("PYTHONPATH");
|
char *envpath = getenv("PYTHONPATH");
|
||||||
#ifdef MS_WIN32
|
|
||||||
char *machinepath, *userpath;
|
|
||||||
|
|
||||||
/* Are we running under Windows 3.1(1) Win32s? */
|
#ifdef MS_WIN32
|
||||||
if (PyWin_IsWin32s()) {
|
char *machinepath = NULL;
|
||||||
/* Only CLASSES_ROOT is supported */
|
char *userpath = NULL;
|
||||||
machinepath = getpythonregpath(HKEY_CLASSES_ROOT, TRUE);
|
|
||||||
userpath = NULL;
|
|
||||||
} else {
|
|
||||||
machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, FALSE);
|
|
||||||
userpath = getpythonregpath(HKEY_CURRENT_USER, FALSE);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
get_progpath();
|
get_progpath();
|
||||||
|
@ -329,19 +354,8 @@ calculate_path()
|
||||||
if (pythonhome == NULL || *pythonhome == '\0') {
|
if (pythonhome == NULL || *pythonhome == '\0') {
|
||||||
if (search_for_prefix(argv0_path, LANDMARK))
|
if (search_for_prefix(argv0_path, LANDMARK))
|
||||||
pythonhome = prefix;
|
pythonhome = prefix;
|
||||||
else {
|
else
|
||||||
/* Couldnt find a source version - lets see if a compiled version exists. */
|
pythonhome = NULL;
|
||||||
char LANDMARK_Look[MAX_PATH+1];
|
|
||||||
strcpy(LANDMARK_Look, LANDMARK);
|
|
||||||
/* Turn it into ".pyc" or ".pyc" depending on the current mode. */
|
|
||||||
strcat(LANDMARK_Look, Py_OptimizeFlag ? "o": "c");
|
|
||||||
/* And search again */
|
|
||||||
if (search_for_prefix(argv0_path, LANDMARK_Look))
|
|
||||||
pythonhome = prefix;
|
|
||||||
else
|
|
||||||
/* Give up in disgust - just use the default! */
|
|
||||||
pythonhome = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strcpy(prefix, pythonhome);
|
strcpy(prefix, pythonhome);
|
||||||
|
@ -349,14 +363,30 @@ calculate_path()
|
||||||
if (envpath && *envpath == '\0')
|
if (envpath && *envpath == '\0')
|
||||||
envpath = NULL;
|
envpath = NULL;
|
||||||
|
|
||||||
/* We need to construct a path from the following parts:
|
#ifdef MS_WIN32
|
||||||
|
if (!prefixisbuilddir()) {
|
||||||
|
/* Are we running under Windows 3.1(1) Win32s? */
|
||||||
|
if (PyWin_IsWin32s()) {
|
||||||
|
/* Only CLASSES_ROOT is supported */
|
||||||
|
machinepath = getpythonregpath(HKEY_CLASSES_ROOT, TRUE);
|
||||||
|
userpath = NULL;
|
||||||
|
} else {
|
||||||
|
machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, FALSE);
|
||||||
|
userpath = getpythonregpath(HKEY_CURRENT_USER, FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* We need to construct a path from the following parts.
|
||||||
(1) the PYTHONPATH environment variable, if set;
|
(1) the PYTHONPATH environment variable, if set;
|
||||||
(2) for Win32, the machinepath and userpath, if set;
|
(2) for Win32, the machinepath and userpath, if set;
|
||||||
The following only if neither machinepath nor userpath is set:
|
|
||||||
(3) the PYTHONPATH config macro, with the leading "."
|
(3) the PYTHONPATH config macro, with the leading "."
|
||||||
of each component replaced with pythonhome, if set;
|
of each component replaced with pythonhome, if set;
|
||||||
(4) the directory containing the executable (argv0_path).
|
(4) the directory containing the executable (argv0_path).
|
||||||
The length calculation calculates #3 first.
|
The length calculation calculates #3 first.
|
||||||
|
Extra rules:
|
||||||
|
- If PYTHONHOME is set (in any way) item (2) is ignored.
|
||||||
|
- If registry values are used, (3) and (4) are ignored.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Calculate size of return buffer */
|
/* Calculate size of return buffer */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue