44fdefa0fb2319b468ac578a1c4f89bed8b88d66
[debian/tar] / gnu / allocator.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Memory allocators such as malloc+free.
4
5    Copyright (C) 2011-2013 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* Written by Paul Eggert.  */
21
22 #ifndef _GL_ALLOCATOR_H
23 #define _GL_ALLOCATOR_H
24
25 #include <stddef.h>
26
27 /* An object describing a memory allocator family.  */
28
29 struct allocator
30 {
31   /* Do not use GCC attributes such as __attribute__ ((malloc)) with
32      the function types pointed at by these members, because these
33      attributes do not work with pointers to functions.  See
34      <http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00007.html>.  */
35
36   /* Call ALLOCATE to allocate memory, like 'malloc'.  On failure ALLOCATE
37      should return NULL, though not necessarily set errno.  When given
38      a zero size it may return NULL even if successful.  */
39   void *(*allocate) (size_t);
40
41   /* If nonnull, call REALLOCATE to reallocate memory, like 'realloc'.
42      On failure REALLOCATE should return NULL, though not necessarily set
43      errno.  When given a zero size it may return NULL even if
44      successful.  */
45   void *(*reallocate) (void *, size_t);
46
47   /* Call FREE to free memory, like 'free'.  */
48   void (*free) (void *);
49
50   /* If nonnull, call DIE (SIZE) if MALLOC (SIZE) or REALLOC (...,
51      SIZE) fails.  DIE should not return.  SIZE should equal SIZE_MAX
52      if size_t overflow was detected while calculating sizes to be
53      passed to MALLOC or REALLOC.  */
54   void (*die) (size_t);
55 };
56
57 /* An allocator using the stdlib functions and a null DIE function.  */
58 extern struct allocator const stdlib_allocator;
59
60 #endif /* _GL_ALLOCATOR_H */