authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2020-05-06 23:56:48-06:00
committergravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2020-05-06 23:56:48-06:00
log0a76e11617a76d884a52bf49c7b2b9a706e7bc8c
tree4d29dcb2c5ced4ccc9ccff918109c65bff4a33a9
parent0c7397b49f8c434cf1f714c08ab37d1429ab1be7

add failAllocator to enable some regression tests


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

lib/std/mem.zig+16
...@@ -281,6 +281,22 @@ pub const Allocator = struct {...@@ -281,6 +281,22 @@ pub const Allocator = struct {
281 }281 }
282};282};
283283
284var failAllocator = Allocator {
285 .reallocFn = failAllocatorRealloc,
286 .shrinkFn = failAllocatorShrink,
287};
288fn failAllocatorRealloc(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 {
289 return error.OutOfMemory;
290}
291fn 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
295test "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/// Copy all of source into dest at position 0.300/// Copy all of source into dest at position 0.
285/// dest.len must be >= source.len.301/// dest.len must be >= source.len.
286/// dest.ptr must be <= src.ptr.302/// dest.ptr must be <= src.ptr.