Blame lib/allocator.h

Packit 33f14e
/* Memory allocators such as malloc+free.
Packit 33f14e
Packit 33f14e
   Copyright (C) 2011-2017 Free Software Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software: you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3 of the License, or
Packit 33f14e
   (at your option) any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
/* Written by Paul Eggert.  */
Packit 33f14e
Packit 33f14e
#ifndef _GL_ALLOCATOR_H
Packit 33f14e
#define _GL_ALLOCATOR_H
Packit 33f14e
Packit 33f14e
#include <stddef.h>
Packit 33f14e
Packit 33f14e
/* An object describing a memory allocator family.  */
Packit 33f14e
Packit 33f14e
struct allocator
Packit 33f14e
{
Packit 33f14e
  /* Do not use GCC attributes such as __attribute__ ((malloc)) with
Packit 33f14e
     the function types pointed at by these members, because these
Packit 33f14e
     attributes do not work with pointers to functions.  See
Packit 33f14e
     <http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00007.html>.  */
Packit 33f14e
Packit 33f14e
  /* Call ALLOCATE to allocate memory, like 'malloc'.  On failure ALLOCATE
Packit 33f14e
     should return NULL, though not necessarily set errno.  When given
Packit 33f14e
     a zero size it may return NULL even if successful.  */
Packit 33f14e
  void *(*allocate) (size_t);
Packit 33f14e
Packit 33f14e
  /* If nonnull, call REALLOCATE to reallocate memory, like 'realloc'.
Packit 33f14e
     On failure REALLOCATE should return NULL, though not necessarily set
Packit 33f14e
     errno.  When given a zero size it may return NULL even if
Packit 33f14e
     successful.  */
Packit 33f14e
  void *(*reallocate) (void *, size_t);
Packit 33f14e
Packit 33f14e
  /* Call FREE to free memory, like 'free'.  */
Packit 33f14e
  void (*free) (void *);
Packit 33f14e
Packit 33f14e
  /* If nonnull, call DIE (SIZE) if MALLOC (SIZE) or REALLOC (...,
Packit 33f14e
     SIZE) fails.  DIE should not return.  SIZE should equal SIZE_MAX
Packit 33f14e
     if size_t overflow was detected while calculating sizes to be
Packit 33f14e
     passed to MALLOC or REALLOC.  */
Packit 33f14e
  void (*die) (size_t);
Packit 33f14e
};
Packit 33f14e
Packit 33f14e
/* An allocator using the stdlib functions and a null DIE function.  */
Packit 33f14e
extern struct allocator const stdlib_allocator;
Packit 33f14e
Packit 33f14e
#endif /* _GL_ALLOCATOR_H */