mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add temp allocator scribble. Make bufferstream safer.
This commit is contained in:
@@ -65,6 +65,16 @@ fn void TempAllocator.release(&self, void* old_pointer, bool) @dynamic
|
||||
fn void TempAllocator.reset(&self, usz mark) @dynamic
|
||||
{
|
||||
TempAllocatorPage *last_page = self.last_page;
|
||||
$if env::COMPILER_SAFE_MODE:
|
||||
if (!last_page)
|
||||
{
|
||||
usz cleaned = self.used - mark;
|
||||
if (cleaned > 0)
|
||||
{
|
||||
self.data[mark : cleaned] = 0xAA;
|
||||
}
|
||||
}
|
||||
$endif
|
||||
while (last_page && last_page.mark > mark)
|
||||
{
|
||||
TempAllocatorPage *to_free = last_page;
|
||||
|
||||
@@ -141,15 +141,9 @@ fn usz! copy_to(InStream in, OutStream dst, char[] buffer = {})
|
||||
if (&dst.read_to) return dst.read_to(in);
|
||||
$switch (env::MEMORY_ENV)
|
||||
$case NORMAL:
|
||||
@pool()
|
||||
{
|
||||
return copy_through_buffer(in, dst, mem::temp_alloc_array(char, 4096));
|
||||
};
|
||||
return copy_through_buffer(in, dst, &&char[4096]{});
|
||||
$case SMALL:
|
||||
@pool()
|
||||
{
|
||||
return copy_through_buffer(in, dst, mem::temp_alloc_array(char, 1024));
|
||||
};
|
||||
return copy_through_buffer(in, dst, &&char[1024]{});
|
||||
$case TINY:
|
||||
$case NONE:
|
||||
return copy_through_buffer(in, dst, &&(char[256]{}));
|
||||
|
||||
@@ -15,7 +15,7 @@ fn void! readbuffer_large()
|
||||
|
||||
assert(n == DATA.len, "large read failed: got %d; want %d", n, DATA.len);
|
||||
String got = (String)bytes[..];
|
||||
assert(got == DATA, "large read failed: got %d; want %d", got, DATA);
|
||||
assert(got == DATA, "large read failed: got %s; want %s", got, DATA);
|
||||
}
|
||||
|
||||
fn void! readbuffer()
|
||||
@@ -33,7 +33,7 @@ fn void! readbuffer()
|
||||
|
||||
assert(n == DATA.len, "got %d; want %d", n, DATA.len);
|
||||
String got = bw.str_view();
|
||||
assert(got == DATA, "got %d; want %d", got, DATA);
|
||||
assert(got == DATA, "got %s; want %s", got, DATA);
|
||||
}
|
||||
|
||||
fn void! writebuffer_large()
|
||||
@@ -48,7 +48,7 @@ fn void! writebuffer_large()
|
||||
|
||||
assert(n == DATA.len, "large write failed: got %d; want %d", n, DATA.len);
|
||||
String got = out.str_view();
|
||||
assert(got == DATA, "large write failed: got %d; want %d", got, DATA);
|
||||
assert(got == DATA, "large write failed: got %s; want %s", got, DATA);
|
||||
}
|
||||
|
||||
fn void! writebuffer()
|
||||
@@ -65,5 +65,5 @@ fn void! writebuffer()
|
||||
|
||||
assert(n == DATA.len, "got %d; want %d", n, DATA.len);
|
||||
String got = out.str_view();
|
||||
assert(got == DATA, "got %d; want %d", got, DATA);
|
||||
assert(got == DATA, "got %s; want %s", got, DATA);
|
||||
}
|
||||
Reference in New Issue
Block a user