Blame gettext-tools/gnulib-lib/allocator.h

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