From 770fe161ab72b2ca228f34b4c065f337feccd087 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith [Google LLC]" Date: Tue, 19 Dec 2023 03:59:40 +0000 Subject: [PATCH 1/2] gh-113117: Fix the macOS framework installer build --- Modules/posixmodule.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 8ffe0f5de1e7bd..0d05e4f86acb96 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1557,6 +1557,7 @@ _Py_Sigset_Converter(PyObject *obj, void *addr) ** man environ(7). */ #include +#define USE_DARWIN_NS_GET_ENVIRON 1 #elif !defined(_MSC_VER) && (!defined(__WATCOMC__) || defined(__QNX__) || defined(__VXWORKS__)) extern char **environ; #endif /* !_MSC_VER */ @@ -1579,7 +1580,7 @@ convertenviron(void) through main() instead of wmain(). */ (void)_wgetenv(L""); e = _wenviron; -#elif defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) +#elif defined(USE_DARWIN_NS_GET_ENVIRON) /* environ is not accessible as an extern in a shared object on OSX; use _NSGetEnviron to resolve it. The value changes if you add environment variables between calls to Py_Initialize, so don't cache the value. */ @@ -7167,7 +7168,11 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a } if (env == Py_None) { +#if defined(USE_DARWIN_NS_GET_ENVIRON) + envlist = *_NSGetEnviron(); +#else envlist = environ; +#endif } else { envlist = parse_envlist(env, &envc); if (envlist == NULL) { From 737ffae20cc333658ba568d7b880296da265e28c Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith [Google LLC]" Date: Tue, 19 Dec 2023 04:04:49 +0000 Subject: [PATCH 2/2] fix the fix? :) --- Modules/posixmodule.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 0d05e4f86acb96..c7ee591f30c51f 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7167,12 +7167,16 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a goto exit; } +#ifdef USE_DARWIN_NS_GET_ENVIRON + // There is no environ global in this situation. + char **environ = NULL; +#endif + if (env == Py_None) { -#if defined(USE_DARWIN_NS_GET_ENVIRON) - envlist = *_NSGetEnviron(); -#else - envlist = environ; +#ifdef USE_DARWIN_NS_GET_ENVIRON + environ = *_NSGetEnviron(); #endif + envlist = environ; } else { envlist = parse_envlist(env, &envc); if (envlist == NULL) {