summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/ChangeLog8
-rw-r--r--lib/xalloc.h10
-rw-r--r--lib/xsize.h3
-rw-r--r--m4/ChangeLog8
-rw-r--r--m4/xalloc.m410
-rw-r--r--m4/xsize.m43
-rw-r--r--modules/xalloc2
-rw-r--r--modules/xsize1
9 files changed, 41 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index e435554c59..37219b077e 100644
--- 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.
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 0791de9e71..6163b5d5d0 100644
--- 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
diff --git a/lib/xalloc.h b/lib/xalloc.h
index 571e53c048..8faf316013 100644
--- 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 @@ 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 34919f8b7c..42aa68a2a9 100644
--- 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:
diff --git a/m4/ChangeLog b/m4/ChangeLog
index 950443ed52..418503bd0c 100644
--- 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.
diff --git a/m4/xalloc.m4 b/m4/xalloc.m4
index 0c14045ba4..07efb2f7f7 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 ee30a4d458..9b7cf9b493 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 46482cc88e..2e7b89bba2 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 f4d1597015..9acf916fa0 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: