From 8224e3007771aa0ef666eb1ff1d2564208cc2c91 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 11 Nov 2003 11:58:42 +0000 Subject: [PATCH] Rely on SIZE_MAX and PTRDIFF_MAX as defined by ISO C 99. --- ChangeLog | 5 +++++ lib/ChangeLog | 8 +++++++- lib/xalloc.h | 10 +++++++--- lib/xsize.h | 3 --- m4/ChangeLog | 8 ++++++++ m4/xalloc.m4 | 10 +++++++++- m4/xsize.m4 | 3 ++- modules/xalloc | 2 ++ modules/xsize | 1 + 9 files changed, 41 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e435554c5..37219b077 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-11-11 Bruno Haible + + * 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 * modules/xsize: New file. diff --git a/lib/ChangeLog b/lib/ChangeLog index 0791de9e7..6163b5d5d 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2003-11-11 Bruno Haible + + * 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 * 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. - + 2003-11-05 Bruno Haible * xsize.h: Include limits.h, to avoid a possible collision with diff --git a/lib/xalloc.h b/lib/xalloc.h index 571e53c04..8faf31601 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -20,7 +20,11 @@ #ifndef XALLOC_H_ # define XALLOC_H_ +/* Get size_t. */ # include + +/* Get SIZE_MAX, PTRDIFF_MAX. */ +# include # if HAVE_STDINT_H # include # 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. */ -# if defined PTRDIFF_MAX && PTRDIFF_MAX < SIZE_MAX +# if PTRDIFF_MAX < SIZE_MAX # 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 diff --git a/lib/xsize.h b/lib/xsize.h index 34919f8b7..42aa68a2a 100644 --- a/lib/xsize.h +++ b/lib/xsize.h @@ -27,9 +27,6 @@ #if HAVE_STDINT_H # include #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: diff --git a/m4/ChangeLog b/m4/ChangeLog index 950443ed5..418503bd0 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,11 @@ +2003-11-11 Bruno Haible + + * 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 * xsize.m4: New file. diff --git a/m4/xalloc.m4 b/m4/xalloc.m4 index 0c14045ba..07efb2f7f 100644 --- a/m4/xalloc.m4 +++ b/m4/xalloc.m4 @@ -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 @@ -8,10 +8,18 @@ dnl the same distribution terms as the rest of that program. AC_DEFUN([gl_XALLOC], [ + gl_PREREQ_XALLOC 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]) diff --git a/m4/xsize.m4 b/m4/xsize.m4 index ee30a4d45..9b7cf9b49 100644 --- a/m4/xsize.m4 +++ b/m4/xsize.m4 @@ -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 @@ -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_REQUIRE([gl_SIZE_MAX]) AC_CHECK_HEADERS(stdint.h) ]) diff --git a/modules/xalloc b/modules/xalloc index 46482cc88..2e7b89bba 100644 --- a/modules/xalloc +++ b/modules/xalloc @@ -6,6 +6,8 @@ lib/xalloc.h lib/xmalloc.c lib/xstrdup.c m4/xalloc.m4 +m4/size_max.m4 +m4/ptrdiff_max.m4 Depends-on: malloc diff --git a/modules/xsize b/modules/xsize index f4d159701..9acf916fa 100644 --- a/modules/xsize +++ b/modules/xsize @@ -4,6 +4,7 @@ Checked size_t computations. Files: lib/xsize.h m4/xsize.m4 +m4/size_max.m4 Depends-on: -- 2.11.0