Merged revisions 84008-84009 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r84008 | antoine.pitrou | 2010-08-14 14:33:18 +0200 (sam., 14 août 2010) | 3 lines Add comments about Windows in Modules/getpath.c ........ r84009 | antoine.pitrou | 2010-08-14 14:34:41 +0200 (sam., 14 août 2010) | 2 lines Fix indentation in Modules/getpath.c ........
This commit is contained in:
parent
abfb5ac30a
commit
d6dac2e2fd
|
@ -89,6 +89,8 @@
|
||||||
* directory). This seems to make more sense given that currently the only
|
* directory). This seems to make more sense given that currently the only
|
||||||
* known use of sys.prefix and sys.exec_prefix is for the ILU installation
|
* known use of sys.prefix and sys.exec_prefix is for the ILU installation
|
||||||
* process to find the installed Python tree.
|
* process to find the installed Python tree.
|
||||||
|
*
|
||||||
|
* NOTE: Windows MSVC builds use PC/getpathp.c instead!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -134,7 +136,10 @@ static wchar_t lib_python[] = L"lib/python" VERSION;
|
||||||
/* In principle, this should use HAVE__WSTAT, and _wstat
|
/* In principle, this should use HAVE__WSTAT, and _wstat
|
||||||
should be detected by autoconf. However, no current
|
should be detected by autoconf. However, no current
|
||||||
POSIX system provides that function, so testing for
|
POSIX system provides that function, so testing for
|
||||||
it is pointless. */
|
it is pointless.
|
||||||
|
Not sure whether the MS_WINDOWS guards are necessary:
|
||||||
|
perhaps for cygwin/mingw builds?
|
||||||
|
*/
|
||||||
#ifndef MS_WINDOWS
|
#ifndef MS_WINDOWS
|
||||||
static int
|
static int
|
||||||
_wstat(const wchar_t* path, struct stat *buf)
|
_wstat(const wchar_t* path, struct stat *buf)
|
||||||
|
@ -461,21 +466,21 @@ calculate_path(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (_path) {
|
if (_path) {
|
||||||
size_t r = mbstowcs(wpath, _path, MAXPATHLEN+1);
|
size_t r = mbstowcs(wpath, _path, MAXPATHLEN+1);
|
||||||
path = wpath;
|
path = wpath;
|
||||||
if (r == (size_t)-1 || r > MAXPATHLEN) {
|
if (r == (size_t)-1 || r > MAXPATHLEN) {
|
||||||
/* Could not convert PATH, or it's too long. */
|
/* Could not convert PATH, or it's too long. */
|
||||||
path = NULL;
|
path = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there is no slash in the argv0 path, then we have to
|
/* If there is no slash in the argv0 path, then we have to
|
||||||
* assume python is on the user's $PATH, since there's no
|
* assume python is on the user's $PATH, since there's no
|
||||||
* other way to find a directory to start the search from. If
|
* other way to find a directory to start the search from. If
|
||||||
* $PATH isn't exported, you lose.
|
* $PATH isn't exported, you lose.
|
||||||
*/
|
*/
|
||||||
if (wcschr(prog, SEP))
|
if (wcschr(prog, SEP))
|
||||||
wcsncpy(progpath, prog, MAXPATHLEN);
|
wcsncpy(progpath, prog, MAXPATHLEN);
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
/* On Mac OS X, if a script uses an interpreter of the form
|
/* On Mac OS X, if a script uses an interpreter of the form
|
||||||
* "#!/opt/python2.3/bin/python", the kernel only passes "python"
|
* "#!/opt/python2.3/bin/python", the kernel only passes "python"
|
||||||
|
@ -487,52 +492,52 @@ calculate_path(void)
|
||||||
* will fail if a relative path was used. but in that case,
|
* will fail if a relative path was used. but in that case,
|
||||||
* absolutize() should help us out below
|
* absolutize() should help us out below
|
||||||
*/
|
*/
|
||||||
else if(0 == _NSGetExecutablePath(execpath, &nsexeclength) && execpath[0] == SEP) {
|
else if(0 == _NSGetExecutablePath(execpath, &nsexeclength) && execpath[0] == SEP) {
|
||||||
size_t r = mbstowcs(progpath, execpath, MAXPATHLEN+1);
|
size_t r = mbstowcs(progpath, execpath, MAXPATHLEN+1);
|
||||||
if (r == (size_t)-1 || r > MAXPATHLEN) {
|
if (r == (size_t)-1 || r > MAXPATHLEN) {
|
||||||
/* Could not convert execpath, or it's too long. */
|
/* Could not convert execpath, or it's too long. */
|
||||||
progpath[0] = '\0';
|
progpath[0] = '\0';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif /* __APPLE__ */
|
#endif /* __APPLE__ */
|
||||||
else if (path) {
|
else if (path) {
|
||||||
while (1) {
|
while (1) {
|
||||||
wchar_t *delim = wcschr(path, DELIM);
|
wchar_t *delim = wcschr(path, DELIM);
|
||||||
|
|
||||||
if (delim) {
|
if (delim) {
|
||||||
size_t len = delim - path;
|
size_t len = delim - path;
|
||||||
if (len > MAXPATHLEN)
|
if (len > MAXPATHLEN)
|
||||||
len = MAXPATHLEN;
|
len = MAXPATHLEN;
|
||||||
wcsncpy(progpath, path, len);
|
wcsncpy(progpath, path, len);
|
||||||
*(progpath + len) = '\0';
|
*(progpath + len) = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
wcsncpy(progpath, path, MAXPATHLEN);
|
wcsncpy(progpath, path, MAXPATHLEN);
|
||||||
|
|
||||||
joinpath(progpath, prog);
|
joinpath(progpath, prog);
|
||||||
if (isxfile(progpath))
|
if (isxfile(progpath))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!delim) {
|
if (!delim) {
|
||||||
progpath[0] = L'\0';
|
progpath[0] = L'\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
path = delim + 1;
|
path = delim + 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
progpath[0] = '\0';
|
else
|
||||||
if (progpath[0] != SEP && progpath[0] != '\0')
|
progpath[0] = '\0';
|
||||||
absolutize(progpath);
|
if (progpath[0] != SEP && progpath[0] != '\0')
|
||||||
wcsncpy(argv0_path, progpath, MAXPATHLEN);
|
absolutize(progpath);
|
||||||
argv0_path[MAXPATHLEN] = '\0';
|
wcsncpy(argv0_path, progpath, MAXPATHLEN);
|
||||||
|
argv0_path[MAXPATHLEN] = '\0';
|
||||||
|
|
||||||
#ifdef WITH_NEXT_FRAMEWORK
|
#ifdef WITH_NEXT_FRAMEWORK
|
||||||
/* On Mac OS X we have a special case if we're running from a framework.
|
/* On Mac OS X we have a special case if we're running from a framework.
|
||||||
** This is because the python home should be set relative to the library,
|
** This is because the python home should be set relative to the library,
|
||||||
** which is in the framework, not relative to the executable, which may
|
** which is in the framework, not relative to the executable, which may
|
||||||
** be outside of the framework. Except when we're in the build directory...
|
** be outside of the framework. Except when we're in the build directory...
|
||||||
*/
|
*/
|
||||||
pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
|
pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
|
||||||
/* Use dylib functions to find out where the framework was loaded from */
|
/* Use dylib functions to find out where the framework was loaded from */
|
||||||
buf = (wchar_t *)NSLibraryNameForModule(pythonModule);
|
buf = (wchar_t *)NSLibraryNameForModule(pythonModule);
|
||||||
|
@ -550,13 +555,13 @@ calculate_path(void)
|
||||||
joinpath(argv0_path, lib_python);
|
joinpath(argv0_path, lib_python);
|
||||||
joinpath(argv0_path, LANDMARK);
|
joinpath(argv0_path, LANDMARK);
|
||||||
if (!ismodule(argv0_path)) {
|
if (!ismodule(argv0_path)) {
|
||||||
/* We are in the build directory so use the name of the
|
/* We are in the build directory so use the name of the
|
||||||
executable - we know that the absolute path is passed */
|
executable - we know that the absolute path is passed */
|
||||||
wcsncpy(argv0_path, progpath, MAXPATHLEN);
|
wcsncpy(argv0_path, progpath, MAXPATHLEN);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Use the location of the library as the progpath */
|
/* Use the location of the library as the progpath */
|
||||||
wcsncpy(argv0_path, buf, MAXPATHLEN);
|
wcsncpy(argv0_path, buf, MAXPATHLEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue