Remove dependency of xalloc.h on SIZE_MAX and PTRDIFF_MAX.
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 13 Nov 2003 07:19:08 +0000 (07:19 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 13 Nov 2003 07:19:08 +0000 (07:19 +0000)
ChangeLog
lib/ChangeLog
lib/xalloc.h
m4/ChangeLog
m4/xalloc.m4
modules/xalloc

index 37219b0..b733dd0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,12 @@
+2003-11-12  Paul Eggert  <eggert@twinsun.com>
+
+       * modules/xalloc (Files): Undo latest change, since xalloc.h
+       no longer needs SIZE_MAX or PTRDIFF_MAX.
+
 2003-11-11  Bruno Haible  <bruno@clisp.org>
 
        * modules/xsize (Files): Add m4/size_max.m4.
-       * modules/xalloc (Files): Add m4/size_max.m4, m4_ptrdiff_max.m4.
+       * modules/xalloc (Files): Add m4/size_max.m4, m4/ptrdiff_max.m4.
 
 2003-11-04  Bruno Haible  <bruno@clisp.org>
 
 2003-08-18  Paul Eggert  <eggert@twinsun.com>
 
        * modules/stdbool: Add BUILT_SOURCES.  Prefer $@ to target name
-        in makefile rules.
+       in makefile rules.
 
 2003-08-17  Simon Josefsson  <jas@extundo.com>
 
index 6163b5d..29fc9b9 100644 (file)
@@ -1,3 +1,17 @@
+2003-11-12  Paul Eggert  <eggert@twinsun.com>
+
+       * xalloc.h: Do not include <limits.h> or <stdint.h>.
+       (xalloc_oversized): Use sizeof (ptrdiff_t) and sizeof (size_t) for
+       the heuristic, rather than PTRDIFF_MAX and SIZE_MAX.  This
+       heuristic is just as accurate as far as we know, and it removes a
+       dependency on size_max.m4 and ptrdiff_max.m4.
+
+2003-11-12  Paul Eggert  <eggert@twinsun.com>
+
+       * xstrtol.c (__xstrtol): Remove "break" immediately after
+       "return", to pacify some unknown compiler.  Problem reported
+       by Joerg Schilling.
+
 2003-11-11  Bruno Haible  <bruno@clisp.org>
 
        * xsize.h (SIZE_MAX): Remove fallback definition.
index 8faf316..4b65858 100644 (file)
 #ifndef XALLOC_H_
 # define XALLOC_H_
 
-/* Get size_t.  */
 # include <stddef.h>
 
-/* Get SIZE_MAX, PTRDIFF_MAX.  */
-# include <limits.h>
-# if HAVE_STDINT_H
-#  include <stdint.h>
-# endif
-
 # ifndef __attribute__
 #  if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
 #   define __attribute__(x)
@@ -75,14 +68,11 @@ char *xstrdup (const char *str);
    calculations, so the conservative dividend to use here is
    SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
    However, malloc (SIZE_MAX) fails on all known hosts where
-   PTRDIFF_MAX < SIZE_MAX, so do not bother to test for
+   sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
    exactly-SIZE_MAX allocations on such hosts; this avoids a test and
    branch when S is known to be 1.  */
-# if PTRDIFF_MAX < SIZE_MAX
-#  define xalloc_oversized(n, s) (SIZE_MAX / (s) < (n))
-# else
-#  define xalloc_oversized(n, s) ((SIZE_MAX - 1) / (s) < (n))
-# endif
+# define xalloc_oversized(n, s) \
+    ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
 
 /* These macros are deprecated; they will go away soon, and are retained
    temporarily only to ease conversion to the functions described above.  */
index 418503b..2f2b32f 100644 (file)
@@ -1,3 +1,8 @@
+2003-11-12  Paul Eggert  <eggert@twinsun.com>
+
+       * xalloc.m4 (gl_PREREQ_XALLOC): Do not require gl_SIZE_MAX or
+       gl_PTRDIFF_MAX.
+
 2003-11-11  Bruno Haible  <bruno@clisp.org>
 
        * size_max.m4: New file.
index 07efb2f..dec8417 100644 (file)
@@ -1,4 +1,4 @@
-# xalloc.m4 serial 7
+# xalloc.m4 serial 8
 dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
@@ -15,8 +15,6 @@ AC_DEFUN([gl_XALLOC],
 
 # Prerequisites of lib/xalloc.h.
 AC_DEFUN([gl_PREREQ_XALLOC], [
-  AC_REQUIRE([gl_SIZE_MAX])
-  AC_REQUIRE([gl_PTRDIFF_MAX])
   :
 ])
 
index 2e7b89b..46482cc 100644 (file)
@@ -6,8 +6,6 @@ lib/xalloc.h
 lib/xmalloc.c
 lib/xstrdup.c
 m4/xalloc.m4
-m4/size_max.m4
-m4/ptrdiff_max.m4
 
 Depends-on:
 malloc