Paul Eggert wrote:

>Derek Price <[EMAIL PROTECTED]> writes:
>
>  
>
>>Corrected patch attached.
>>    
>>
>
>Thanks.  A couple more things.  (Sorry I didn't catch it earlier.)
>First, the $gl_* variables should be cached, with AC_CACHE_CHECK.
>  
>

Done.

>Second, suppose <limits.h> and <sys/param.h> have conflicting
>definitions of MIN and MAX?  To work around the latter potential
>problem you can #undef MIN and MAX after including <limits.h>.
>  
>

Done.  Since you are worried about potential system header conflicts, I
also had to update gl_PREREQ_MINMAX to always check for MIN in
<sys/param.h> as well as <limits.h>.  It used to skip the <sys/param.h>
check if MIN was found in <limits.h>.

Revised patch attached.

2005-05-18  Derek Price  <[EMAIL PROTECTED]>

    * lib/minmax.h: Only include <limits.h> and <sys/param.h> when needed.
    * m4/minmax.m4: New file.
    * modules/minmax: Add minmax.m4.


Regards,

Derek
Index: lib/minmax.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/minmax.h,v
retrieving revision 1.4
diff -u -p -r1.4 minmax.h
--- lib/minmax.h        14 May 2005 06:03:58 -0000      1.4
+++ lib/minmax.h        18 May 2005 18:10:23 -0000
@@ -23,9 +23,19 @@
    MIN, MAX macro redefinitions on some systems; the workaround is to
    #include this file as the last one among the #include list.  */
 
-/* Before we define the following symbols we get the <limits.h> file
-   since otherwise we get redefinitions on some systems.  */
-#include <limits.h>
+/* Before we define the following symbols we try to get the <limits.h>
+   or <sys/param.h> files since otherwise we get redefinitions on some
+   systems.  */
+#ifdef LIMITS_H_HAS_MINMAX
+# include <limits.h>
+/* Avoid allowing the MIN & MAX definitions from these two headers to conflict.
+   There are no known systems where this is a problem.  */
+# undef MIN
+# undef MAX
+#endif
+#ifdef SYS_PARAM_H_HAS_MINMAX
+# include <sys/param.h>
+#endif
 
 /* Note: MIN and MAX should be used with two arguments of the
    same type.  They might not return the minimum and maximum of their two
Index: m4/minmax.m4
===================================================================
RCS file: m4/minmax.m4
diff -N m4/minmax.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ m4/minmax.m4        18 May 2005 18:10:23 -0000
@@ -0,0 +1,35 @@
+# minmax.m4 serial 1
+dnl Copyright (C) 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_MINMAX], [gl_PREREQ_MINMAX])
+
+# Prerequisites of minmax.h.
+AC_DEFUN([gl_PREREQ_MINMAX],
+[
+  AC_CACHE_CHECK([whether <limits.h> defines MIN & MAX],
+                gl_limits_h_has_minmax,
+    [AC_COMPILE_IFELSE(
+[#include <limits.h>
+int x = MIN (1, 2);],
+      [gl_limits_h_has_minmax=yes], [gl_limits_h_has_minmax=no])])
+
+  if test $gl_limits_h_has_minmax = yes; then
+    AC_DEFINE(LIMITS_H_HAS_MINMAX, 1,
+      [Define to 1 if <limits.h> defines the MIN and MAX macros.])
+  fi
+
+  AC_CACHE_CHECK([whether <sys/param.h> defines MIN & MAX],
+                gl_sys_param_h_has_minmax,
+    [AC_COMPILE_IFELSE(
+[#include <sys/param.h>
+int x = MIN (1, 2);],
+      [gl_sys_param_h_has_minmax=yes], [gl_sys_param_h_has_minmax=no])])
+
+  if test $gl_sys_param_h_has_minmax = yes; then
+    AC_DEFINE(SYS_PARAM_H_HAS_MINMAX, 1,
+      [Define to 1 if <sys/param.h> defines the MIN and MAX macros.])
+  fi
+  :])
Index: modules/minmax
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/minmax,v
retrieving revision 1.3
diff -u -p -r1.3 minmax
--- modules/minmax      28 Sep 2004 20:15:39 -0000      1.3
+++ modules/minmax      18 May 2005 18:10:23 -0000
@@ -3,10 +3,12 @@ MIN, MAX macros.
 
 Files:
 lib/minmax.h
+m4/minmax.m4
 
 Depends-on:
 
 configure.ac:
+gl_MINMAX
 
 Makefile.am:
 lib_SOURCES += minmax.h
_______________________________________________
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib

Reply via email to