[m-rev.] diff: fix linking problem in .par grades on mac os x

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Dec 11 01:53:04 AEDT 2007


Estimated hours taken: 1
Branches: main

Fix a linking error in .par grades on Mac OS X due to an undefined symbol.

library/io.m:
 	On Mac OS X shared libraries cannot access environ directly but must
 	instead look its address up at runtime using the function
 	_NSGetEnviron().

runtime/mercury_conf_param.h:
 	Add a new macro MR_MAC_OSX that is defined Mac OS X systems.

Julien.

Index: library/io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.406
diff -u -r1.406 io.m
--- library/io.m	23 Nov 2007 07:35:56 -0000	1.406
+++ library/io.m	10 Dec 2007 14:40:52 -0000
@@ -9314,13 +9314,17 @@

  :- pragma foreign_decl("C", "

-#ifdef MR_HAVE_ENVIRON
+#if defined(MR_HAVE_ENVIRON) && !defined(MR_MAC_OSX)
      #include <unistd.h>

      /* The man page says that this should be declared by the user program. */
      extern char **environ;
  #endif

+#if defined(MR_MAC_OSX)
+    #include <crt_externs.h>
+#endif
+
  #ifdef MR_HAVE_SPAWN_H
      #include <spawn.h>
  #endif
@@ -9353,7 +9357,17 @@
      /* Protect `environ' from concurrent modifications. */
      MR_OBTAIN_GLOBAL_LOCK(MR_PROC_LABEL);

-    err = posix_spawn(&pid, ""/bin/sh"", NULL, NULL, argv, environ);
+    /*
+    ** On Mac OS X shared libraries do not have direct access to environ.
+    ** The man page for environ(7) says that we should look it up at
+    ** runtime using _NSGetEnviron().
+    */
+    #if defined(MR_MAC_OSX)
+        err = posix_spawn(&pid, ""/bin/sh"", NULL, NULL, argv,
+            *_NSGetEnviron());
+    #else
+        err = posix_spawn(&pid, ""/bin/sh"", NULL, NULL, argv, environ);
+    #endif

      MR_RELEASE_GLOBAL_LOCK(MR_PROC_LABEL);

Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.103
diff -u -r1.103 mercury_conf_param.h
--- runtime/mercury_conf_param.h	24 Oct 2007 09:21:17 -0000	1.103
+++ runtime/mercury_conf_param.h	10 Dec 2007 14:40:52 -0000
@@ -894,4 +894,14 @@

  /*---------------------------------------------------------------------------*/

+/*
+** Mac OS X specific.
+*/
+
+#if defined(__APPLE__) && defined(__MACH__)
+   #define MR_MAC_OSX
+#endif
+
+/*---------------------------------------------------------------------------*/
+
  #endif /* MERCURY_CONF_PARAM_H */

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list