summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-04-08 14:53:30 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-04-08 14:53:30 -0700
commitf83a1a4d77cfb8fd00c84b1d34df09f9602f0534 (patch)
treea0342be9a31d2cd9c632b5f2132548f31e8c1c35 /lib
parent4c504bf8cd6e894ff2f776418f4f105947bd1c05 (diff)
downloademacs-f83a1a4d77cfb8fd00c84b1d34df09f9602f0534.tar.gz
Update from gnulib.
Diffstat (limited to 'lib')
-rw-r--r--lib/allocator.c5
-rw-r--r--lib/allocator.h13
-rw-r--r--lib/careadlinkat.c21
-rw-r--r--lib/gnulib.mk10
-rw-r--r--lib/stdlib.in.h14
5 files changed, 37 insertions, 26 deletions
diff --git a/lib/allocator.c b/lib/allocator.c
new file mode 100644
index 00000000000..2c1a3da03aa
--- /dev/null
+++ b/lib/allocator.c
@@ -0,0 +1,5 @@
+#define _GL_USE_STDLIB_ALLOC 1
+#include <config.h>
+#include "allocator.h"
+#include <stdlib.h>
+struct allocator const stdlib_allocator = { malloc, realloc, free, NULL };
diff --git a/lib/allocator.h b/lib/allocator.h
index 4ac863b224c..a89ba32b09b 100644
--- a/lib/allocator.h
+++ b/lib/allocator.h
@@ -30,16 +30,16 @@ struct allocator
attributes do not work with pointers to functions. See
<http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00007.html>. */
- /* Call MALLOC to allocate memory, like 'malloc'. On failure MALLOC
+ /* Call ALLOCATE to allocate memory, like 'malloc'. On failure ALLOCATE
should return NULL, though not necessarily set errno. When given
a zero size it may return NULL even if successful. */
- void *(*malloc) (size_t);
+ void *(*allocate) (size_t);
- /* If nonnull, call REALLOC to reallocate memory, like 'realloc'.
- On failure REALLOC should return NULL, though not necessarily set
+ /* If nonnull, call REALLOCATE to reallocate memory, like 'realloc'.
+ On failure REALLOCATE should return NULL, though not necessarily set
errno. When given a zero size it may return NULL even if
successful. */
- void *(*realloc) (void *, size_t);
+ void *(*reallocate) (void *, size_t);
/* Call FREE to free memory, like 'free'. */
void (*free) (void *);
@@ -50,4 +50,7 @@ struct allocator
void (*die) (void);
};
+/* An allocator using the stdlib functions and a null DIE function. */
+extern struct allocator const stdlib_allocator;
+
#endif
diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c
index 15ffe24c0f4..7a7806d121c 100644
--- a/lib/careadlinkat.c
+++ b/lib/careadlinkat.c
@@ -26,15 +26,9 @@
#include <errno.h>
#include <limits.h>
-#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-/* Use the system functions, not the gnulib overrides, because this
- module does not depend on GNU or POSIX semantics. */
-#undef malloc
-#undef realloc
-
/* Define this independently so that stdint.h is not a prerequisite. */
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
@@ -57,11 +51,6 @@ careadlinkatcwd (int fd, char const *filename, char *buffer,
}
#endif
-/* A standard allocator. For now, only careadlinkat needs this, but
- perhaps it should be moved to the allocator module. */
-static struct allocator const standard_allocator =
- { malloc, realloc, free, NULL };
-
/* Assuming the current directory is FD, get the symbolic link value
of FILENAME as a null-terminated string and put it into a buffer.
If FD is AT_FDCWD, FILENAME is interpreted relative to the current
@@ -94,7 +83,7 @@ careadlinkat (int fd, char const *filename,
char stack_buf[1024];
if (! alloc)
- alloc = &standard_allocator;
+ alloc = &stdlib_allocator;
if (! buffer_size)
{
@@ -138,16 +127,16 @@ careadlinkat (int fd, char const *filename,
if (buf == stack_buf)
{
- char *b = (char *) alloc->malloc (link_size);
+ char *b = (char *) alloc->allocate (link_size);
if (! b)
break;
memcpy (b, buf, link_size);
buf = b;
}
- else if (link_size < buf_size && buf != buffer && alloc->realloc)
+ else if (link_size < buf_size && buf != buffer && alloc->reallocate)
{
/* Shrink BUF before returning it. */
- char *b = (char *) alloc->realloc (buf, link_size);
+ char *b = (char *) alloc->reallocate (buf, link_size);
if (b)
buf = b;
}
@@ -164,7 +153,7 @@ careadlinkat (int fd, char const *filename,
buf_size = buf_size_max;
else
break;
- buf = (char *) alloc->malloc (buf_size);
+ buf = (char *) alloc->allocate (buf_size);
}
while (buf);
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index d2fd6698030..1938c6127a2 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -21,6 +21,14 @@ libgnu_a_LIBADD = $(gl_LIBOBJS)
libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
EXTRA_libgnu_a_SOURCES =
+## begin gnulib module allocator
+
+libgnu_a_SOURCES += allocator.c
+
+EXTRA_DIST += allocator.h
+
+## end gnulib module allocator
+
## begin gnulib module arg-nonnull
# The BUILT_SOURCES created by this Makefile snippet are not used via #include
@@ -73,7 +81,7 @@ EXTRA_DIST += $(top_srcdir)/./c++defs.h
libgnu_a_SOURCES += careadlinkat.c
-EXTRA_DIST += allocator.h careadlinkat.h
+EXTRA_DIST += careadlinkat.h
## end gnulib module careadlinkat
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 2697a4bd1db..b9ada2cd1a8 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -255,9 +255,14 @@ _GL_WARN_ON_USE (ptsname, "grantpt is not portable - "
# endif
#endif
+/* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not
+ rely on GNU or POSIX semantics for malloc and realloc (for example,
+ by never specifying a zero size), so it does not need malloc or
+ realloc to be redefined. */
#if @GNULIB_MALLOC_POSIX@
# if @REPLACE_MALLOC@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
+ || _GL_USE_STDLIB_ALLOC)
# undef malloc
# define malloc rpl_malloc
# endif
@@ -267,7 +272,7 @@ _GL_CXXALIAS_RPL (malloc, void *, (size_t size));
_GL_CXXALIAS_SYS (malloc, void *, (size_t size));
# endif
_GL_CXXALIASWARN (malloc);
-#elif defined GNULIB_POSIXCHECK
+#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
# undef malloc
/* Assume malloc is always declared. */
_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
@@ -531,7 +536,8 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
#if @GNULIB_REALLOC_POSIX@
# if @REPLACE_REALLOC@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
+ || _GL_USE_STDLIB_ALLOC)
# undef realloc
# define realloc rpl_realloc
# endif
@@ -541,7 +547,7 @@ _GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size));
_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
# endif
_GL_CXXALIASWARN (realloc);
-#elif defined GNULIB_POSIXCHECK
+#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
# undef realloc
/* Assume realloc is always declared. */
_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "