OSDN Git Service

7407486b6961f4c38df6f529bba8d5b8c03f5c36
[pf3gnuchains/gcc-fork.git] / libgfortran / runtime / memory.c
1 /* Memory management routines.
2    Copyright 2002, 2005, 2006, 2007 Free Software Foundation, Inc.
3    Contributed by Paul Brook <paul@nowt.org>
4
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file.  (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
19 executable.)
20
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public
27 License along with libgfortran; see the file COPYING.  If not,
28 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA.  */
30
31 #include "config.h"
32 #include <stdlib.h>
33 #include "libgfortran.h"
34
35 /* If GFC_CLEAR_MEMORY is defined, the memory allocation routines will
36    return memory that is guaranteed to be set to zero.  This can have
37    a severe efficiency penalty, so it should never be set if good
38    performance is desired, but it can help when you're debugging code.  */
39 /* #define GFC_CLEAR_MEMORY */
40
41 void *
42 get_mem (size_t n)
43 {
44   void *p;
45
46 #ifdef GFC_CLEAR_MEMORY
47   p = (void *) calloc (1, n);
48 #else
49   p = (void *) malloc (n);
50 #endif
51   if (p == NULL)
52     os_error ("Memory allocation failed");
53
54   return p;
55 }
56
57
58 void
59 free_mem (void *p)
60 {
61   free (p);
62 }
63
64
65 /* Allocate memory for internal (compiler generated) use.  */
66
67 void *
68 internal_malloc_size (size_t size)
69 {
70   if (size == 0)
71     return NULL;
72
73   return get_mem (size);
74 }