authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-07 12:39:57+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-05-07 12:39:57+03:00
log54b2a6ec41ae7be190163e94dd75bafb359cf239
tree4d29dcb2c5ced4ccc9ccff918109c65bff4a33a9
parentb336dda0765ba345253ed4b25113a5db4386c3f0
parent0a76e11617a76d884a52bf49c7b2b9a706e7bc8c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #5287 from marler8997/fixAllocWithPayload

fix copy/paste error in AllocWithOptionaPayload

1 files changed, 18 insertions(+), 2 deletions(-)

lib/std/mem.zig+18-2
......@@ -124,9 +124,9 @@ pub const Allocator = struct {
124124
125125 fn AllocWithOptionsPayload(comptime Elem: type, comptime alignment: ?u29, comptime sentinel: ?Elem) type {
126126 if (sentinel) |s| {
127 return [:s]align(alignment orelse @alignOf(T)) Elem;
127 return [:s]align(alignment orelse @alignOf(Elem)) Elem;
128128 } else {
129 return []align(alignment orelse @alignOf(T)) Elem;
129 return []align(alignment orelse @alignOf(Elem)) Elem;
130130 }
131131 }
132132
......@@ -281,6 +281,22 @@ pub const Allocator = struct {
281281 }
282282};
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
284300/// Copy all of source into dest at position 0.
285301/// dest.len must be >= source.len.
286302/// dest.ptr must be <= src.ptr.