Commit 7ec98caf authored by Paul Eggert's avatar Paul Eggert

Update from gnulib.

parent 70476b54
2011-04-08 Paul Eggert <eggert@cs.ucla.edu>
* lib/allocator.c: New file, automatically generated by gnulib.
2011-04-06 Eli Zaretskii <eliz@gnu.org>
* lib/makefile.w32-in ($(BLD)/careadlinkat.$(O), GNULIBOBJS):
......
#define _GL_USE_STDLIB_ALLOC 1
#include <config.h>
#include "allocator.h"
#include <stdlib.h>
struct allocator const stdlib_allocator = { malloc, realloc, free, NULL };
......@@ -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
......@@ -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);
......
......@@ -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
......
......@@ -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 - "
......
......@@ -26,6 +26,7 @@ AC_DEFUN([gl_EARLY],
m4_pattern_allow([^gl_LIBOBJS$])dnl a variable
m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable
AC_REQUIRE([AC_PROG_RANLIB])
# Code from module allocator:
# Code from module arg-nonnull:
# Code from module c++defs:
# Code from module careadlinkat:
......@@ -79,6 +80,7 @@ AC_DEFUN([gl_INIT],
m4_pushdef([gl_LIBSOURCES_DIR], [])
gl_COMMON
gl_source_base='lib'
# Code from module allocator:
# Code from module arg-nonnull:
# Code from module c++defs:
# Code from module careadlinkat:
......@@ -293,6 +295,7 @@ AC_DEFUN([gl_FILE_LIST], [
build-aux/arg-nonnull.h
build-aux/c++defs.h
build-aux/warn-on-use.h
lib/allocator.c
lib/allocator.h
lib/careadlinkat.c
lib/careadlinkat.h
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment