[m-rev.] diff: avoid issues with environ global on macOS

Julien Fischer jfischer at opturion.com
Thu Aug 19 00:41:15 AEST 2021


Avoid issues with environ global on macOS.

compiler/options_file.m:
     Programs on macOS cannot access the environ global directly
     and must do so via the _NSGetEnviron() function.

Julien.

diff --git a/compiler/options_file.m b/compiler/options_file.m
index 273dc95..e252a47 100644
--- a/compiler/options_file.m
+++ b/compiler/options_file.m
@@ -1666,9 +1666,18 @@ get_environment_var_map(EnvVarMap, !IO) :-
      MR_Word cur_env = EnvVarAL0;
      MR_Word next_env;
      int     i;
-
-    for (i = 0; environ[i] != NULL; i++) {
-        MC_record_env_var_equal_value(environ[i], cur_env, &next_env);
+    char    **environ_vars;
+
+    // See the comments about the enivorn global in library/io.m
+    // for an explanation of this.
+    #if defined(MR_MAC_OSX)
+        environ_vars = (*_NSGetEnviron());
+    #else
+        environ_vars = environ;
+    #endif
+
+    for (i = 0; environ_vars[i] != NULL; i++) {
+        MC_record_env_var_equal_value(environ_vars[i], cur_env, &next_env);
          cur_env = next_env;
      }



More information about the reviews mailing list