comparison druntime/src/gc/stub/gc.d @ 759:d3eb054172f9

Added copy of druntime from DMD 2.020 modified for LDC.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 11 Nov 2008 01:52:37 +0100
parents
children
comparison
equal deleted inserted replaced
758:f04dde6e882c 759:d3eb054172f9
1 /**
2 * This module contains a minimal garbage collector implementation according to
3 * published requirements. This library is mostly intended to serve as an
4 * example, but it is usable in applications which do not rely on a garbage
5 * collector to clean up memory (ie. when dynamic array resizing is not used,
6 * and all memory allocated with 'new' is freed deterministically with
7 * 'delete').
8 *
9 * Please note that block attribute data must be tracked, or at a minimum, the
10 * FINALIZE bit must be tracked for any allocated memory block because calling
11 * rt_finalize on a non-object block can result in an access violation. In the
12 * allocator below, this tracking is done via a leading uint bitmask. A real
13 * allocator may do better to store this data separately, similar to the basic
14 * GC.
15 *
16 * Copyright: Public Domain
17 * License: Public Domain
18 * Authors: Sean Kelly
19 */
20
21 module gc.gc;
22
23 private import stdc.stdlib;
24
25 private
26 {
27 enum BlkAttr : uint
28 {
29 FINALIZE = 0b0000_0001,
30 NO_SCAN = 0b0000_0010,
31 NO_MOVE = 0b0000_0100,
32 ALL_BITS = 0b1111_1111
33 }
34
35 struct BlkInfo
36 {
37 void* base;
38 size_t size;
39 uint attr;
40 }
41
42 extern (C) void thread_init();
43 extern (C) void onOutOfMemoryError();
44 }
45
46 extern (C) void gc_init()
47 {
48 // NOTE: The GC must initialize the thread library before its first
49 // collection, and always before returning from gc_init().
50 thread_init();
51 }
52
53 extern (C) void gc_term()
54 {
55
56 }
57
58 extern (C) void gc_enable()
59 {
60
61 }
62
63 extern (C) void gc_disable()
64 {
65
66 }
67
68 extern (C) void gc_collect()
69 {
70
71 }
72
73 extern (C) void gc_minimize()
74 {
75
76 }
77
78 extern (C) uint gc_getAttr( void* p )
79 {
80 return 0;
81 }
82
83 extern (C) uint gc_setAttr( void* p, uint a )
84 {
85 return 0;
86 }
87
88 extern (C) uint gc_clrAttr( void* p, uint a )
89 {
90 return 0;
91 }
92
93 extern (C) void* gc_malloc( size_t sz, uint ba = 0 )
94 {
95 void* p = malloc( sz );
96
97 if( sz && p is null )
98 onOutOfMemoryError();
99 return p;
100 }
101
102 extern (C) void* gc_calloc( size_t sz, uint ba = 0 )
103 {
104 void* p = calloc( 1, sz );
105
106 if( sz && p is null )
107 onOutOfMemoryError();
108 return p;
109 }
110
111 extern (C) void* gc_realloc( void* p, size_t sz, uint ba = 0 )
112 {
113 p = realloc( p, sz );
114
115 if( sz && p is null )
116 onOutOfMemoryError();
117 return p;
118 }
119
120 extern (C) size_t gc_extend( void* p, size_t mx, size_t sz )
121 {
122 return 0;
123 }
124
125 extern (C) size_t gc_reserve( size_t sz )
126 {
127 return 0;
128 }
129
130 extern (C) void gc_free( void* p )
131 {
132 free( p );
133 }
134
135 extern (C) void* gc_addrOf( void* p )
136 {
137 return null;
138 }
139
140 extern (C) size_t gc_sizeOf( void* p )
141 {
142 return 0;
143 }
144
145 extern (C) BlkInfo gc_query( void* p )
146 {
147 return BlkInfo.init;
148 }
149
150 extern (C) void gc_addRoot( void* p )
151 {
152
153 }
154
155 extern (C) void gc_addRange( void* p, size_t sz )
156 {
157
158 }
159
160 extern (C) void gc_removeRoot( void *p )
161 {
162
163 }
164
165 extern (C) void gc_removeRange( void *p )
166 {
167
168 }
169
170 extern (C) void* gc_getHandle()
171 {
172 return null;
173 }
174
175 extern (C) void gc_setHandle(void* p)
176 {
177 }
178
179 extern (C) void gc_endHandle()
180 {
181 }
182