[commit: packages/unix] master: Have Autoconf test for _NSGetEnviron presence (12799d0)

git at git.haskell.org git at git.haskell.org
Tue Apr 19 21:38:34 UTC 2016


Repository : ssh://git@git.haskell.org/unix

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/12799d0fc7dcff0dc95640b1efad0637ad011144/unix

>---------------------------------------------------------------

commit 12799d0fc7dcff0dc95640b1efad0637ad011144
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Sun Jan 31 16:54:04 2016 +0100

    Have Autoconf test for _NSGetEnviron presence


>---------------------------------------------------------------

12799d0fc7dcff0dc95640b1efad0637ad011144
 System/Posix/Env.hsc            | 6 ++----
 System/Posix/Env/ByteString.hsc | 4 ++--
 configure.ac                    | 4 ++++
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc
index 6412bae..7d5f04c 100644
--- a/System/Posix/Env.hsc
+++ b/System/Posix/Env.hsc
@@ -78,9 +78,8 @@ getEnvironmentPrim = do
       mapM peekFilePath arr
 
 getCEnviron :: IO (Ptr CString)
-
-#if darwin_HOST_OS
--- You should not access _environ directly on Darwin in a bundle/shared library.
+#if HAVE__NSGETENVIRON
+-- You should not access @char **environ@ directly on Darwin in a bundle/shared library.
 -- See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
 getCEnviron = nsGetEnviron >>= peek
 
@@ -88,7 +87,6 @@ foreign import ccall unsafe "_NSGetEnviron"
    nsGetEnviron :: IO (Ptr (Ptr CString))
 #else
 getCEnviron = peek c_environ_p
-
 foreign import ccall unsafe "&environ"
    c_environ_p :: Ptr (Ptr CString)
 #endif
diff --git a/System/Posix/Env/ByteString.hsc b/System/Posix/Env/ByteString.hsc
index 57b03aa..c6c374c 100644
--- a/System/Posix/Env/ByteString.hsc
+++ b/System/Posix/Env/ByteString.hsc
@@ -69,8 +69,8 @@ getEnvironmentPrim = do
   mapM B.packCString arr
 
 getCEnviron :: IO (Ptr CString)
-#if darwin_HOST_OS
--- You should not access _environ directly on Darwin in a bundle/shared library.
+#if HAVE__NSGETENVIRON
+-- You should not access @char **environ@ directly on Darwin in a bundle/shared library.
 -- See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
 getCEnviron = nsGetEnviron >>= peek
 
diff --git a/configure.ac b/configure.ac
index 5b6eb7c..fdc27e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,10 @@ AC_CHECK_FUNCS([readdir_r])
 dnl not available on android so check for it
 AC_CHECK_FUNCS([telldir seekdir])
 
+dnl When available, _NSGetEnviron() (defined in <crt_externs.h>) is
+dnl the preferred way to access environ(7)
+AC_CHECK_FUNCS([_NSGetEnviron])
+
 dnl This is e.g. available as a GNU extension in glibc 2.11+
 AC_CHECK_DECLS([execvpe])
 AC_CHECK_FUNCS([execvpe])



More information about the ghc-commits mailing list