[m-rev.] diff: fix up a C compiler warning on MinGW

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Dec 14 02:26:31 AEDT 2010


Branches: main

Fix a problem with the handling of the environ "global variable" on MinGW
that was resulting in a C compiler warning being emitted when the io 
module was compiled.

library/io.m:
 	Don't declare the global variable environ on MinGW.  On that
 	system it is a macro that expands to a function call that returns
 	the user environment.

 	Document the above.  Also, gather the documentation about how
         the environ "global" is handled on various systems into one comment.

runtime/mercury_conf_param.h:
 	Define MR_MINGW when we are using MinGW.

Julien.

Index: runtime/mercury_conf_param.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_conf_param.h,v
retrieving revision 1.115
diff -u -r1.115 mercury_conf_param.h
--- runtime/mercury_conf_param.h	11 Oct 2010 00:49:27 -0000	1.115
+++ runtime/mercury_conf_param.h	13 Dec 2010 15:17:46 -0000
@@ -1022,4 +1022,14 @@

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

+/*
+** MinGW specific.
+*/
+
+#if defined(__MINGW32__)
+   #define MR_MINGW
+#endif
+
+/*---------------------------------------------------------------------------*/
+
  #endif /* MERCURY_CONF_PARAM_H */
Index: library/io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.449
diff -u -r1.449 io.m
--- library/io.m	9 Dec 2010 05:22:19 -0000	1.449
+++ library/io.m	13 Dec 2010 15:17:46 -0000
@@ -9396,11 +9396,28 @@

  :- pragma foreign_decl("C", "

+/*
+** A note regarding the declaration of the environ global variable
+** that follows:
+**
+** The man page (on Linux) says that it should be declared by the user
+** program.
+**
+** On MinGW, environ is a macro (defined in stdlib.h) that expands to a
+** function call that returns the user environment; no additional
+** declaration is required.
+**
+** 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_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;
+ 
+    #if !defined(MR_MINGW)
+        extern char **environ;
+    #endif
  #endif

  #if defined(MR_MAC_OSX)
@@ -9440,9 +9457,8 @@
      MR_OBTAIN_GLOBAL_LOCK(MR_PROC_LABEL);

      /*
-    ** 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().
+    ** See the comment at the head of the body of preceding foreign_decl
+    ** for details of why Mac OS X is different here.
      */
      #if defined(MR_MAC_OSX)
          err = posix_spawn(&pid, ""/bin/sh"", NULL, NULL, argv,
--------------------------------------------------------------------------
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