authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2020-07-04 13:44:28+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-04 21:40:06+03:00
log0ae1157e4553d6f54e0d489daebb006c402e0f63
treea182d250d6b86db25e60950916a923bcd47de234
parent672b4d5c24ab6c4d8ddf1ec7a1a7753a2d21dc87

std.mem.dupe is deprecated, move all references in std

Replaced all occurences of std.mem.dupe in stdlib with Allocator.dupe/std.mem.dupeZ -> Allocator.dupeZ

14 files changed, 23 insertions(+), 23 deletions(-)

lib/std/buf_map.zig+1-1
......@@ -79,7 +79,7 @@ pub const BufMap = struct {
7979 }
8080
8181 fn copy(self: BufMap, value: []const u8) ![]u8 {
82 return mem.dupe(self.hash_map.allocator, u8, value);
82 return self.hash_map.allocator.dupe(u8, value);
8383 }
8484};
8585
lib/std/build.zig+1-1
......@@ -286,7 +286,7 @@ pub const Builder = struct {
286286 }
287287
288288 pub fn dupe(self: *Builder, bytes: []const u8) []u8 {
289 return mem.dupe(self.allocator, u8, bytes) catch unreachable;
289 return self.allocator.dupe(u8, bytes) catch unreachable;
290290 }
291291
292292 pub fn dupePath(self: *Builder, bytes: []const u8) []u8 {
lib/std/cache_hash.zig+1-1
......@@ -207,7 +207,7 @@ pub const CacheHash = struct {
207207 }
208208
209209 if (cache_hash_file.path == null) {
210 cache_hash_file.path = try mem.dupe(self.allocator, u8, file_path);
210 cache_hash_file.path = try self.allocator.dupe(u8, file_path);
211211 }
212212
213213 const this_file = fs.cwd().openFile(cache_hash_file.path.?, .{ .read = true }) catch {
lib/std/fs.zig+3-3
......@@ -1825,7 +1825,7 @@ pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 {
18251825 // TODO(#4812): Investigate other systems and whether it is possible to get
18261826 // this path by trying larger and larger buffers until one succeeds.
18271827 var buf: [MAX_PATH_BYTES]u8 = undefined;
1828 return mem.dupe(allocator, u8, try selfExePath(&buf));
1828 return allocator.dupe(u8, try selfExePath(&buf));
18291829}
18301830
18311831/// Get the path to the current executable.
......@@ -1888,7 +1888,7 @@ pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 {
18881888 // TODO(#4812): Investigate other systems and whether it is possible to get
18891889 // this path by trying larger and larger buffers until one succeeds.
18901890 var buf: [MAX_PATH_BYTES]u8 = undefined;
1891 return mem.dupe(allocator, u8, try selfExeDirPath(&buf));
1891 return allocator.dupe(u8, try selfExeDirPath(&buf));
18921892}
18931893
18941894/// Get the directory path that contains the current executable.
......@@ -1910,7 +1910,7 @@ pub fn realpathAlloc(allocator: *Allocator, pathname: []const u8) ![]u8 {
19101910 // paths. musl supports passing NULL but restricts the output to PATH_MAX
19111911 // anyway.
19121912 var buf: [MAX_PATH_BYTES]u8 = undefined;
1913 return mem.dupe(allocator, u8, try os.realpath(pathname, &buf));
1913 return allocator.dupe(u8, try os.realpath(pathname, &buf));
19141914}
19151915
19161916test "" {
lib/std/fs/path.zig+2-2
......@@ -1034,7 +1034,7 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
10341034 var from_it = mem.tokenize(resolved_from, "/\\");
10351035 var to_it = mem.tokenize(resolved_to, "/\\");
10361036 while (true) {
1037 const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest());
1037 const from_component = from_it.next() orelse return allocator.dupe(u8, to_it.rest());
10381038 const to_rest = to_it.rest();
10391039 if (to_it.next()) |to_component| {
10401040 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
......@@ -1085,7 +1085,7 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
10851085 var from_it = mem.tokenize(resolved_from, "/");
10861086 var to_it = mem.tokenize(resolved_to, "/");
10871087 while (true) {
1088 const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest());
1088 const from_component = from_it.next() orelse return allocator.dupe(u8, to_it.rest());
10891089 const to_rest = to_it.rest();
10901090 if (to_it.next()) |to_component| {
10911091 if (mem.eql(u8, from_component, to_component))
lib/std/fs/watch.zig+1-1
......@@ -360,7 +360,7 @@ pub fn Watch(comptime V: type) type {
360360
361361 fn addFileWindows(self: *Self, file_path: []const u8, value: V) !?V {
362362 // TODO we might need to convert dirname and basename to canonical file paths ("short"?)
363 const dirname = try std.mem.dupe(self.allocator, u8, std.fs.path.dirname(file_path) orelse ".");
363 const dirname = try self.allocator.dupe(u8, std.fs.path.dirname(file_path) orelse ".");
364364 var dirname_consumed = false;
365365 defer if (!dirname_consumed) self.allocator.free(dirname);
366366
lib/std/http/headers.zig+2-2
......@@ -38,7 +38,7 @@ const HeaderEntry = struct {
3838 return Self{
3939 .allocator = allocator,
4040 .name = name, // takes reference
41 .value = try mem.dupe(allocator, u8, value),
41 .value = try allocator.dupe(u8, value),
4242 .never_index = never_index orelse never_index_default(name),
4343 };
4444 }
......@@ -161,7 +161,7 @@ pub const Headers = struct {
161161 var dex = &kv.value;
162162 try dex.append(n - 1);
163163 } else {
164 const name_dup = try mem.dupe(self.allocator, u8, name);
164 const name_dup = try self.allocator.dupe(u8, name);
165165 errdefer self.allocator.free(name_dup);
166166 entry = try HeaderEntry.init(self.allocator, name_dup, value, never_index);
167167 errdefer entry.deinit();
lib/std/json.zig+2-2
......@@ -1567,7 +1567,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
15671567 if (ptrInfo.child != u8) return error.UnexpectedToken;
15681568 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
15691569 switch (stringToken.escapes) {
1570 .None => return mem.dupe(allocator, u8, source_slice),
1570 .None => return allocator.dupe(u8, source_slice),
15711571 .Some => |some_escapes| {
15721572 const output = try allocator.alloc(u8, stringToken.decodedLength());
15731573 errdefer allocator.free(output);
......@@ -2043,7 +2043,7 @@ pub const Parser = struct {
20432043 fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayloadType(Token, Token.String), input: []const u8, i: usize) !Value {
20442044 const slice = s.slice(input, i);
20452045 switch (s.escapes) {
2046 .None => return Value{ .String = if (p.copy_strings) try mem.dupe(allocator, u8, slice) else slice },
2046 .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice },
20472047 .Some => |some_escapes| {
20482048 const output = try allocator.alloc(u8, s.decodedLength());
20492049 errdefer allocator.free(output);
lib/std/math/big/int.zig+1-1
......@@ -1105,7 +1105,7 @@ pub const Const = struct {
11051105 assert(base <= 16);
11061106
11071107 if (self.eqZero()) {
1108 return mem.dupe(allocator, u8, "0");
1108 return allocator.dupe(u8, "0");
11091109 }
11101110 const string = try allocator.alloc(u8, self.sizeInBaseUpperBound(base));
11111111 errdefer allocator.free(string);
lib/std/net.zig+1-1
......@@ -682,7 +682,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
682682
683683 if (info.canonname) |n| {
684684 if (result.canon_name == null) {
685 result.canon_name = try mem.dupe(arena, u8, mem.spanZ(n));
685 result.canon_name = try arena.dupe(u8, mem.spanZ(n));
686686 }
687687 }
688688 i += 1;
lib/std/priority_queue.zig+1-1
......@@ -333,7 +333,7 @@ test "std.PriorityQueue: addSlice" {
333333
334334test "std.PriorityQueue: fromOwnedSlice" {
335335 const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
336 const heap_items = try std.mem.dupe(testing.allocator, u32, items[0..]);
336 const heap_items = try testing.allocator.dupe(u32, items[0..]);
337337 var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, heap_items[0..]);
338338 defer queue.deinit();
339339
lib/std/process.zig+5-5
......@@ -30,7 +30,7 @@ pub fn getCwdAlloc(allocator: *Allocator) ![]u8 {
3030 var current_buf: []u8 = &stack_buf;
3131 while (true) {
3232 if (os.getcwd(current_buf)) |slice| {
33 return mem.dupe(allocator, u8, slice);
33 return allocator.dupe(u8, slice);
3434 } else |err| switch (err) {
3535 error.NameTooLong => {
3636 // The path is too long to fit in stack_buf. Allocate geometrically
......@@ -169,7 +169,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
169169 };
170170 } else {
171171 const result = os.getenv(key) orelse return error.EnvironmentVariableNotFound;
172 return mem.dupe(allocator, u8, result);
172 return allocator.dupe(u8, result);
173173 }
174174}
175175
......@@ -436,7 +436,7 @@ pub const ArgIterator = struct {
436436 if (builtin.os.tag == .windows) {
437437 return self.inner.next(allocator);
438438 } else {
439 return mem.dupe(allocator, u8, self.inner.next() orelse return null);
439 return allocator.dupe(u8, self.inner.next() orelse return null);
440440 }
441441 }
442442
......@@ -718,7 +718,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
718718 fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void {
719719 const name = info.dlpi_name orelse return;
720720 if (name[0] == '/') {
721 const item = try mem.dupeZ(list.allocator, u8, mem.spanZ(name));
721 const item = try list.allocator.dupeZ(u8, mem.spanZ(name));
722722 errdefer list.allocator.free(item);
723723 try list.append(item);
724724 }
......@@ -739,7 +739,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
739739 var i: u32 = 0;
740740 while (i < img_count) : (i += 1) {
741741 const name = std.c._dyld_get_image_name(i);
742 const item = try mem.dupeZ(allocator, u8, mem.spanZ(name));
742 const item = try allocator.dupeZ(u8, mem.spanZ(name));
743743 errdefer allocator.free(item);
744744 try paths.append(item);
745745 }
lib/std/zig/cross_target.zig+1-1
......@@ -497,7 +497,7 @@ pub const CrossTarget = struct {
497497
498498 pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 {
499499 if (self.isNative()) {
500 return mem.dupe(allocator, u8, "native");
500 return allocator.dupe(u8, "native");
501501 }
502502
503503 const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native";
lib/std/zig/system.zig+1-1
......@@ -161,7 +161,7 @@ pub const NativePaths = struct {
161161 }
162162
163163 fn appendArray(self: *NativePaths, array: *ArrayList([:0]u8), s: []const u8) !void {
164 const item = try std.mem.dupeZ(array.allocator, u8, s);
164 const item = try array.allocator.dupeZ(u8, s);
165165 errdefer array.allocator.free(item);
166166 try array.append(item);
167167 }