|
1 | | -const std = @import("index.zig"); |
| 1 | +const std = @import("../index.zig"); |
2 | 2 | const math = std.math; |
3 | 3 | const mem = std.mem; |
4 | 4 | const io = std.io; |
5 | 5 | const os = std.os; |
6 | | -const elf = @import("elf.zig"); |
7 | | -const DW = @import("dwarf.zig"); |
| 6 | +const elf = std.elf; |
| 7 | +const DW = std.dwarf; |
8 | 8 | const ArrayList = std.ArrayList; |
9 | 9 | const builtin = @import("builtin"); |
10 | 10 |
|
@@ -992,59 +992,3 @@ fn readILeb128(in_stream: &io.InStream) -> %i64 { |
992 | 992 | pub const global_allocator = &global_fixed_allocator.allocator; |
993 | 993 | var global_fixed_allocator = mem.FixedBufferAllocator.init(global_allocator_mem[0..]); |
994 | 994 | var global_allocator_mem: [100 * 1024]u8 = undefined; |
995 | | - |
996 | | -/// Allocator that fails after N allocations, useful for making sure out of |
997 | | -/// memory conditions are handled correctly. |
998 | | -pub const FailingAllocator = struct { |
999 | | - allocator: mem.Allocator, |
1000 | | - index: usize, |
1001 | | - fail_index: usize, |
1002 | | - internal_allocator: &mem.Allocator, |
1003 | | - allocated_bytes: usize, |
1004 | | - |
1005 | | - pub fn init(allocator: &mem.Allocator, fail_index: usize) -> FailingAllocator { |
1006 | | - return FailingAllocator { |
1007 | | - .internal_allocator = allocator, |
1008 | | - .fail_index = fail_index, |
1009 | | - .index = 0, |
1010 | | - .allocated_bytes = 0, |
1011 | | - .allocator = mem.Allocator { |
1012 | | - .allocFn = alloc, |
1013 | | - .reallocFn = realloc, |
1014 | | - .freeFn = free, |
1015 | | - }, |
1016 | | - }; |
1017 | | - } |
1018 | | - |
1019 | | - fn alloc(allocator: &mem.Allocator, n: usize, alignment: u29) -> %[]u8 { |
1020 | | - const self = @fieldParentPtr(FailingAllocator, "allocator", allocator); |
1021 | | - if (self.index == self.fail_index) { |
1022 | | - return error.OutOfMemory; |
1023 | | - } |
1024 | | - self.index += 1; |
1025 | | - const result = %return self.internal_allocator.allocFn(self.internal_allocator, n, alignment); |
1026 | | - self.allocated_bytes += result.len; |
1027 | | - return result; |
1028 | | - } |
1029 | | - |
1030 | | - fn realloc(allocator: &mem.Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 { |
1031 | | - const self = @fieldParentPtr(FailingAllocator, "allocator", allocator); |
1032 | | - if (new_size <= old_mem.len) { |
1033 | | - self.allocated_bytes -= old_mem.len - new_size; |
1034 | | - return self.internal_allocator.reallocFn(self.internal_allocator, old_mem, new_size, alignment); |
1035 | | - } |
1036 | | - if (self.index == self.fail_index) { |
1037 | | - return error.OutOfMemory; |
1038 | | - } |
1039 | | - self.index += 1; |
1040 | | - const result = %return self.internal_allocator.reallocFn(self.internal_allocator, old_mem, new_size, alignment); |
1041 | | - self.allocated_bytes += new_size - old_mem.len; |
1042 | | - return result; |
1043 | | - } |
1044 | | - |
1045 | | - fn free(allocator: &mem.Allocator, bytes: []u8) { |
1046 | | - const self = @fieldParentPtr(FailingAllocator, "allocator", allocator); |
1047 | | - self.allocated_bytes -= bytes.len; |
1048 | | - return self.internal_allocator.freeFn(self.internal_allocator, bytes); |
1049 | | - } |
1050 | | -}; |
0 commit comments