]> code.delx.au - gnu-emacs/commitdiff
Update from gnulib.
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 8 Apr 2011 21:53:30 +0000 (14:53 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 8 Apr 2011 21:53:30 +0000 (14:53 -0700)
ChangeLog
lib/allocator.c [new file with mode: 0644]
lib/allocator.h
lib/careadlinkat.c
lib/gnulib.mk
lib/stdlib.in.h
m4/gl-comp.m4

index b7f8f77dd3489da19f942c68603a2a4c8d1ef105..ea5b106a8951abaab983a45deedc5fc5cd52cd5d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+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):
diff --git a/lib/allocator.c b/lib/allocator.c
new file mode 100644 (file)
index 0000000..2c1a3da
--- /dev/null
@@ -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 };
index 4ac863b224cac91a35fe1f7ad1525c2ebf6515cd..a89ba32b09b1eda6c4d933a087bd327351bdfa73 100644 (file)
@@ -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
index 15ffe24c0f4cb6fb763e16b08c6fec346cf6dff6..7a7806d121c60cbd731ebe9842660f5f6fa741db 100644 (file)
 
 #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);
 
index d2fd6698030fc30c941422c82f981fca6d9763e1..1938c6127a2ae822d8cf7a60421e6c41c5064c07 100644 (file)
@@ -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
 
index 2697a4bd1dbd3687f270eb33210bd164958f3916..b9ada2cd1a879416e5cea84a3c937b1b78ccb585 100644 (file)
@@ -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 - "
index 43cce9b367606408a4eff65560c708f65af639d3..3ca40ee39bd1883fc428ec6fbb8155cef8b98c22 100644 (file)
@@ -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