Mercurial > hg > octave-kai > gnulib-hg
changeset 4862:1f6c3678919c
Rely on SIZE_MAX and PTRDIFF_MAX as defined by ISO C 99.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 11 Nov 2003 11:58:42 +0000 |
parents | 1d3dc83fb7a5 |
children | 0076fd7ab6ab |
files | ChangeLog lib/ChangeLog lib/xalloc.h lib/xsize.h m4/ChangeLog m4/xalloc.m4 m4/xsize.m4 modules/xalloc modules/xsize |
diffstat | 9 files changed, 41 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -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 && @@ -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 <bruno@clisp.org> * xsize.h: Include limits.h, to avoid a possible collision with
--- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -20,7 +20,11 @@ #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 @@ -74,10 +78,10 @@ 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
--- a/lib/xsize.h +++ b/lib/xsize.h @@ -27,9 +27,6 @@ #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:
--- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -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.
--- 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 @@ 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])
--- 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 @@ AC_DEFUN([gl_XSIZE], [ dnl Prerequisites of lib/xsize.h. + AC_REQUIRE([gl_SIZE_MAX]) AC_CHECK_HEADERS(stdint.h) ])