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

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