1 /* GNU Objective C Runtime Memory allocation functions
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2002, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Kresten Krab Thorup
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3, or (at your option) any
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
28 This file includes the standard functions for memory allocation and
29 disposal. Users should use these functions in their ObjC programs
30 so that they work properly with garbage collectors.
33 #include "objc-private/common.h"
34 #include "objc-private/error.h"
36 /* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for
37 malloc, free, etc. on some platforms. It is unclear if we still
38 need it, but it can't hurt.
40 #define __USE_FIXED_PROTOTYPES__
43 #include "objc/objc.h"
44 #include "objc/objc-api.h"
50 objc_malloc (size_t size)
52 void *res = (void *)(GC_malloc (size));
54 _objc_abort ("Virtual memory exhausted\n");
59 objc_atomic_malloc (size_t size)
61 void *res = (void *)(GC_malloc_atomic (size));
63 _objc_abort ("Virtual memory exhausted\n");
68 objc_realloc (void *mem, size_t size)
70 void *res = (void *)(GC_realloc (mem, size));
72 _objc_abort ("Virtual memory exhausted\n");
77 objc_calloc (size_t nelem, size_t size)
79 /* Note that GC_malloc returns cleared memory (see documentation) so
80 there is no need to clear it. */
81 void *res = (void *)(GC_malloc (nelem * size));
83 _objc_abort ("Virtual memory exhausted\n");
96 objc_malloc (size_t size)
98 void *res = (void *)(malloc (size));
100 _objc_abort ("Virtual memory exhausted\n");
105 objc_atomic_malloc (size_t size)
107 void *res = (void *)(malloc (size));
109 _objc_abort ("Virtual memory exhausted\n");
114 objc_realloc (void *mem, size_t size)
116 void *res = (void *)(realloc (mem, size));
118 _objc_abort ("Virtual memory exhausted\n");
123 objc_calloc (size_t nelem, size_t size)
125 void *res = (void *)(calloc (nelem, size));
127 _objc_abort ("Virtual memory exhausted\n");
132 objc_free (void *mem)
137 #endif /* !OBJC_WITH_GC */
139 /* The rest of the file contains deprecated code. */
144 objc_valloc (size_t size)
146 void *res = (void *)(GC_malloc (size));
148 _objc_abort ("Virtual memory exhausted\n");
155 objc_valloc (size_t size)
157 void *res = (void *)(malloc (size));
159 _objc_abort ("Virtual memory exhausted\n");
163 #endif /* !OBJC_WITH_GC */
166 Hook functions for memory allocation and disposal. Deprecated
167 and currently unused.
170 void *(*_objc_malloc) (size_t) = malloc;
171 void *(*_objc_atomic_malloc) (size_t) = malloc;
172 void *(*_objc_valloc) (size_t) = malloc;
173 void *(*_objc_realloc) (void *, size_t) = realloc;
174 void *(*_objc_calloc) (size_t, size_t) = calloc;
175 void (*_objc_free) (void *) = free;