| ... | ... | @@ -281,6 +281,22 @@ pub const Allocator = struct { |
| 281 | 281 | } |
| 282 | 282 | }; |
| 283 | 283 | |
| 284 | var failAllocator = Allocator { |
| 285 | .reallocFn = failAllocatorRealloc, |
| 286 | .shrinkFn = failAllocatorShrink, |
| 287 | }; |
| 288 | fn failAllocatorRealloc(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 { |
| 289 | return error.OutOfMemory; |
| 290 | } |
| 291 | fn failAllocatorShrink(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 { |
| 292 | @panic("failAllocatorShrink should never be called because it cannot allocate"); |
| 293 | } |
| 294 | |
| 295 | test "mem.Allocator basics" { |
| 296 | testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1)); |
| 297 | testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0)); |
| 298 | } |
| 299 | |
| 284 | 300 | /// Copy all of source into dest at position 0. |
| 285 | 301 | /// dest.len must be >= source.len. |
| 286 | 302 | /// dest.ptr must be <= src.ptr. |