]>
Commit | Line | Data |
---|---|---|
8b6dba81 | 1 | /* Memory management routines. |
748086b7 | 2 | Copyright 2002, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | Contributed by Paul Brook <paul@nowt.org> |
4 | ||
57dea9f6 | 5 | This file is part of the GNU Fortran 95 runtime library (libgfortran). |
6de9cd9a | 6 | |
57dea9f6 TM |
7 | Libgfortran is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU General Public | |
6de9cd9a | 9 | License as published by the Free Software Foundation; either |
748086b7 | 10 | version 3 of the License, or (at your option) any later version. |
57dea9f6 TM |
11 | |
12 | Libgfortran is distributed in the hope that it will be useful, | |
6de9cd9a DN |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
57dea9f6 | 15 | GNU General Public License for more details. |
6de9cd9a | 16 | |
748086b7 JJ |
17 | Under Section 7 of GPL version 3, you are granted additional |
18 | permissions described in the GCC Runtime Library Exception, version | |
19 | 3.1, as published by the Free Software Foundation. | |
20 | ||
21 | You should have received a copy of the GNU General Public License and | |
22 | a copy of the GCC Runtime Library Exception along with this program; | |
23 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
24 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a | 25 | |
6de9cd9a | 26 | #include "libgfortran.h" |
36ae8a61 | 27 | #include <stdlib.h> |
6de9cd9a DN |
28 | |
29 | /* If GFC_CLEAR_MEMORY is defined, the memory allocation routines will | |
30 | return memory that is guaranteed to be set to zero. This can have | |
31 | a severe efficiency penalty, so it should never be set if good | |
32 | performance is desired, but it can help when you're debugging code. */ | |
c42a19d5 | 33 | /* #define GFC_CLEAR_MEMORY */ |
6de9cd9a | 34 | |
6de9cd9a DN |
35 | void * |
36 | get_mem (size_t n) | |
37 | { | |
38 | void *p; | |
39 | ||
40 | #ifdef GFC_CLEAR_MEMORY | |
7d7b8bfe | 41 | p = (void *) calloc (1, n); |
6de9cd9a | 42 | #else |
6de9cd9a | 43 | p = (void *) malloc (n); |
6de9cd9a DN |
44 | #endif |
45 | if (p == NULL) | |
46 | os_error ("Memory allocation failed"); | |
47 | ||
48 | return p; | |
49 | } | |
50 | ||
51 | ||
52 | void | |
53 | free_mem (void *p) | |
54 | { | |
6de9cd9a DN |
55 | free (p); |
56 | } | |
57 | ||
58 | ||
6de9cd9a DN |
59 | /* Allocate memory for internal (compiler generated) use. */ |
60 | ||
61 | void * | |
62 | internal_malloc_size (size_t size) | |
63 | { | |
ec25720b | 64 | if (size == 0) |
03551860 | 65 | return NULL; |
6de9cd9a | 66 | |
03551860 | 67 | return get_mem (size); |
6de9cd9a | 68 | } |