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