comparison dmd/mem.c @ 268:23d0d9855cad trunk

[svn r289] Fixed: right shift >> was broken for unsigned types. Fixed: debug info for classes now started.
author lindquist
date Sun, 15 Jun 2008 18:52:27 +0200
parents 35d93ce68cf4
children 967178e31a13
comparison
equal deleted inserted replaced
267:c43911baea21 268:23d0d9855cad
1 1
2 /* Copyright (c) 2000 Digital Mars */ 2 /* Copyright (c) 2000 Digital Mars */
3 /* All Rights Reserved */ 3 /* All Rights Reserved */
4 4
5 #include <stdio.h> 5 #include <cstdio>
6 #include <stdlib.h> 6 #include <cstdlib>
7 #include <string.h> 7 #include <cstring>
8 8 #include <cassert>
9 // I needed to perfix the dir after upgrading to gc 7.0
10 #include "gc/gc.h"
11 9
12 #include "mem.h" 10 #include "mem.h"
11
12 #define USE_BOEHM_GC 0
13
14 #if USE_BOEHM_GC
15 // I needed to perfix the dir after upgrading to gc 7.0
16 #include "gc/gc.h"
17 #endif
13 18
14 /* This implementation of the storage allocator uses the standard C allocation package. 19 /* This implementation of the storage allocator uses the standard C allocation package.
15 */ 20 */
16 21
17 Mem mem; 22 Mem mem;
23
24 #if USE_BOEHM_GC
25
18 static bool gc_was_init = false; 26 static bool gc_was_init = false;
19 27
20 void Mem::init() 28 void Mem::init()
21 { 29 {
22 GC_init(); 30 GC_init();
146 void operator delete(void *p) 154 void operator delete(void *p)
147 { 155 {
148 GC_free(p); 156 GC_free(p);
149 } 157 }
150 158
151 159 #elif !USE_BOEHM_GC
160
161 void Mem::init()
162 {
163 }
164
165 char *Mem::strdup(const char *s)
166 {
167 char *p;
168
169 if (s)
170 {
171 p = ::strdup(s);
172 if (p)
173 return p;
174 error();
175 }
176 return NULL;
177 }
178
179 void *Mem::malloc(size_t size)
180 { void *p;
181
182 if (!size)
183 p = NULL;
184 else
185 {
186 p = ::malloc(size);
187 if (!p)
188 error();
189 }
190 return p;
191 }
192
193 void *Mem::calloc(size_t size, size_t n)
194 { void *p;
195
196 if (!size || !n)
197 p = NULL;
198 else
199 {
200 p = ::malloc(size * n);
201 if (!p)
202 error();
203 memset(p, 0, size * n);
204 }
205 return p;
206 }
207
208 void *Mem::realloc(void *p, size_t size)
209 {
210 if (!size)
211 { if (p)
212 { ::free(p);
213 p = NULL;
214 }
215 }
216 else if (!p)
217 {
218 p = ::malloc(size);
219 if (!p)
220 error();
221 }
222 else
223 {
224 p = ::realloc(p, size);
225 if (!p)
226 error();
227 }
228 return p;
229 }
230
231 void Mem::free(void *p)
232 {
233 if (p)
234 ::free(p);
235 }
236
237 void *Mem::mallocdup(void *o, size_t size)
238 { void *p;
239
240 if (!size)
241 p = NULL;
242 else
243 {
244 p = ::malloc(size);
245 if (!p)
246 error();
247 else
248 memcpy(p,o,size);
249 }
250 return p;
251 }
252
253 void Mem::error()
254 {
255 printf("Error: out of memory\n");
256 exit(EXIT_FAILURE);
257 }
258
259 void Mem::fullcollect()
260 {
261 }
262
263 void Mem::mark(void *pointer)
264 {
265 }
266
267 #endif // USE_BOEHM_GC