aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2011-04-08 14:53:30 -0700
committerPaul Eggert2011-04-08 14:53:30 -0700
commit7ec98caf7757bbf462d91a5cebd440cf12cc5816 (patch)
treea06f12700c55c0a932163ff80c6c3d01883a9c36 /lib
parent70476b54414db1be5261c71073fc991eab5cd34a (diff)
downloademacs-7ec98caf7757bbf462d91a5cebd440cf12cc5816.tar.gz
emacs-7ec98caf7757bbf462d91a5cebd440cf12cc5816.zip
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 @@
1#define _GL_USE_STDLIB_ALLOC 1
2#include <config.h>
3#include "allocator.h"
4#include <stdlib.h>
5struct 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
30 attributes do not work with pointers to functions. See 30 attributes do not work with pointers to functions. See
31 <http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00007.html>. */ 31 <http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00007.html>. */
32 32
33 /* Call MALLOC to allocate memory, like 'malloc'. On failure MALLOC 33 /* Call ALLOCATE to allocate memory, like 'malloc'. On failure ALLOCATE
34 should return NULL, though not necessarily set errno. When given 34 should return NULL, though not necessarily set errno. When given
35 a zero size it may return NULL even if successful. */ 35 a zero size it may return NULL even if successful. */
36 void *(*malloc) (size_t); 36 void *(*allocate) (size_t);
37 37
38 /* If nonnull, call REALLOC to reallocate memory, like 'realloc'. 38 /* If nonnull, call REALLOCATE to reallocate memory, like 'realloc'.
39 On failure REALLOC should return NULL, though not necessarily set 39 On failure REALLOCATE should return NULL, though not necessarily set
40 errno. When given a zero size it may return NULL even if 40 errno. When given a zero size it may return NULL even if
41 successful. */ 41 successful. */
42 void *(*realloc) (void *, size_t); 42 void *(*reallocate) (void *, size_t);
43 43
44 /* Call FREE to free memory, like 'free'. */ 44 /* Call FREE to free memory, like 'free'. */
45 void (*free) (void *); 45 void (*free) (void *);
@@ -50,4 +50,7 @@ struct allocator
50 void (*die) (void); 50 void (*die) (void);
51}; 51};
52 52
53/* An allocator using the stdlib functions and a null DIE function. */
54extern struct allocator const stdlib_allocator;
55
53#endif 56#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 @@
26 26
27#include <errno.h> 27#include <errno.h>
28#include <limits.h> 28#include <limits.h>
29#include <stdlib.h>
30#include <string.h> 29#include <string.h>
31#include <unistd.h> 30#include <unistd.h>
32 31
33/* Use the system functions, not the gnulib overrides, because this
34 module does not depend on GNU or POSIX semantics. */
35#undef malloc
36#undef realloc
37
38/* Define this independently so that stdint.h is not a prerequisite. */ 32/* Define this independently so that stdint.h is not a prerequisite. */
39#ifndef SIZE_MAX 33#ifndef SIZE_MAX
40# define SIZE_MAX ((size_t) -1) 34# define SIZE_MAX ((size_t) -1)
@@ -57,11 +51,6 @@ careadlinkatcwd (int fd, char const *filename, char *buffer,
57} 51}
58#endif 52#endif
59 53
60/* A standard allocator. For now, only careadlinkat needs this, but
61 perhaps it should be moved to the allocator module. */
62static struct allocator const standard_allocator =
63 { malloc, realloc, free, NULL };
64
65/* Assuming the current directory is FD, get the symbolic link value 54/* Assuming the current directory is FD, get the symbolic link value
66 of FILENAME as a null-terminated string and put it into a buffer. 55 of FILENAME as a null-terminated string and put it into a buffer.
67 If FD is AT_FDCWD, FILENAME is interpreted relative to the current 56 If FD is AT_FDCWD, FILENAME is interpreted relative to the current
@@ -94,7 +83,7 @@ careadlinkat (int fd, char const *filename,
94 char stack_buf[1024]; 83 char stack_buf[1024];
95 84
96 if (! alloc) 85 if (! alloc)
97 alloc = &standard_allocator; 86 alloc = &stdlib_allocator;
98 87
99 if (! buffer_size) 88 if (! buffer_size)
100 { 89 {
@@ -138,16 +127,16 @@ careadlinkat (int fd, char const *filename,
138 127
139 if (buf == stack_buf) 128 if (buf == stack_buf)
140 { 129 {
141 char *b = (char *) alloc->malloc (link_size); 130 char *b = (char *) alloc->allocate (link_size);
142 if (! b) 131 if (! b)
143 break; 132 break;
144 memcpy (b, buf, link_size); 133 memcpy (b, buf, link_size);
145 buf = b; 134 buf = b;
146 } 135 }
147 else if (link_size < buf_size && buf != buffer && alloc->realloc) 136 else if (link_size < buf_size && buf != buffer && alloc->reallocate)
148 { 137 {
149 /* Shrink BUF before returning it. */ 138 /* Shrink BUF before returning it. */
150 char *b = (char *) alloc->realloc (buf, link_size); 139 char *b = (char *) alloc->reallocate (buf, link_size);
151 if (b) 140 if (b)
152 buf = b; 141 buf = b;
153 } 142 }
@@ -164,7 +153,7 @@ careadlinkat (int fd, char const *filename,
164 buf_size = buf_size_max; 153 buf_size = buf_size_max;
165 else 154 else
166 break; 155 break;
167 buf = (char *) alloc->malloc (buf_size); 156 buf = (char *) alloc->allocate (buf_size);
168 } 157 }
169 while (buf); 158 while (buf);
170 159
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)
21libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) 21libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
22EXTRA_libgnu_a_SOURCES = 22EXTRA_libgnu_a_SOURCES =
23 23
24## begin gnulib module allocator
25
26libgnu_a_SOURCES += allocator.c
27
28EXTRA_DIST += allocator.h
29
30## end gnulib module allocator
31
24## begin gnulib module arg-nonnull 32## begin gnulib module arg-nonnull
25 33
26# The BUILT_SOURCES created by this Makefile snippet are not used via #include 34# The BUILT_SOURCES created by this Makefile snippet are not used via #include
@@ -73,7 +81,7 @@ EXTRA_DIST += $(top_srcdir)/./c++defs.h
73 81
74libgnu_a_SOURCES += careadlinkat.c 82libgnu_a_SOURCES += careadlinkat.c
75 83
76EXTRA_DIST += allocator.h careadlinkat.h 84EXTRA_DIST += careadlinkat.h
77 85
78## end gnulib module careadlinkat 86## end gnulib module careadlinkat
79 87
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 - "
255# endif 255# endif
256#endif 256#endif
257 257
258/* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not
259 rely on GNU or POSIX semantics for malloc and realloc (for example,
260 by never specifying a zero size), so it does not need malloc or
261 realloc to be redefined. */
258#if @GNULIB_MALLOC_POSIX@ 262#if @GNULIB_MALLOC_POSIX@
259# if @REPLACE_MALLOC@ 263# if @REPLACE_MALLOC@
260# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 264# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
265 || _GL_USE_STDLIB_ALLOC)
261# undef malloc 266# undef malloc
262# define malloc rpl_malloc 267# define malloc rpl_malloc
263# endif 268# endif
@@ -267,7 +272,7 @@ _GL_CXXALIAS_RPL (malloc, void *, (size_t size));
267_GL_CXXALIAS_SYS (malloc, void *, (size_t size)); 272_GL_CXXALIAS_SYS (malloc, void *, (size_t size));
268# endif 273# endif
269_GL_CXXALIASWARN (malloc); 274_GL_CXXALIASWARN (malloc);
270#elif defined GNULIB_POSIXCHECK 275#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
271# undef malloc 276# undef malloc
272/* Assume malloc is always declared. */ 277/* Assume malloc is always declared. */
273_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - " 278_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 - "
531 536
532#if @GNULIB_REALLOC_POSIX@ 537#if @GNULIB_REALLOC_POSIX@
533# if @REPLACE_REALLOC@ 538# if @REPLACE_REALLOC@
534# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 539# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
540 || _GL_USE_STDLIB_ALLOC)
535# undef realloc 541# undef realloc
536# define realloc rpl_realloc 542# define realloc rpl_realloc
537# endif 543# endif
@@ -541,7 +547,7 @@ _GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size));
541_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size)); 547_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
542# endif 548# endif
543_GL_CXXALIASWARN (realloc); 549_GL_CXXALIASWARN (realloc);
544#elif defined GNULIB_POSIXCHECK 550#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
545# undef realloc 551# undef realloc
546/* Assume realloc is always declared. */ 552/* Assume realloc is always declared. */
547_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - " 553_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "