Rely on SIZE_MAX and PTRDIFF_MAX as defined by ISO C 99.
authorBruno Haible <bruno@clisp.org>
Tue, 11 Nov 2003 11:58:42 +0000 (11:58 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 11 Nov 2003 11:58:42 +0000 (11:58 +0000)
ChangeLog
lib/ChangeLog
lib/xalloc.h
lib/xsize.h
m4/ChangeLog
m4/xalloc.m4
m4/xsize.m4
modules/xalloc
modules/xsize

index e435554..37219b0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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.
+
 2003-11-04  Bruno Haible  <bruno@clisp.org>
 
        * modules/xsize: New file.
 2003-11-04  Bruno Haible  <bruno@clisp.org>
 
        * modules/xsize: New file.
index 0791de9..6163b5d 100644 (file)
@@ -1,3 +1,9 @@
+2003-11-11  Bruno Haible  <bruno@clisp.org>
+
+       * xsize.h (SIZE_MAX): Remove fallback definition.
+       * xalloc.h: Include limits.h. Assume SIZE_MAX and PTRDIFF_MAX are
+       defined.
+
 2003-11-10  Paul Eggert  <eggert@twinsun.com>
 
        * xalloc.h (xalloc_oversized): [! (defined PTRDIFF_MAX &&
 2003-11-10  Paul Eggert  <eggert@twinsun.com>
 
        * xalloc.h (xalloc_oversized): [! (defined PTRDIFF_MAX &&
@@ -14,7 +20,7 @@
        Reject sizes of exactly SIZE_MAX bytes.
        * xreadlink.c: Include "xalloc.h" before checking whether SIZE_MAX
        is defined, since "xalloc.h" now defines SIZE_MAX on modern hosts.
        Reject sizes of exactly SIZE_MAX bytes.
        * xreadlink.c: Include "xalloc.h" before checking whether SIZE_MAX
        is defined, since "xalloc.h" now defines SIZE_MAX on modern hosts.
-       
+
 2003-11-05  Bruno Haible  <bruno@clisp.org>
 
        * xsize.h: Include limits.h, to avoid a possible collision with
 2003-11-05  Bruno Haible  <bruno@clisp.org>
 
        * xsize.h: Include limits.h, to avoid a possible collision with
index 571e53c..8faf316 100644 (file)
 #ifndef XALLOC_H_
 # define XALLOC_H_
 
 #ifndef XALLOC_H_
 # define XALLOC_H_
 
+/* Get size_t.  */
 # include <stddef.h>
 # include <stddef.h>
+
+/* Get SIZE_MAX, PTRDIFF_MAX.  */
+# include <limits.h>
 # if HAVE_STDINT_H
 #  include <stdint.h>
 # endif
 # if HAVE_STDINT_H
 #  include <stdint.h>
 # endif
@@ -74,10 +78,10 @@ char *xstrdup (const char *str);
    PTRDIFF_MAX < SIZE_MAX, 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.  */
    PTRDIFF_MAX < SIZE_MAX, 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 defined PTRDIFF_MAX && PTRDIFF_MAX < SIZE_MAX
+# if PTRDIFF_MAX < SIZE_MAX
 #  define xalloc_oversized(n, s) (SIZE_MAX / (s) < (n))
 #  define xalloc_oversized(n, s) (SIZE_MAX / (s) < (n))
-# else /* SIZE_MAX might not be defined, so avoid (SIZE_MAX - 1).  */
-#  define xalloc_oversized(n, s) ((size_t) -2 / (s) < (n))
+# else
+#  define xalloc_oversized(n, s) ((SIZE_MAX - 1) / (s) < (n))
 # endif
 
 /* These macros are deprecated; they will go away soon, and are retained
 # endif
 
 /* These macros are deprecated; they will go away soon, and are retained
index 34919f8..42aa68a 100644 (file)
@@ -27,9 +27,6 @@
 #if HAVE_STDINT_H
 # include <stdint.h>
 #endif
 #if HAVE_STDINT_H
 # include <stdint.h>
 #endif
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
 
 /* The size of memory objects is often computed through expressions of
    type size_t. Example:
 
 /* The size of memory objects is often computed through expressions of
    type size_t. Example:
index 950443e..418503b 100644 (file)
@@ -1,3 +1,11 @@
+2003-11-11  Bruno Haible  <bruno@clisp.org>
+
+       * size_max.m4: New file.
+       * ptrdiff_max.m4: New file.
+       * xsize,m4 (gl_XSIZE): Require gl_SIZE_MAX.
+       * xalloc.m4 (gl_PREREQ_XALLOC): New file.
+       (gl_XALLOC): Invoke it.
+
 2003-11-04  Bruno Haible  <bruno@clisp.org>
 
        * xsize.m4: New file.
 2003-11-04  Bruno Haible  <bruno@clisp.org>
 
        * xsize.m4: New file.
index 0c14045..07efb2f 100644 (file)
@@ -1,4 +1,4 @@
-# xalloc.m4 serial 6
+# xalloc.m4 serial 7
 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
 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
@@ -8,10 +8,18 @@ dnl the same distribution terms as the rest of that program.
 
 AC_DEFUN([gl_XALLOC],
 [
 
 AC_DEFUN([gl_XALLOC],
 [
+  gl_PREREQ_XALLOC
   gl_PREREQ_XMALLOC
   gl_PREREQ_XSTRDUP
 ])
 
   gl_PREREQ_XMALLOC
   gl_PREREQ_XSTRDUP
 ])
 
+# Prerequisites of lib/xalloc.h.
+AC_DEFUN([gl_PREREQ_XALLOC], [
+  AC_REQUIRE([gl_SIZE_MAX])
+  AC_REQUIRE([gl_PTRDIFF_MAX])
+  :
+])
+
 # Prerequisites of lib/xmalloc.c.
 AC_DEFUN([gl_PREREQ_XMALLOC], [
   AC_REQUIRE([AC_C_INLINE])
 # Prerequisites of lib/xmalloc.c.
 AC_DEFUN([gl_PREREQ_XMALLOC], [
   AC_REQUIRE([AC_C_INLINE])
index ee30a4d..9b7cf9b 100644 (file)
@@ -1,4 +1,4 @@
-# xsize.m4 serial 1
+# xsize.m4 serial 2
 dnl Copyright (C) 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
 dnl Copyright (C) 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
@@ -9,5 +9,6 @@ dnl the same distribution terms as the rest of that program.
 AC_DEFUN([gl_XSIZE],
 [
   dnl Prerequisites of lib/xsize.h.
 AC_DEFUN([gl_XSIZE],
 [
   dnl Prerequisites of lib/xsize.h.
+  AC_REQUIRE([gl_SIZE_MAX])
   AC_CHECK_HEADERS(stdint.h)
 ])
   AC_CHECK_HEADERS(stdint.h)
 ])
index 46482cc..2e7b89b 100644 (file)
@@ -6,6 +6,8 @@ lib/xalloc.h
 lib/xmalloc.c
 lib/xstrdup.c
 m4/xalloc.m4
 lib/xmalloc.c
 lib/xstrdup.c
 m4/xalloc.m4
+m4/size_max.m4
+m4/ptrdiff_max.m4
 
 Depends-on:
 malloc
 
 Depends-on:
 malloc
index f4d1597..9acf916 100644 (file)
@@ -4,6 +4,7 @@ Checked size_t computations.
 Files:
 lib/xsize.h
 m4/xsize.m4
 Files:
 lib/xsize.h
 m4/xsize.m4
+m4/size_max.m4
 
 Depends-on:
 
 
 Depends-on: