diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-12-10 21:26:28 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-12-10 21:26:52 -0500 |
| commit | f210f17d306ed1298901d38a29c1e50a1ee38ae5 (patch) | |
| tree | 77e220c6b51859d1c808a5fbcab82c97e1705fc3 /std/debug.zig | |
| parent | 4b1d120f5874a3cad4d05e21e6a3219e48f9b056 (diff) | |
| download | zig-f210f17d306ed1298901d38a29c1e50a1ee38ae5.tar.gz zig-f210f17d306ed1298901d38a29c1e50a1ee38ae5.zip | |
add self-hosted parsing and rendering to main tests
Diffstat (limited to 'std/debug.zig')
| -rw-r--r-- | std/debug.zig | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/std/debug.zig b/std/debug.zig index c520e98b15..3e7a38d043 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -966,28 +966,29 @@ fn readILeb128(in_stream: &io.InStream) -> %i64 { } pub const global_allocator = &global_allocator_state; + var global_allocator_state = mem.Allocator { .allocFn = globalAlloc, .reallocFn = globalRealloc, .freeFn = globalFree, }; -var some_mem: [100 * 1024]u8 = undefined; -var some_mem_index: usize = 0; +pub var global_allocator_mem: [100 * 1024]u8 = undefined; +pub var global_allocator_index: usize = 0; error OutOfMemory; fn globalAlloc(self: &mem.Allocator, n: usize, alignment: u29) -> %[]u8 { - const addr = @ptrToInt(&some_mem[some_mem_index]); + const addr = @ptrToInt(&global_allocator_mem[global_allocator_index]); const rem = @rem(addr, alignment); const march_forward_bytes = if (rem == 0) 0 else (alignment - rem); - const adjusted_index = some_mem_index + march_forward_bytes; + const adjusted_index = global_allocator_index + march_forward_bytes; const end_index = adjusted_index + n; - if (end_index > some_mem.len) { + if (end_index > global_allocator_mem.len) { return error.OutOfMemory; } - const result = some_mem[adjusted_index .. end_index]; - some_mem_index = end_index; + const result = global_allocator_mem[adjusted_index .. end_index]; + global_allocator_index = end_index; return result; } |
