]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/runtime/memory.c
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libgfortran / runtime / memory.c
CommitLineData
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 5This file is part of the GNU Fortran 95 runtime library (libgfortran).
6de9cd9a 6
57dea9f6
TM
7Libgfortran is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public
6de9cd9a 9License as published by the Free Software Foundation; either
748086b7 10version 3 of the License, or (at your option) any later version.
57dea9f6
TM
11
12Libgfortran is distributed in the hope that it will be useful,
6de9cd9a
DN
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57dea9f6 15GNU General Public License for more details.
6de9cd9a 16
748086b7
JJ
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see 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
35void *
36get_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
52void
53free_mem (void *p)
54{
6de9cd9a
DN
55 free (p);
56}
57
58
6de9cd9a
DN
59/* Allocate memory for internal (compiler generated) use. */
60
61void *
62internal_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}