autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bruno Haible <address@hidden>] _AC_COMPUTE_INT forgets to include s


From: Paul Eggert
Subject: Re: [Bruno Haible <address@hidden>] _AC_COMPUTE_INT forgets to include stdio.h, stdlib.h
Date: Tue, 18 Sep 2001 11:04:34 -0700 (PDT)

> From: Bruno Haible <address@hidden>
>
> Not allowing negative numbers is a bigger problem than not allowing
> values greater than LONG_MAX. When I test for EILSEQ, for example, all
> I know is that it will be an 'int' (because errno is an 'int'). It
> could be negative.

EILSEQ can't be negative on an host that conforms to POSIX, so it's
unlikely that the code was exercised with negative numbers.  Negative
numbers have never really been supported in the past: they may have
worked in that little bit of code, but the parent shell script doesn't
handle them reliably.

That being said, I fixed the code so that it worked at least as well
as it did before with negative numbers, as follows.  I also fixed a
shell-evaluation bug with negative numbers that I found in the
process.

However, the resulting code still isn't entirely reliable with
negative numbers.  For example, on a host with 32-bit int, C treats
'-2147483648' as if it were 2147483648 (because of the usual C brain
damage with unsigned values), whereas 'expr' treats it as if it were
-2147483648.  I see no easy fix for this longstanding bug, so I left
it alone.

2001-09-18  Paul Eggert  <address@hidden>

        * lib/autoconf/c.m4:
        (AC_LANG_INT_SAVE(C)): Also support negative values, down to LONG_MIN.

        * lib/autoconf/general.m4 (_AC_COMPUTE_INT_COMPILE):
        Do not pass a first argument with leading '-'
        to expr, by parenthesizing initial integers that might be negative.

Index: lib/autoconf/c.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/c.m4,v
retrieving revision 1.154
diff -p -u -r1.154 c.m4
--- lib/autoconf/c.m4   2001/09/17 21:49:30     1.154
+++ lib/autoconf/c.m4   2001/09/18 17:52:33
@@ -208,22 +208,29 @@ _array_ @<:@0@:>@ = 0
 # But we include them only after the EXPRESSION has been evaluated.
 m4_define([AC_LANG_INT_SAVE(C)],
 [AC_LANG_PROGRAM([$1
-unsigned long conftestval () { return $2; }
+long longval () { return $2; }
+unsigned long ulongval () { return $2; }
 @%:@include <stdio.h>
 @%:@include <stdlib.h>],
 [
   FILE *f = fopen ("conftest.val", "w");
-  if (f)
+  if (! f)
+    exit (1);
+  if (($2) < 0)
     {
-      unsigned long i = conftestval ();
-      if (0 <= ($2) && i == ($2))
-       {
-         fprintf (f, "%lu\n", i);
-         if (! ferror (f) && fclose (f) == 0)
-           exit (0);
-       }
+      long i = longval ();
+      if (i != ($2))
+       exit (1);
+      fprintf (f, "%ld\n", i);
     }
-  exit (1);
+  else
+    {
+      unsigned long i = ulongval ();
+      if (i != ($2))
+       exit (1);
+      fprintf (f, "%lu\n", i);
+    }
+  exit (ferror (f) || fclose (f) != 0);
 ])])
 
 
Index: lib/autoconf/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/general.m4,v
retrieving revision 1.765
diff -p -u -r1.765 general.m4
--- lib/autoconf/general.m4     2001/09/18 12:26:36     1.765
+++ lib/autoconf/general.m4     2001/09/18 17:52:36
@@ -2517,13 +2517,13 @@ AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_
   while :; do
     AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= $ac_mid])],
                       [ac_lo=$ac_mid; break],
-                      [ac_hi=`expr $ac_mid - 1`; ac_mid=`expr 2 '*' $ac_mid`])
+                      [ac_hi=`expr '(' $ac_mid ')' - 1`; ac_mid=`expr 2 '*' 
$ac_mid`])
   done])
 # Binary search between lo and hi bounds.
 while test "x$ac_lo" != "x$ac_hi"; do
   ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
   AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_mid])],
-                     [ac_hi=$ac_mid], [ac_lo=`expr $ac_mid + 1`])
+                     [ac_hi=$ac_mid], [ac_lo=`expr '(' $ac_mid ')' + 1`])
 done
 $2=$ac_lo[]dnl
 ])# _AC_COMPUTE_INT_COMPILE



reply via email to

[Prev in Thread] Current Thread [Next in Thread]