From 697e56d0f592165209cbeb87583c75dc231c6338 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Fri, 25 Jan 2013 17:57:13 +0100 Subject: [PATCH] Issue #1602133: 'environ' is not really available with shared libraries on OSX There already was a workaround for this for framework builds on OSX, this changeset enables the same workaround for shared libraries. Closes #1602133 --- Misc/NEWS | 3 +++ Modules/posixmodule.c | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index da71cd610fe..e19c06948da 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -197,6 +197,9 @@ Core and Builtins - Issue #13521: dict.setdefault() now does only one lookup for the given key, making it "atomic" for many purposes. Patch by Filip GruszczyƄski. +- Issue #1602133: on Mac OS X a shared library build (``--enable-shared``) + now fills the ``os.environ`` variable correctly. + - Issue #14471: Fix a possible buffer overrun in the winreg module. Library diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index e7e530589cf..4179c0ef074 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -501,9 +501,10 @@ win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag) #endif /* MS_WINDOWS */ /* Return a dictionary corresponding to the POSIX environment table */ -#ifdef WITH_NEXT_FRAMEWORK +#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) /* On Darwin/MacOSX a shared library or framework has no access to -** environ directly, we must obtain it with _NSGetEnviron(). +** environ directly, we must obtain it with _NSGetEnviron(). See also +** man environ(7). */ #include static char **environ; @@ -528,7 +529,7 @@ convertenviron(void) d = PyDict_New(); if (d == NULL) return NULL; -#ifdef WITH_NEXT_FRAMEWORK +#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) if (environ == NULL) environ = *_NSGetEnviron(); #endif