comparison dmd/OutBuffer.d @ 5:63623152e82a

Fixed memory corruption bug which was introduced when attempting to restore GC functionality
author dkoroskin <>
date Tue, 08 Dec 2009 21:39:17 +0300
parents d706d958e4e8
children 832f71e6f96c
comparison
equal deleted inserted replaced
4:d706d958e4e8 5:63623152e82a
5 5
6 import core.stdc.stdlib; 6 import core.stdc.stdlib;
7 import core.stdc.string; 7 import core.stdc.string;
8 8
9 import core.memory; 9 import core.memory;
10 import core.stdc.stdlib;
10 11
11 class OutBuffer 12 class OutBuffer
12 { 13 {
13 ubyte* data; 14 ubyte* data;
14 uint offset; 15 uint offset;
39 { 40 {
40 //printf("OutBuffer::reserve: size = %d, offset = %d, nbytes = %d\n", size, offset, nbytes); 41 //printf("OutBuffer::reserve: size = %d, offset = %d, nbytes = %d\n", size, offset, nbytes);
41 if (size - offset < nbytes) 42 if (size - offset < nbytes)
42 { 43 {
43 size = (offset + nbytes) * 2; 44 size = (offset + nbytes) * 2;
44 data = cast(ubyte*)GC.realloc(data, size); 45 data = cast(ubyte*)realloc(data, size);
45 } 46 }
46 } 47 }
47 48
48 final void setsize(uint size) 49 final void setsize(uint size)
49 { 50 {
264 assert(false); 265 assert(false);
265 } 266 }
266 267
267 string toChars() 268 string toChars()
268 { 269 {
269 return getString().idup; 270 char[] s = getString();
271 char* copy = cast(char*)malloc(s.length);
272 memcpy(copy, s.ptr, s.length);
273 return assumeUnique(copy[0..s.length]);
274
275 //return getString().idup;
270 } 276 }
271 277
272 final string extractString() 278 final string extractString()
273 { 279 {
274 char[] s = getString(); 280 char[] s = getString();