authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2017-09-20 01:47:41+12:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-19 09:47:41-04:00
logc4a54377e3f07bbd2f9c54c1962c7941792c2c1f
treed2e66dddcd183f75bac9207323bf2d25a4402de7
parent751ab72a82a0edc4c5c129c6675a33d3cd57fa73

Stop debug allocator ever panicking (#492)


1 files changed, 5 insertions(+), 0 deletions(-)

std/debug.zig+5
...@@ -957,12 +957,17 @@ pub var global_allocator = mem.Allocator {...@@ -957,12 +957,17 @@ pub var global_allocator = mem.Allocator {
957var some_mem: [100 * 1024]u8 = undefined;957var some_mem: [100 * 1024]u8 = undefined;
958var some_mem_index: usize = 0;958var some_mem_index: usize = 0;
959959
960error OutOfMemory;
961
960fn globalAlloc(self: &mem.Allocator, n: usize, alignment: usize) -> %[]u8 {962fn globalAlloc(self: &mem.Allocator, n: usize, alignment: usize) -> %[]u8 {
961 const addr = @ptrToInt(&some_mem[some_mem_index]);963 const addr = @ptrToInt(&some_mem[some_mem_index]);
962 const rem = @rem(addr, alignment);964 const rem = @rem(addr, alignment);
963 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);965 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);
964 const adjusted_index = some_mem_index + march_forward_bytes;966 const adjusted_index = some_mem_index + march_forward_bytes;
965 const end_index = adjusted_index + n;967 const end_index = adjusted_index + n;
968 if (end_index > some_mem.len) {
969 return error.OutOfMemory;
970 }
966 const result = some_mem[adjusted_index .. end_index];971 const result = some_mem[adjusted_index .. end_index];
967 some_mem_index = end_index;972 some_mem_index = end_index;
968 return result;973 return result;