authorgravatar for pascal@quies.netPascal S. de Kloe <pascal@quies.net> 2023-09-07 17:26:21+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-09-07 21:56:57+03:00
log9126852ba93c6df2f1bb2deff6e276561b58f313
treebceca45aef069d7ce502329e9f123b3ad40c2478
parent6484e279e54fc4232bae911dbe6fb76aa9e711ed

mem: explicit dupe and dupeZ error on Allocator


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

lib/std/mem/Allocator.zig+2-2
...@@ -315,14 +315,14 @@ pub fn free(self: Allocator, memory: anytype) void {...@@ -315,14 +315,14 @@ pub fn free(self: Allocator, memory: anytype) void {
315}315}
316316
317/// Copies `m` to newly allocated memory. Caller owns the memory.317/// Copies `m` to newly allocated memory. Caller owns the memory.
318pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T {318pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) Error![]T {
319 const new_buf = try allocator.alloc(T, m.len);319 const new_buf = try allocator.alloc(T, m.len);
320 @memcpy(new_buf, m);320 @memcpy(new_buf, m);
321 return new_buf;321 return new_buf;
322}322}
323323
324/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.324/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.
325pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T {325pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) Error![:0]T {
326 const new_buf = try allocator.alloc(T, m.len + 1);326 const new_buf = try allocator.alloc(T, m.len + 1);
327 @memcpy(new_buf[0..m.len], m);327 @memcpy(new_buf[0..m.len], m);
328 new_buf[m.len] = 0;328 new_buf[m.len] = 0;