| author | |
| committer | |
| log | 0ae1157e4553d6f54e0d489daebb006c402e0f63 |
| tree | a182d250d6b86db25e60950916a923bcd47de234 |
| parent | 672b4d5c24ab6c4d8ddf1ec7a1a7753a2d21dc87 |
Replaced all occurences of std.mem.dupe in stdlib with
Allocator.dupe/std.mem.dupeZ -> Allocator.dupeZ14 files changed, 23 insertions(+), 23 deletions(-)
lib/std/buf_map.zig+1-1| ... | @@ -79,7 +79,7 @@ pub const BufMap = struct { | ... | @@ -79,7 +79,7 @@ pub const BufMap = struct { |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | fn copy(self: BufMap, value: []const u8) ![]u8 { | 81 | 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); |
| 83 | } | 83 | } |
| 84 | }; | 84 | }; |
| 85 | 85 |
lib/std/build.zig+1-1| ... | @@ -286,7 +286,7 @@ pub const Builder = struct { | ... | @@ -286,7 +286,7 @@ pub const Builder = struct { |
| 286 | } | 286 | } |
| 287 | 287 | ||
| 288 | pub fn dupe(self: *Builder, bytes: []const u8) []u8 { | 288 | 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; |
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | pub fn dupePath(self: *Builder, bytes: []const u8) []u8 { | 292 | pub fn dupePath(self: *Builder, bytes: []const u8) []u8 { |
lib/std/cache_hash.zig+1-1| ... | @@ -207,7 +207,7 @@ pub const CacheHash = struct { | ... | @@ -207,7 +207,7 @@ pub const CacheHash = struct { |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | if (cache_hash_file.path == null) { | 209 | 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); |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | const this_file = fs.cwd().openFile(cache_hash_file.path.?, .{ .read = true }) catch { | 213 | 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 { | ... | @@ -1825,7 +1825,7 @@ pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 { |
| 1825 | // TODO(#4812): Investigate other systems and whether it is possible to get | 1825 | // TODO(#4812): Investigate other systems and whether it is possible to get |
| 1826 | // this path by trying larger and larger buffers until one succeeds. | 1826 | // this path by trying larger and larger buffers until one succeeds. |
| 1827 | var buf: [MAX_PATH_BYTES]u8 = undefined; | 1827 | var buf: [MAX_PATH_BYTES]u8 = undefined; |
| 1828 | return mem.dupe(allocator, u8, try selfExePath(&buf)); | 1828 | return allocator.dupe(u8, try selfExePath(&buf)); |
| 1829 | } | 1829 | } |
| 1830 | 1830 | ||
| 1831 | /// Get the path to the current executable. | 1831 | /// Get the path to the current executable. |
| ... | @@ -1888,7 +1888,7 @@ pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 { | ... | @@ -1888,7 +1888,7 @@ pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 { |
| 1888 | // TODO(#4812): Investigate other systems and whether it is possible to get | 1888 | // TODO(#4812): Investigate other systems and whether it is possible to get |
| 1889 | // this path by trying larger and larger buffers until one succeeds. | 1889 | // this path by trying larger and larger buffers until one succeeds. |
| 1890 | var buf: [MAX_PATH_BYTES]u8 = undefined; | 1890 | var buf: [MAX_PATH_BYTES]u8 = undefined; |
| 1891 | return mem.dupe(allocator, u8, try selfExeDirPath(&buf)); | 1891 | return allocator.dupe(u8, try selfExeDirPath(&buf)); |
| 1892 | } | 1892 | } |
| 1893 | 1893 | ||
| 1894 | /// Get the directory path that contains the current executable. | 1894 | /// Get the directory path that contains the current executable. |
| ... | @@ -1910,7 +1910,7 @@ pub fn realpathAlloc(allocator: *Allocator, pathname: []const u8) ![]u8 { | ... | @@ -1910,7 +1910,7 @@ pub fn realpathAlloc(allocator: *Allocator, pathname: []const u8) ![]u8 { |
| 1910 | // paths. musl supports passing NULL but restricts the output to PATH_MAX | 1910 | // paths. musl supports passing NULL but restricts the output to PATH_MAX |
| 1911 | // anyway. | 1911 | // anyway. |
| 1912 | var buf: [MAX_PATH_BYTES]u8 = undefined; | 1912 | 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)); |
| 1914 | } | 1914 | } |
| 1915 | 1915 | ||
| 1916 | test "" { | 1916 | test "" { |
lib/std/fs/path.zig+2-2| ... | @@ -1034,7 +1034,7 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) | ... | @@ -1034,7 +1034,7 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) |
| 1034 | var from_it = mem.tokenize(resolved_from, "/\\"); | 1034 | var from_it = mem.tokenize(resolved_from, "/\\"); |
| 1035 | var to_it = mem.tokenize(resolved_to, "/\\"); | 1035 | var to_it = mem.tokenize(resolved_to, "/\\"); |
| 1036 | while (true) { | 1036 | 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()); |
| 1038 | const to_rest = to_it.rest(); | 1038 | const to_rest = to_it.rest(); |
| 1039 | if (to_it.next()) |to_component| { | 1039 | if (to_it.next()) |to_component| { |
| 1040 | // TODO ASCII is wrong, we actually need full unicode support to compare paths. | 1040 | // 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) ![ | ... | @@ -1085,7 +1085,7 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![ |
| 1085 | var from_it = mem.tokenize(resolved_from, "/"); | 1085 | var from_it = mem.tokenize(resolved_from, "/"); |
| 1086 | var to_it = mem.tokenize(resolved_to, "/"); | 1086 | var to_it = mem.tokenize(resolved_to, "/"); |
| 1087 | while (true) { | 1087 | 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()); |
| 1089 | const to_rest = to_it.rest(); | 1089 | const to_rest = to_it.rest(); |
| 1090 | if (to_it.next()) |to_component| { | 1090 | if (to_it.next()) |to_component| { |
| 1091 | if (mem.eql(u8, from_component, to_component)) | 1091 | 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 { | ... | @@ -360,7 +360,7 @@ pub fn Watch(comptime V: type) type { |
| 360 | 360 | ||
| 361 | fn addFileWindows(self: *Self, file_path: []const u8, value: V) !?V { | 361 | fn addFileWindows(self: *Self, file_path: []const u8, value: V) !?V { |
| 362 | // TODO we might need to convert dirname and basename to canonical file paths ("short"?) | 362 | // 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 "."); |
| 364 | var dirname_consumed = false; | 364 | var dirname_consumed = false; |
| 365 | defer if (!dirname_consumed) self.allocator.free(dirname); | 365 | defer if (!dirname_consumed) self.allocator.free(dirname); |
| 366 | 366 |
lib/std/http/headers.zig+2-2| ... | @@ -38,7 +38,7 @@ const HeaderEntry = struct { | ... | @@ -38,7 +38,7 @@ const HeaderEntry = struct { |
| 38 | return Self{ | 38 | return Self{ |
| 39 | .allocator = allocator, | 39 | .allocator = allocator, |
| 40 | .name = name, // takes reference | 40 | .name = name, // takes reference |
| 41 | .value = try mem.dupe(allocator, u8, value), | 41 | .value = try allocator.dupe(u8, value), |
| 42 | .never_index = never_index orelse never_index_default(name), | 42 | .never_index = never_index orelse never_index_default(name), |
| 43 | }; | 43 | }; |
| 44 | } | 44 | } |
| ... | @@ -161,7 +161,7 @@ pub const Headers = struct { | ... | @@ -161,7 +161,7 @@ pub const Headers = struct { |
| 161 | var dex = &kv.value; | 161 | var dex = &kv.value; |
| 162 | try dex.append(n - 1); | 162 | try dex.append(n - 1); |
| 163 | } else { | 163 | } else { |
| 164 | const name_dup = try mem.dupe(self.allocator, u8, name); | 164 | const name_dup = try self.allocator.dupe(u8, name); |
| 165 | errdefer self.allocator.free(name_dup); | 165 | errdefer self.allocator.free(name_dup); |
| 166 | entry = try HeaderEntry.init(self.allocator, name_dup, value, never_index); | 166 | entry = try HeaderEntry.init(self.allocator, name_dup, value, never_index); |
| 167 | errdefer entry.deinit(); | 167 | errdefer entry.deinit(); |
lib/std/json.zig+2-2| ... | @@ -1567,7 +1567,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options: | ... | @@ -1567,7 +1567,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options: |
| 1567 | if (ptrInfo.child != u8) return error.UnexpectedToken; | 1567 | if (ptrInfo.child != u8) return error.UnexpectedToken; |
| 1568 | const source_slice = stringToken.slice(tokens.slice, tokens.i - 1); | 1568 | const source_slice = stringToken.slice(tokens.slice, tokens.i - 1); |
| 1569 | switch (stringToken.escapes) { | 1569 | switch (stringToken.escapes) { |
| 1570 | .None => return mem.dupe(allocator, u8, source_slice), | 1570 | .None => return allocator.dupe(u8, source_slice), |
| 1571 | .Some => |some_escapes| { | 1571 | .Some => |some_escapes| { |
| 1572 | const output = try allocator.alloc(u8, stringToken.decodedLength()); | 1572 | const output = try allocator.alloc(u8, stringToken.decodedLength()); |
| 1573 | errdefer allocator.free(output); | 1573 | errdefer allocator.free(output); |
| ... | @@ -2043,7 +2043,7 @@ pub const Parser = struct { | ... | @@ -2043,7 +2043,7 @@ pub const Parser = struct { |
| 2043 | fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayloadType(Token, Token.String), input: []const u8, i: usize) !Value { | 2043 | fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayloadType(Token, Token.String), input: []const u8, i: usize) !Value { |
| 2044 | const slice = s.slice(input, i); | 2044 | const slice = s.slice(input, i); |
| 2045 | switch (s.escapes) { | 2045 | 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 }, |
| 2047 | .Some => |some_escapes| { | 2047 | .Some => |some_escapes| { |
| 2048 | const output = try allocator.alloc(u8, s.decodedLength()); | 2048 | const output = try allocator.alloc(u8, s.decodedLength()); |
| 2049 | errdefer allocator.free(output); | 2049 | errdefer allocator.free(output); |
lib/std/math/big/int.zig+1-1| ... | @@ -1105,7 +1105,7 @@ pub const Const = struct { | ... | @@ -1105,7 +1105,7 @@ pub const Const = struct { |
| 1105 | assert(base <= 16); | 1105 | assert(base <= 16); |
| 1106 | 1106 | ||
| 1107 | if (self.eqZero()) { | 1107 | if (self.eqZero()) { |
| 1108 | return mem.dupe(allocator, u8, "0"); | 1108 | return allocator.dupe(u8, "0"); |
| 1109 | } | 1109 | } |
| 1110 | const string = try allocator.alloc(u8, self.sizeInBaseUpperBound(base)); | 1110 | const string = try allocator.alloc(u8, self.sizeInBaseUpperBound(base)); |
| 1111 | errdefer allocator.free(string); | 1111 | 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) !* | ... | @@ -682,7 +682,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !* |
| 682 | 682 | ||
| 683 | if (info.canonname) |n| { | 683 | if (info.canonname) |n| { |
| 684 | if (result.canon_name == null) { | 684 | 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)); |
| 686 | } | 686 | } |
| 687 | } | 687 | } |
| 688 | i += 1; | 688 | i += 1; |
lib/std/priority_queue.zig+1-1| ... | @@ -333,7 +333,7 @@ test "std.PriorityQueue: addSlice" { | ... | @@ -333,7 +333,7 @@ test "std.PriorityQueue: addSlice" { |
| 333 | 333 | ||
| 334 | test "std.PriorityQueue: fromOwnedSlice" { | 334 | test "std.PriorityQueue: fromOwnedSlice" { |
| 335 | const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 }; | 335 | 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..]); |
| 337 | var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, heap_items[0..]); | 337 | var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, heap_items[0..]); |
| 338 | defer queue.deinit(); | 338 | defer queue.deinit(); |
| 339 | 339 |
lib/std/process.zig+5-5| ... | @@ -30,7 +30,7 @@ pub fn getCwdAlloc(allocator: *Allocator) ![]u8 { | ... | @@ -30,7 +30,7 @@ pub fn getCwdAlloc(allocator: *Allocator) ![]u8 { |
| 30 | var current_buf: []u8 = &stack_buf; | 30 | var current_buf: []u8 = &stack_buf; |
| 31 | while (true) { | 31 | while (true) { |
| 32 | if (os.getcwd(current_buf)) |slice| { | 32 | if (os.getcwd(current_buf)) |slice| { |
| 33 | return mem.dupe(allocator, u8, slice); | 33 | return allocator.dupe(u8, slice); |
| 34 | } else |err| switch (err) { | 34 | } else |err| switch (err) { |
| 35 | error.NameTooLong => { | 35 | error.NameTooLong => { |
| 36 | // The path is too long to fit in stack_buf. Allocate geometrically | 36 | // 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 | ... | @@ -169,7 +169,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned |
| 169 | }; | 169 | }; |
| 170 | } else { | 170 | } else { |
| 171 | const result = os.getenv(key) orelse return error.EnvironmentVariableNotFound; | 171 | const result = os.getenv(key) orelse return error.EnvironmentVariableNotFound; |
| 172 | return mem.dupe(allocator, u8, result); | 172 | return allocator.dupe(u8, result); |
| 173 | } | 173 | } |
| 174 | } | 174 | } |
| 175 | 175 | ||
| ... | @@ -436,7 +436,7 @@ pub const ArgIterator = struct { | ... | @@ -436,7 +436,7 @@ pub const ArgIterator = struct { |
| 436 | if (builtin.os.tag == .windows) { | 436 | if (builtin.os.tag == .windows) { |
| 437 | return self.inner.next(allocator); | 437 | return self.inner.next(allocator); |
| 438 | } else { | 438 | } else { |
| 439 | return mem.dupe(allocator, u8, self.inner.next() orelse return null); | 439 | return allocator.dupe(u8, self.inner.next() orelse return null); |
| 440 | } | 440 | } |
| 441 | } | 441 | } |
| 442 | 442 | ||
| ... | @@ -718,7 +718,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] | ... | @@ -718,7 +718,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] |
| 718 | fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void { | 718 | fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void { |
| 719 | const name = info.dlpi_name orelse return; | 719 | const name = info.dlpi_name orelse return; |
| 720 | if (name[0] == '/') { | 720 | 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)); |
| 722 | errdefer list.allocator.free(item); | 722 | errdefer list.allocator.free(item); |
| 723 | try list.append(item); | 723 | try list.append(item); |
| 724 | } | 724 | } |
| ... | @@ -739,7 +739,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] | ... | @@ -739,7 +739,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] |
| 739 | var i: u32 = 0; | 739 | var i: u32 = 0; |
| 740 | while (i < img_count) : (i += 1) { | 740 | while (i < img_count) : (i += 1) { |
| 741 | const name = std.c._dyld_get_image_name(i); | 741 | 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)); |
| 743 | errdefer allocator.free(item); | 743 | errdefer allocator.free(item); |
| 744 | try paths.append(item); | 744 | try paths.append(item); |
| 745 | } | 745 | } |
lib/std/zig/cross_target.zig+1-1| ... | @@ -497,7 +497,7 @@ pub const CrossTarget = struct { | ... | @@ -497,7 +497,7 @@ pub const CrossTarget = struct { |
| 497 | 497 | ||
| 498 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 { | 498 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 { |
| 499 | if (self.isNative()) { | 499 | if (self.isNative()) { |
| 500 | return mem.dupe(allocator, u8, "native"); | 500 | return allocator.dupe(u8, "native"); |
| 501 | } | 501 | } |
| 502 | 502 | ||
| 503 | const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native"; | 503 | 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 { | ... | @@ -161,7 +161,7 @@ pub const NativePaths = struct { |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | fn appendArray(self: *NativePaths, array: *ArrayList([:0]u8), s: []const u8) !void { | 163 | 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); |
| 165 | errdefer array.allocator.free(item); | 165 | errdefer array.allocator.free(item); |
| 166 | try array.append(item); | 166 | try array.append(item); |
| 167 | } | 167 | } |