Merge -r 127928:132243 from trunk
[official-gcc.git] / libgfortran / runtime / memory.c
blobd84d32200bdddcc4a0b123fe61a41450eb4d5c8a
1 /* Memory management routines.
2 Copyright 2002, 2005, 2006, 2007 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
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.
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.)
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.
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. */
31 #include "libgfortran.h"
32 #include <stdlib.h>
34 /* If GFC_CLEAR_MEMORY is defined, the memory allocation routines will
35 return memory that is guaranteed to be set to zero. This can have
36 a severe efficiency penalty, so it should never be set if good
37 performance is desired, but it can help when you're debugging code. */
38 /* #define GFC_CLEAR_MEMORY */
40 void *
41 get_mem (size_t n)
43 void *p;
45 #ifdef GFC_CLEAR_MEMORY
46 p = (void *) calloc (1, n);
47 #else
48 p = (void *) malloc (n);
49 #endif
50 if (p == NULL)
51 os_error ("Memory allocation failed");
53 return p;
57 void
58 free_mem (void *p)
60 free (p);
64 /* Allocate memory for internal (compiler generated) use. */
66 void *
67 internal_malloc_size (size_t size)
69 if (size == 0)
70 return NULL;
72 return get_mem (size);