From cb4ce86374195eccbc3591f74a0c7b8168273667 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 8 Apr 2011 13:22:51 -0700 Subject: [PATCH] allocator: New module. * modules/allocator, lib/allocator.c: New files. * lib/allocator.h (stdlib_allocator): New decl. * lib/careadlinkat.c (_GL_USE_STDLIB_ALLOC, standard_allocator): Remove. Do not include . (careadlinkat): Use stdlib_allocator instead of rolling our own. * modules/careadlinkat (Files): Remove lib/allocator.h. (Depends-on): Add allocator. --- ChangeLog | 9 +++++++++ lib/allocator.c | 5 +++++ lib/allocator.h | 3 +++ lib/careadlinkat.c | 9 +-------- modules/allocator | 22 ++++++++++++++++++++++ modules/careadlinkat | 2 +- 6 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 lib/allocator.c create mode 100644 modules/allocator diff --git a/ChangeLog b/ChangeLog index 619bf67f45..121c22a318 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2011-04-08 Paul Eggert + allocator: New module. + * modules/allocator, lib/allocator.c: New files. + * lib/allocator.h (stdlib_allocator): New decl. + * lib/careadlinkat.c (_GL_USE_STDLIB_ALLOC, standard_allocator): + Remove. Do not include . + (careadlinkat): Use stdlib_allocator instead of rolling our own. + * modules/careadlinkat (Files): Remove lib/allocator.h. + (Depends-on): Add allocator. + stdlib: let modules use system malloc, realloc * lib/stdlib.in.h (malloc, realloc): Don't #define or add warnings if !_GL_USE_STDLIB_ALLOC. diff --git a/lib/allocator.c b/lib/allocator.c new file mode 100644 index 0000000000..2c1a3da03a --- /dev/null +++ b/lib/allocator.c @@ -0,0 +1,5 @@ +#define _GL_USE_STDLIB_ALLOC 1 +#include +#include "allocator.h" +#include +struct allocator const stdlib_allocator = { malloc, realloc, free, NULL }; diff --git a/lib/allocator.h b/lib/allocator.h index e30732b605..a89ba32b09 100644 --- a/lib/allocator.h +++ b/lib/allocator.h @@ -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 5f0d43c2e7..7a7806d121 100644 --- a/lib/careadlinkat.c +++ b/lib/careadlinkat.c @@ -18,7 +18,6 @@ /* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */ -#define _GL_USE_STDLIB_ALLOC 1 #include #include "careadlinkat.h" @@ -27,7 +26,6 @@ #include #include -#include #include #include @@ -53,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 @@ -90,7 +83,7 @@ careadlinkat (int fd, char const *filename, char stack_buf[1024]; if (! alloc) - alloc = &standard_allocator; + alloc = &stdlib_allocator; if (! buffer_size) { diff --git a/modules/allocator b/modules/allocator new file mode 100644 index 0000000000..6ff55526c4 --- /dev/null +++ b/modules/allocator @@ -0,0 +1,22 @@ +Description: +Storage allocators. + +Files: +lib/allocator.h +lib/allocator.c + +Depends-on: + +configure.ac: + +Makefile.am: +lib_SOURCES += allocator.c + +Include: +"allocator.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/careadlinkat b/modules/careadlinkat index 670fde08f7..b4bc4a4dfb 100644 --- a/modules/careadlinkat +++ b/modules/careadlinkat @@ -4,9 +4,9 @@ Read symbolic links into a buffer without size limitation, relative to fd. Files: lib/careadlinkat.c lib/careadlinkat.h -lib/allocator.h Depends-on: +allocator readlink ssize_t unistd -- 2.30.2