bpo-32030: Fix calculate_path() on macOS (#4526) · python/cpython@b919795 (original) (raw)

Original file line number Diff line number Diff line change
@@ -589,6 +589,15 @@ calculate_reduce_exec_prefix(PyCalculatePath *calculate, PyPathConfig *config)
589 589 static void
590 590 calculate_progpath(PyCalculatePath *calculate, PyPathConfig *config)
591 591 {
592 +#ifdef __APPLE__
593 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
594 +uint32_t nsexeclength = MAXPATHLEN;
595 +#else
596 +unsigned long nsexeclength = MAXPATHLEN;
597 +#endif
598 +char execpath[MAXPATHLEN+1];
599 +#endif
600 +
592 601 /* If there is no slash in the argv0 path, then we have to
593 602 * assume python is on the user's $PATH, since there's no
594 603 * other way to find a directory to start the search from. If
@@ -597,15 +606,7 @@ calculate_progpath(PyCalculatePath *calculate, PyPathConfig *config)
597 606 if (wcschr(calculate->prog, SEP)) {
598 607 wcsncpy(config->progpath, calculate->prog, MAXPATHLEN);
599 608 }
600 -
601 609 #ifdef __APPLE__
602 -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
603 -uint32_t nsexeclength = MAXPATHLEN;
604 -#else
605 -unsigned long nsexeclength = MAXPATHLEN;
606 -#endif
607 -char execpath[MAXPATHLEN+1];
608 -
609 610 /* On Mac OS X, if a script uses an interpreter of the form
610 611 * "#!/opt/python2.3/bin/python", the kernel only passes "python"
611 612 * as argv[0], which falls through to the $PATH search below.