Blame lib/allocator.h

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