| ... | ... | @@ -88,6 +88,7 @@ pub const IncrementingAllocator = struct { |
| 88 | 88 | allocator: Allocator, |
| 89 | 89 | bytes: []u8, |
| 90 | 90 | end_index: usize, |
| 91 | heap_handle: if (builtin.os == Os.windows) os.windows.HANDLE else void, |
| 91 | 92 | |
| 92 | 93 | fn init(capacity: usize) -> %IncrementingAllocator { |
| 93 | 94 | switch (builtin.os) { |
| ... | ... | @@ -106,11 +107,12 @@ pub const IncrementingAllocator = struct { |
| 106 | 107 | }, |
| 107 | 108 | .bytes = @intToPtr(&u8, addr)[0..capacity], |
| 108 | 109 | .end_index = 0, |
| 110 | .heap_handle = {}, |
| 109 | 111 | }; |
| 110 | 112 | }, |
| 111 | 113 | Os.windows => { |
| 112 | | const heap_handle = os.windows.GetProcessHeap(); |
| 113 | | const ptr = os.windows.HeapAlloc(heap_handle, 0, capacity); |
| 114 | const heap_handle = os.windows.GetProcessHeap() ?? return error.OutOfMemory; |
| 115 | const ptr = os.windows.HeapAlloc(heap_handle, 0, capacity) ?? return error.OutOfMemory; |
| 114 | 116 | return IncrementingAllocator { |
| 115 | 117 | .allocator = Allocator { |
| 116 | 118 | .allocFn = alloc, |
| ... | ... | @@ -119,6 +121,7 @@ pub const IncrementingAllocator = struct { |
| 119 | 121 | }, |
| 120 | 122 | .bytes = @ptrCast(&u8, ptr)[0..capacity], |
| 121 | 123 | .end_index = 0, |
| 124 | .heap_handle = heap_handle, |
| 122 | 125 | }; |
| 123 | 126 | }, |
| 124 | 127 | else => @compileError("Unsupported OS"), |
| ... | ... | @@ -131,8 +134,7 @@ pub const IncrementingAllocator = struct { |
| 131 | 134 | _ = os.posix.munmap(self.bytes.ptr, self.bytes.len); |
| 132 | 135 | }, |
| 133 | 136 | Os.windows => { |
| 134 | | const heap_handle = os.windows.GetProcessHeap(); |
| 135 | | _ = os.windows.HeapFree(heap_handle, 0, @ptrCast(os.windows.LPVOID, self.bytes.ptr)); |
| 137 | _ = os.windows.HeapFree(self.heap_handle, 0, @ptrCast(os.windows.LPVOID, self.bytes.ptr)); |
| 136 | 138 | }, |
| 137 | 139 | else => @compileError("Unsupported OS"), |
| 138 | 140 | } |