annotate libobjc/memory.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* GNU Objective C Runtime Memory allocation functions
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1993-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Kresten Krab Thorup
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
kono
parents:
diff changeset
9 Free Software Foundation; either version 3, or (at your option) any
kono
parents:
diff changeset
10 later version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT
kono
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
18 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
19 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
22 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 /* This file includes the standard functions for memory allocation and
kono
parents:
diff changeset
27 disposal. Users should use these functions in their ObjC programs
kono
parents:
diff changeset
28 so that they work properly with garbage collectors. */
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 /* TODO: Turn these into macros or inline functions. */
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 #include "objc-private/common.h"
kono
parents:
diff changeset
33 #include "objc-private/error.h"
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 /* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for
kono
parents:
diff changeset
36 malloc, free, etc. on some platforms. It is unclear if we still
kono
parents:
diff changeset
37 need it, but it can't hurt. */
kono
parents:
diff changeset
38 #define __USE_FIXED_PROTOTYPES__
kono
parents:
diff changeset
39 #include <stdlib.h>
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 #include "objc/runtime.h"
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 #if OBJC_WITH_GC
kono
parents:
diff changeset
44 #include <gc/gc.h>
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 void *
kono
parents:
diff changeset
47 objc_malloc (size_t size)
kono
parents:
diff changeset
48 {
kono
parents:
diff changeset
49 void *res = (void *)(GC_malloc (size));
kono
parents:
diff changeset
50 if (! res)
kono
parents:
diff changeset
51 _objc_abort ("Virtual memory exhausted\n");
kono
parents:
diff changeset
52 return res;
kono
parents:
diff changeset
53 }
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 void *
kono
parents:
diff changeset
56 objc_atomic_malloc (size_t size)
kono
parents:
diff changeset
57 {
kono
parents:
diff changeset
58 void *res = (void *)(GC_malloc_atomic (size));
kono
parents:
diff changeset
59 if (! res)
kono
parents:
diff changeset
60 _objc_abort ("Virtual memory exhausted\n");
kono
parents:
diff changeset
61 return res;
kono
parents:
diff changeset
62 }
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 void *
kono
parents:
diff changeset
65 objc_realloc (void *mem, size_t size)
kono
parents:
diff changeset
66 {
kono
parents:
diff changeset
67 void *res = (void *)(GC_realloc (mem, size));
kono
parents:
diff changeset
68 if (! res)
kono
parents:
diff changeset
69 _objc_abort ("Virtual memory exhausted\n");
kono
parents:
diff changeset
70 return res;
kono
parents:
diff changeset
71 }
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 void *
kono
parents:
diff changeset
74 objc_calloc (size_t nelem, size_t size)
kono
parents:
diff changeset
75 {
kono
parents:
diff changeset
76 /* Note that GC_malloc returns cleared memory (see documentation) so
kono
parents:
diff changeset
77 there is no need to clear it. */
kono
parents:
diff changeset
78 void *res = (void *)(GC_malloc (nelem * size));
kono
parents:
diff changeset
79 if (! res)
kono
parents:
diff changeset
80 _objc_abort ("Virtual memory exhausted\n");
kono
parents:
diff changeset
81 return res;
kono
parents:
diff changeset
82 }
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 void
kono
parents:
diff changeset
85 objc_free (void *mem __attribute__ ((__unused__)))
kono
parents:
diff changeset
86 {
kono
parents:
diff changeset
87 return;
kono
parents:
diff changeset
88 }
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 #else
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 void *
kono
parents:
diff changeset
93 objc_malloc (size_t size)
kono
parents:
diff changeset
94 {
kono
parents:
diff changeset
95 void *res = (void *)(malloc (size));
kono
parents:
diff changeset
96 if (! res)
kono
parents:
diff changeset
97 _objc_abort ("Virtual memory exhausted\n");
kono
parents:
diff changeset
98 return res;
kono
parents:
diff changeset
99 }
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 void *
kono
parents:
diff changeset
102 objc_atomic_malloc (size_t size)
kono
parents:
diff changeset
103 {
kono
parents:
diff changeset
104 void *res = (void *)(malloc (size));
kono
parents:
diff changeset
105 if (! res)
kono
parents:
diff changeset
106 _objc_abort ("Virtual memory exhausted\n");
kono
parents:
diff changeset
107 return res;
kono
parents:
diff changeset
108 }
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 void *
kono
parents:
diff changeset
111 objc_realloc (void *mem, size_t size)
kono
parents:
diff changeset
112 {
kono
parents:
diff changeset
113 void *res = (void *)(realloc (mem, size));
kono
parents:
diff changeset
114 if (! res)
kono
parents:
diff changeset
115 _objc_abort ("Virtual memory exhausted\n");
kono
parents:
diff changeset
116 return res;
kono
parents:
diff changeset
117 }
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 void *
kono
parents:
diff changeset
120 objc_calloc (size_t nelem, size_t size)
kono
parents:
diff changeset
121 {
kono
parents:
diff changeset
122 void *res = (void *)(calloc (nelem, size));
kono
parents:
diff changeset
123 if (! res)
kono
parents:
diff changeset
124 _objc_abort ("Virtual memory exhausted\n");
kono
parents:
diff changeset
125 return res;
kono
parents:
diff changeset
126 }
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 void
kono
parents:
diff changeset
129 objc_free (void *mem)
kono
parents:
diff changeset
130 {
kono
parents:
diff changeset
131 free (mem);
kono
parents:
diff changeset
132 }
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 #endif /* !OBJC_WITH_GC */