]> gcc.gnu.org Git - gcc.git/blame - libobjc/memory.c
pack_generic.c (pack): Add missing return and fix whitespace.
[gcc.git] / libobjc / memory.c
CommitLineData
7b869986
NP
1/* GNU Objective C Runtime Memory allocation functions
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2002, 2009, 2010
40165636 3 Free Software Foundation, Inc.
88e17b57
BE
4 Contributed by Kresten Krab Thorup
5
38709cad 6This file is part of GCC.
88e17b57 7
38709cad 8GCC is free software; you can redistribute it and/or modify it
88e17b57 9under the terms of the GNU General Public License as published by the
748086b7 10Free Software Foundation; either version 3, or (at your option) any
88e17b57
BE
11later version.
12
38709cad 13GCC is distributed in the hope that it will be useful, but WITHOUT
88e17b57
BE
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
748086b7
JJ
18Under Section 7 of GPL version 3, you are granted additional
19permissions described in the GCC Runtime Library Exception, version
203.1, as published by the Free Software Foundation.
21
22You should have received a copy of the GNU General Public License and
23a copy of the GCC Runtime Library Exception along with this program;
24see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25<http://www.gnu.org/licenses/>. */
88e17b57 26
d1be5d82
NP
27/*
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.
31*/
32
6dead247 33#include "objc-private/common.h"
7b869986 34#include "objc-private/error.h"
88e17b57 35
6dead247
NP
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.
39*/
88e17b57
BE
40#define __USE_FIXED_PROTOTYPES__
41#include <stdlib.h>
6dead247 42
a19fac96
NP
43#include "objc/objc.h"
44#include "objc/objc-api.h"
88e17b57 45
d1be5d82
NP
46#if OBJC_WITH_GC
47#include <gc.h>
88e17b57
BE
48
49void *
40165636 50objc_malloc (size_t size)
88e17b57 51{
d1be5d82 52 void *res = (void *)(GC_malloc (size));
40165636 53 if (! res)
7b869986 54 _objc_abort ("Virtual memory exhausted\n");
88e17b57
BE
55 return res;
56}
57
58void *
40165636 59objc_atomic_malloc (size_t size)
88e17b57 60{
d1be5d82 61 void *res = (void *)(GC_malloc_atomic (size));
40165636 62 if (! res)
7b869986 63 _objc_abort ("Virtual memory exhausted\n");
88e17b57
BE
64 return res;
65}
66
67void *
d1be5d82
NP
68objc_realloc (void *mem, size_t size)
69{
70 void *res = (void *)(GC_realloc (mem, size));
71 if (! res)
72 _objc_abort ("Virtual memory exhausted\n");
73 return res;
74}
75
76void *
77objc_calloc (size_t nelem, size_t size)
78{
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));
82 if (! res)
83 _objc_abort ("Virtual memory exhausted\n");
84 return res;
85}
86
87void
88objc_free (void *mem)
89{
90 return;
91}
92
93#else
94
95void *
96objc_malloc (size_t size)
88e17b57 97{
d1be5d82
NP
98 void *res = (void *)(malloc (size));
99 if (! res)
100 _objc_abort ("Virtual memory exhausted\n");
101 return res;
102}
103
104void *
105objc_atomic_malloc (size_t size)
106{
107 void *res = (void *)(malloc (size));
40165636 108 if (! res)
7b869986 109 _objc_abort ("Virtual memory exhausted\n");
88e17b57
BE
110 return res;
111}
112
113void *
40165636 114objc_realloc (void *mem, size_t size)
88e17b57 115{
d1be5d82 116 void *res = (void *)(realloc (mem, size));
40165636 117 if (! res)
7b869986 118 _objc_abort ("Virtual memory exhausted\n");
88e17b57
BE
119 return res;
120}
121
122void *
40165636 123objc_calloc (size_t nelem, size_t size)
88e17b57 124{
d1be5d82 125 void *res = (void *)(calloc (nelem, size));
40165636 126 if (! res)
7b869986 127 _objc_abort ("Virtual memory exhausted\n");
88e17b57
BE
128 return res;
129}
130
131void
40165636 132objc_free (void *mem)
88e17b57 133{
d1be5d82 134 free (mem);
88e17b57
BE
135}
136
d1be5d82
NP
137#endif /* !OBJC_WITH_GC */
138
139/* The rest of the file contains deprecated code. */
88e17b57
BE
140
141#if OBJC_WITH_GC
88e17b57 142
d1be5d82
NP
143void *
144objc_valloc (size_t size)
88e17b57 145{
d1be5d82
NP
146 void *res = (void *)(GC_malloc (size));
147 if (! res)
148 _objc_abort ("Virtual memory exhausted\n");
149 return res;
88e17b57
BE
150}
151
d1be5d82
NP
152#else
153
154void *
155objc_valloc (size_t size)
40165636 156{
d1be5d82
NP
157 void *res = (void *)(malloc (size));
158 if (! res)
159 _objc_abort ("Virtual memory exhausted\n");
160 return res;
40165636 161}
88e17b57 162
d1be5d82 163#endif /* !OBJC_WITH_GC */
88e17b57 164
d1be5d82
NP
165/*
166 Hook functions for memory allocation and disposal. Deprecated
167 and currently unused.
168*/
88e17b57 169
40165636
RB
170void *(*_objc_malloc) (size_t) = malloc;
171void *(*_objc_atomic_malloc) (size_t) = malloc;
172void *(*_objc_valloc) (size_t) = malloc;
173void *(*_objc_realloc) (void *, size_t) = realloc;
174void *(*_objc_calloc) (size_t, size_t) = calloc;
175void (*_objc_free) (void *) = free;
This page took 0.894918 seconds and 5 git commands to generate.