Annotation of OpenXM_contrib/gmp/memory.c, Revision 1.1
1.1 ! maekawa 1: /* Memory allocation routines.
! 2:
! 3: Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
! 4:
! 5: This file is part of the GNU MP Library.
! 6:
! 7: The GNU MP Library is free software; you can redistribute it and/or modify
! 8: it under the terms of the GNU Library General Public License as published by
! 9: the Free Software Foundation; either version 2 of the License, or (at your
! 10: option) any later version.
! 11:
! 12: The GNU MP Library is distributed in the hope that it will be useful, but
! 13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
! 15: License for more details.
! 16:
! 17: You should have received a copy of the GNU Library General Public License
! 18: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
! 19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
! 20: MA 02111-1307, USA. */
! 21:
! 22: #include <stdio.h>
! 23:
! 24: #include "gmp.h"
! 25: #include "gmp-impl.h"
! 26:
! 27: #ifdef __NeXT__
! 28: #define static
! 29: #endif
! 30:
! 31: #if __STDC__
! 32: void * (*_mp_allocate_func) (size_t) = _mp_default_allocate;
! 33: void * (*_mp_reallocate_func) (void *, size_t, size_t)
! 34: = _mp_default_reallocate;
! 35: void (*_mp_free_func) (void *, size_t) = _mp_default_free;
! 36: #else
! 37: void * (*_mp_allocate_func) () = _mp_default_allocate;
! 38: void * (*_mp_reallocate_func) () = _mp_default_reallocate;
! 39: void (*_mp_free_func) () = _mp_default_free;
! 40: #endif
! 41:
! 42: /* Default allocation functions. In case of failure to allocate/reallocate
! 43: an error message is written to stderr and the program aborts. */
! 44:
! 45: void *
! 46: #if __STDC__
! 47: _mp_default_allocate (size_t size)
! 48: #else
! 49: _mp_default_allocate (size)
! 50: size_t size;
! 51: #endif
! 52: {
! 53: void *ret;
! 54:
! 55: ret = malloc (size);
! 56: if (ret == 0)
! 57: {
! 58: perror ("cannot allocate in gmp");
! 59: abort ();
! 60: }
! 61:
! 62: return ret;
! 63: }
! 64:
! 65: void *
! 66: #if __STDC__
! 67: _mp_default_reallocate (void *oldptr, size_t old_size, size_t new_size)
! 68: #else
! 69: _mp_default_reallocate (oldptr, old_size, new_size)
! 70: void *oldptr;
! 71: size_t old_size;
! 72: size_t new_size;
! 73: #endif
! 74: {
! 75: void *ret;
! 76:
! 77: ret = realloc (oldptr, new_size);
! 78: if (ret == 0)
! 79: {
! 80: perror ("cannot allocate in gmp");
! 81: abort ();
! 82: }
! 83:
! 84: return ret;
! 85: }
! 86:
! 87: void
! 88: #if __STDC__
! 89: _mp_default_free (void *blk_ptr, size_t blk_size)
! 90: #else
! 91: _mp_default_free (blk_ptr, blk_size)
! 92: void *blk_ptr;
! 93: size_t blk_size;
! 94: #endif
! 95: {
! 96: free (blk_ptr);
! 97: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>