Skip to content

Commit 55070f5

Browse files
committedDec 2, 2001
Changed logic for finding python home in Mac OS X framework Pythons.
Now sys.executable points to the executable again, in stead of to the shared library. The latter is used only for locating the python home.
1 parent 398c236 commit 55070f5

File tree

1 file changed

+45
-47
lines changed

1 file changed

+45
-47
lines changed
 

‎Modules/getpath.c

+45-47
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,50 @@ calculate_path(void)
374374
NSModule pythonModule;
375375
#endif
376376

377+
/* If there is no slash in the argv0 path, then we have to
378+
* assume python is on the user's $PATH, since there's no
379+
* other way to find a directory to start the search from. If
380+
* $PATH isn't exported, you lose.
381+
*/
382+
if (strchr(prog, SEP))
383+
strncpy(progpath, prog, MAXPATHLEN);
384+
else if (path) {
385+
while (1) {
386+
char *delim = strchr(path, DELIM);
387+
388+
if (delim) {
389+
size_t len = delim - path;
390+
if (len > MAXPATHLEN)
391+
len = MAXPATHLEN;
392+
strncpy(progpath, path, len);
393+
*(progpath + len) = '\0';
394+
}
395+
else
396+
strncpy(progpath, path, MAXPATHLEN);
397+
398+
joinpath(progpath, prog);
399+
if (isxfile(progpath))
400+
break;
401+
402+
if (!delim) {
403+
progpath[0] = '\0';
404+
break;
405+
}
406+
path = delim + 1;
407+
}
408+
}
409+
else
410+
progpath[0] = '\0';
411+
if (progpath[0] != SEP)
412+
absolutize(progpath);
413+
strncpy(argv0_path, progpath, MAXPATHLEN);
414+
377415
#ifdef WITH_NEXT_FRAMEWORK
416+
/* On Mac OS X we have a special case if we're running from a framework.
417+
** This is because the python home should be set relative to the library,
418+
** which is in the framework, not relative to the executable, which may
419+
** be outside of the framework. Except when we're in the build directory...
420+
*/
378421
pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize"));
379422
/* Use dylib functions to find out where the framework was loaded from */
380423
buf = NSLibraryNameForModule(pythonModule);
@@ -394,60 +437,15 @@ calculate_path(void)
394437
if (!ismodule(argv0_path)) {
395438
/* We are in the build directory so use the name of the
396439
executable - we know that the absolute path is passed */
397-
strncpy(progpath, prog, MAXPATHLEN);
440+
strncpy(argv0_path, prog, MAXPATHLEN);
398441
}
399442
else {
400443
/* Use the location of the library as the progpath */
401-
strncpy(progpath, buf, MAXPATHLEN);
444+
strncpy(argv0_path, buf, MAXPATHLEN);
402445
}
403446
}
404-
else {
405-
/* If we're not in a framework, fall back to the old way
406-
(even though NSNameOfModule() probably does the same thing.) */
407447
#endif
408448

409-
/* If there is no slash in the argv0 path, then we have to
410-
* assume python is on the user's $PATH, since there's no
411-
* other way to find a directory to start the search from. If
412-
* $PATH isn't exported, you lose.
413-
*/
414-
if (strchr(prog, SEP))
415-
strncpy(progpath, prog, MAXPATHLEN);
416-
else if (path) {
417-
while (1) {
418-
char *delim = strchr(path, DELIM);
419-
420-
if (delim) {
421-
size_t len = delim - path;
422-
if (len > MAXPATHLEN)
423-
len = MAXPATHLEN;
424-
strncpy(progpath, path, len);
425-
*(progpath + len) = '\0';
426-
}
427-
else
428-
strncpy(progpath, path, MAXPATHLEN);
429-
430-
joinpath(progpath, prog);
431-
if (isxfile(progpath))
432-
break;
433-
434-
if (!delim) {
435-
progpath[0] = '\0';
436-
break;
437-
}
438-
path = delim + 1;
439-
}
440-
}
441-
else
442-
progpath[0] = '\0';
443-
if (progpath[0] != SEP)
444-
absolutize(progpath);
445-
#ifdef WITH_NEXT_FRAMEWORK
446-
}
447-
#endif
448-
449-
strncpy(argv0_path, progpath, MAXPATHLEN);
450-
451449
#if HAVE_READLINK
452450
{
453451
char tmpbuffer[MAXPATHLEN+1];

0 commit comments

Comments
 (0)
Please sign in to comment.