[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
shishi/gl Makefile.am alloca.c getndelim2.c lin...
From: |
shishi-commit |
Subject: |
shishi/gl Makefile.am alloca.c getndelim2.c lin... |
Date: |
Sat, 22 Nov 2003 02:10:07 -0500 |
CVSROOT: /cvsroot/shishi
Module name: shishi
Branch:
Changes by: Simon Josefsson <address@hidden> 03/11/22 02:10:04
Modified files:
gl : Makefile.am alloca.c getndelim2.c linebuffer.c
stdbool_.h vasnprintf.c vasprintf.c xalloc.h
xmalloc.c
gl/m4 : getline.m4 getndelim2.m4 xalloc.m4
Log message:
Update.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/Makefile.am.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/alloca.c.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/getndelim2.c.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/linebuffer.c.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/stdbool_.h.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/vasnprintf.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/vasprintf.c.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/xalloc.h.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/xmalloc.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/m4/getline.m4.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/m4/getndelim2.m4.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/gl/m4/xalloc.m4.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: shishi/gl/Makefile.am
diff -u shishi/gl/Makefile.am:1.23 shishi/gl/Makefile.am:1.24
--- shishi/gl/Makefile.am:1.23 Thu Oct 16 06:51:00 2003
+++ shishi/gl/Makefile.am Sat Nov 22 02:10:04 2003
@@ -98,7 +98,7 @@
# We need the following in order to create a <sysexits.h> when the system
# doesn't have one that works with the given compiler.
-all-local $(libfoo_la_OBJECTS): @SYSEXITS_H@
+all-local $(libfoo_la_OBJECTS): $(SYSEXITS_H)
sysexits.h: sysexit_.h
cp $(srcdir)/sysexit_.h sysexits.h-t
mv sysexits.h-t sysexits.h
Index: shishi/gl/alloca.c
diff -u shishi/gl/alloca.c:1.3 shishi/gl/alloca.c:1.4
--- shishi/gl/alloca.c:1.3 Tue Sep 9 05:00:49 2003
+++ shishi/gl/alloca.c Sat Nov 22 02:10:04 2003
@@ -204,9 +204,6 @@
new = xmalloc (combined_size);
- if (new == 0)
- abort();
-
((header *) new)->h.next = last_alloca_header;
((header *) new)->h.deep = depth;
Index: shishi/gl/getndelim2.c
diff -u shishi/gl/getndelim2.c:1.1 shishi/gl/getndelim2.c:1.2
--- shishi/gl/getndelim2.c:1.1 Thu Oct 16 06:53:29 2003
+++ shishi/gl/getndelim2.c Sat Nov 22 02:10:04 2003
@@ -81,18 +81,15 @@
size_t newlinesize =
(*linesize > MIN_CHUNK ? 2 * *linesize : *linesize + MIN_CHUNK);
- if (newlinesize > nmax)
+ if (! (*linesize < newlinesize && newlinesize <= nmax))
newlinesize = nmax;
- if (newlinesize > *linesize)
- {
- *linesize = newlinesize;
- nbytes_avail = *linesize + *lineptr - read_pos;
- *lineptr = realloc (*lineptr, *linesize);
- if (!*lineptr)
- return -1;
- read_pos = *linesize - nbytes_avail + *lineptr;
- }
+ *linesize = newlinesize;
+ nbytes_avail = *linesize + *lineptr - read_pos;
+ *lineptr = realloc (*lineptr, *linesize);
+ if (!*lineptr)
+ return -1;
+ read_pos = *linesize - nbytes_avail + *lineptr;
}
c = getc (stream);
Index: shishi/gl/linebuffer.c
diff -u shishi/gl/linebuffer.c:1.3 shishi/gl/linebuffer.c:1.4
--- shishi/gl/linebuffer.c:1.3 Thu Oct 16 06:53:29 2003
+++ shishi/gl/linebuffer.c Sat Nov 22 02:10:04 2003
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/types.h>
#include "linebuffer.h"
#include "unlocked-io.h"
@@ -35,9 +36,7 @@
void
initbuffer (struct linebuffer *linebuffer)
{
- linebuffer->length = 0;
- linebuffer->size = 200;
- linebuffer->buffer = xmalloc (linebuffer->size);
+ memset (linebuffer, 0, sizeof *linebuffer);
}
/* Read an arbitrarily long line of text from STREAM into LINEBUFFER.
@@ -73,9 +72,9 @@
}
if (p == end)
{
- linebuffer->size *= 2;
- buffer = xrealloc (buffer, linebuffer->size);
- p = p - linebuffer->buffer + buffer;
+ size_t oldsize = linebuffer->size;
+ buffer = x2realloc (buffer, &linebuffer->size);
+ p = buffer + oldsize;
linebuffer->buffer = buffer;
end = buffer + linebuffer->size;
}
Index: shishi/gl/m4/getline.m4
diff -u shishi/gl/m4/getline.m4:1.1 shishi/gl/m4/getline.m4:1.2
--- shishi/gl/m4/getline.m4:1.1 Thu Oct 16 06:49:11 2003
+++ shishi/gl/m4/getline.m4 Sat Nov 22 02:10:04 2003
@@ -1,4 +1,4 @@
-# getline.m4 serial 9
+# getline.m4 serial 10
dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software
dnl Foundation, Inc.
@@ -56,7 +56,14 @@
AC_DEFINE([getline], [gnu_getline],
[Define to a replacement function name for getline().])
AC_LIBOBJ(getline)
- AC_LIBOBJ(getndelim2)
+
+ # Avoid multiple inclusions of getndelim2.o into LIBOBJS.
+ # This hack won't be needed after gnulib requires Autoconf 2.58 or later.
+ case " $LIB@&address@hidden " in
+ *" getndelim2.$ac_objext "* ) ;;
+ *) AC_LIBOBJ(getndelim2);;
+ esac
+
gl_PREREQ_GETLINE
gl_PREREQ_GETNDELIM2
fi
Index: shishi/gl/m4/getndelim2.m4
diff -u shishi/gl/m4/getndelim2.m4:1.1 shishi/gl/m4/getndelim2.m4:1.2
--- shishi/gl/m4/getndelim2.m4:1.1 Thu Oct 16 06:49:11 2003
+++ shishi/gl/m4/getndelim2.m4 Sat Nov 22 02:10:04 2003
@@ -1,4 +1,4 @@
-# getndelim2.m4 serial 2
+# getndelim2.m4 serial 3
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
@@ -8,7 +8,13 @@
AC_DEFUN([gl_GETNDELIM2],
[
- AC_LIBOBJ(getndelim2)
+ # Avoid multiple inclusions of getndelim2.o into LIBOBJS.
+ # This hack won't be needed after gnulib requires Autoconf 2.58 or later.
+ case " $LIB@&address@hidden " in
+ *" getndelim2.$ac_objext "* ) ;;
+ *) AC_LIBOBJ(getndelim2);;
+ esac
+
gl_PREREQ_GETNDELIM2
])
Index: shishi/gl/m4/xalloc.m4
diff -u shishi/gl/m4/xalloc.m4:1.4 shishi/gl/m4/xalloc.m4:1.5
--- shishi/gl/m4/xalloc.m4:1.4 Thu Oct 16 06:49:11 2003
+++ shishi/gl/m4/xalloc.m4 Sat Nov 22 02:10:04 2003
@@ -1,4 +1,4 @@
-# xalloc.m4 serial 4
+# 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
@@ -8,8 +8,14 @@
AC_DEFUN([gl_XALLOC],
[
+ gl_PREREQ_XALLOC
gl_PREREQ_XMALLOC
gl_PREREQ_XSTRDUP
+])
+
+# Prerequisites of lib/xalloc.h.
+AC_DEFUN([gl_PREREQ_XALLOC], [
+ :
])
# Prerequisites of lib/xmalloc.c.
Index: shishi/gl/stdbool_.h
diff -u shishi/gl/stdbool_.h:1.1 shishi/gl/stdbool_.h:1.2
--- shishi/gl/stdbool_.h:1.1 Thu Oct 16 06:53:29 2003
+++ shishi/gl/stdbool_.h Sat Nov 22 02:10:04 2003
@@ -56,6 +56,7 @@
/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
definitions below, but temporarily we have to #undef them. */
#ifdef __BEOS__
+# include <OS.h> /* defines bool but not _Bool */
# undef false
# undef true
#endif
@@ -69,7 +70,7 @@
(see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
(see ISO C 99 6.3.1.1.(2)). So we add a negative value to the
enum; this ensures that '_Bool' promotes to 'int'. */
-#ifndef __cplusplus
+#if !(defined __cplusplus || defined __BEOS__)
# if address@hidden@
# if defined __SUNPRO_C && (__SUNPRO_C < 0x550 || __STDC__ == 1)
/* Avoid stupid "warning: _Bool is a keyword in ISO C99". */
Index: shishi/gl/vasnprintf.c
diff -u shishi/gl/vasnprintf.c:1.4 shishi/gl/vasnprintf.c:1.5
--- shishi/gl/vasnprintf.c:1.4 Sun Sep 14 17:10:11 2003
+++ shishi/gl/vasnprintf.c Sat Nov 22 02:10:04 2003
@@ -707,7 +707,23 @@
p[1] = '\0';
continue;
}
- count = retcount;
+ else
+ {
+ /* Look at the snprintf() return value. */
+ if (retcount < 0)
+ {
+ /* HP-UX 10.20 snprintf() is doubly deficient:
+ It doesn't understand the '%n' directive,
+ *and* it returns -1 (rather than the length
+ that would have been required) when the
+ buffer is too small. */
+ size_t bigger_need = 2 * allocated + 12;
+ ENSURE_ALLOCATION (bigger_need);
+ continue;
+ }
+ else
+ count = retcount;
+ }
}
#endif
Index: shishi/gl/vasprintf.c
diff -u shishi/gl/vasprintf.c:1.2 shishi/gl/vasprintf.c:1.3
--- shishi/gl/vasprintf.c:1.2 Fri Aug 22 13:48:49 2003
+++ shishi/gl/vasprintf.c Sat Nov 22 02:10:04 2003
@@ -1,5 +1,5 @@
/* Formatted output to strings.
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,6 +22,9 @@
/* Specification. */
#include "vasprintf.h"
+#include <limits.h>
+#include <stdlib.h>
+
#include "vasnprintf.h"
int
@@ -31,6 +34,14 @@
char *result = vasnprintf (NULL, &length, format, args);
if (result == NULL)
return -1;
+ if (length > INT_MAX)
+ {
+ /* We could produce such a big string, but can't return its length
+ as an 'int'. */
+ free (result);
+ return -1;
+ }
+
*resultp = result;
/* Return the number of resulting bytes, excluding the trailing NUL. */
return length;
Index: shishi/gl/xalloc.h
diff -u shishi/gl/xalloc.h:1.4 shishi/gl/xalloc.h:1.5
--- shishi/gl/xalloc.h:1.4 Thu Oct 16 06:53:29 2003
+++ shishi/gl/xalloc.h Sat Nov 22 02:10:04 2003
@@ -54,8 +54,25 @@
void *xcalloc (size_t n, size_t s);
void *xrealloc (void *p, size_t s);
void *xnrealloc (void *p, size_t n, size_t s);
+void *x2realloc (void *p, size_t *pn);
+void *x2nrealloc (void *p, size_t *pn, size_t s);
void *xclone (void const *p, size_t s);
char *xstrdup (const char *str);
+
+/* Return 1 if an array of N objects, each of size S, cannot exist due
+ to size arithmetic overflow. S must be positive and N must be
+ nonnegative. This is a macro, not an inline function, so that it
+ works correctly even when SIZE_MAX < N.
+
+ By gnulib convention, SIZE_MAX represents overflow in size
+ 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
+ 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. */
+# 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: shishi/gl/xmalloc.c
diff -u shishi/gl/xmalloc.c:1.4 shishi/gl/xmalloc.c:1.5
--- shishi/gl/xmalloc.c:1.4 Thu Oct 16 06:53:29 2003
+++ shishi/gl/xmalloc.c Sat Nov 22 02:10:04 2003
@@ -23,7 +23,6 @@
#include "xalloc.h"
-#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -49,15 +48,6 @@
/* If non NULL, call this function when memory is exhausted. */
void (*xalloc_fail_func) (void) = 0;
-/* Return true if array of N objects, each of size S, cannot exist due
- to arithmetic overflow. S must be nonzero. */
-
-static inline bool
-array_size_overflow (size_t n, size_t s)
-{
- return SIZE_MAX / s < n;
-}
-
/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
before exiting when memory is exhausted. Goes through gettext. */
char const xalloc_msg_memory_exhausted[] = N_("memory exhausted");
@@ -77,41 +67,157 @@
/* Allocate an array of N objects, each with S bytes of memory,
dynamically, with error checking. S must be nonzero. */
-inline void *
-xnmalloc (size_t n, size_t s)
+static inline void *
+xnmalloc_inline (size_t n, size_t s)
{
void *p;
- if (array_size_overflow (n, s) || ! (p = malloc (n * s)))
+ if (xalloc_oversized (n, s) || ! (p = malloc (n * s)))
xalloc_die ();
return p;
}
+void *
+xnmalloc (size_t n, size_t s)
+{
+ return xnmalloc_inline (n, s);
+}
+
/* Allocate N bytes of memory dynamically, with error checking. */
void *
xmalloc (size_t n)
{
- return xnmalloc (n, 1);
+ return xnmalloc_inline (n, 1);
}
/* Change the size of an allocated block of memory P to an array of N
objects each of S bytes, with error checking. S must be nonzero. */
-inline void *
-xnrealloc (void *p, size_t n, size_t s)
+static inline void *
+xnrealloc_inline (void *p, size_t n, size_t s)
{
- if (array_size_overflow (n, s) || ! (p = realloc (p, n * s)))
+ if (xalloc_oversized (n, s) || ! (p = realloc (p, n * s)))
xalloc_die ();
return p;
}
+void *
+xnrealloc (void *p, size_t n, size_t s)
+{
+ return xnrealloc_inline (p, n, s);
+}
+
/* Change the size of an allocated block of memory P to N bytes,
with error checking. */
void *
xrealloc (void *p, size_t n)
{
- return xnrealloc (p, n, 1);
+ return xnrealloc_inline (p, n, 1);
+}
+
+
+/* If P is null, allocate a block of at least *PN such objects;
+ otherwise, reallocate P so that it contains more than *PN objects
+ each of S bytes. *PN must be nonzero unless P is null, and S must
+ be nonzero. Set *PN to the new number of objects, and return the
+ pointer to the new block. *PN is never set to zero, and the
+ returned pointer is never null.
+
+ Repeated reallocations are guaranteed to make progress, either by
+ allocating an initial block with a nonzero size, or by allocating a
+ larger block.
+
+ In the following implementation, nonzero sizes are doubled so that
+ repeated reallocations have O(N log N) overall cost rather than
+ O(N**2) cost, but the specification for this function does not
+ guarantee that sizes are doubled.
+
+ Here is an example of use:
+
+ int *p = NULL;
+ size used = 0;
+ size allocated = 0;
+
+ void
+ append_int (int value)
+ {
+ if (used == allocated)
+ p = x2nrealloc (p, &allocated, sizeof *p);
+ p[used++] = value;
+ }
+
+ This causes x2nrealloc to allocate a block of some nonzero size the
+ first time it is called.
+
+ To have finer-grained control over the initial size, set *PN to a
+ nonzero value before calling this function with P == NULL. For
+ example:
+
+ int *p = NULL;
+ size used = 0;
+ size allocated = 0;
+ size allocated1 = 1000;
+
+ void
+ append_int (int value)
+ {
+ if (used == allocated)
+ {
+ p = x2nrealloc (p, &allocated1, sizeof *p);
+ allocated = allocated1;
+ }
+ p[used++] = value;
+ }
+
+ */
+
+static inline void *
+x2nrealloc_inline (void *p, size_t *pn, size_t s)
+{
+ size_t n = *pn;
+
+ if (! p)
+ {
+ if (! n)
+ {
+ /* The approximate size to use for initial small allocation
+ requests, when the invoking code specifies an old size of
+ zero. 64 bytes is the largest "small" request for the
+ GNU C library malloc. */
+ enum { DEFAULT_MXFAST = 64 };
+
+ n = DEFAULT_MXFAST / s;
+ n += !n;
+ }
+ }
+ else
+ {
+ if (SIZE_MAX / 2 / s < n)
+ xalloc_die ();
+ n *= 2;
+ }
+
+ *pn = n;
+ return xrealloc (p, n * s);
+}
+
+void *
+x2nrealloc (void *p, size_t *pn, size_t s)
+{
+ return x2nrealloc_inline (p, pn, s);
+}
+
+/* If P is null, allocate a block of at least *PN bytes; otherwise,
+ reallocate P so that it contains more than *PN bytes. *PN must be
+ nonzero unless P is null. Set *PN to the new block's size, and
+ return the pointer to the new block. *PN is never set to zero, and
+ the returned pointer is never null. */
+
+void *
+x2realloc (void *p, size_t *pn)
+{
+ return x2nrealloc_inline (p, pn, 1);
}
/* Allocate S bytes of zeroed memory dynamically, with error checking.
@@ -133,7 +239,7 @@
void *p;
/* Test for overflow, since some calloc implementations don't have
proper overflow checks. */
- if (array_size_overflow (n, s) || ! (p = calloc (n, s)))
+ if (xalloc_oversized (n, s) || ! (p = calloc (n, s)))
xalloc_die ();
return p;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- shishi/gl Makefile.am alloca.c getndelim2.c lin...,
shishi-commit <=