authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-12-23 18:32:39+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-12-24 00:23:29+02:00
loge79acc24d301bd4d6afe715ce1e6be9dc3c654b5
treec138dab203b86645cd36165796d379e0675ba910
parente5aab6222812f29f4e8c99adb89358ac3e781680
signaturelock-open Commit is signed but in an unrecognized format.

std: clenup, fixes, fmt


6 files changed, 47 insertions(+), 24 deletions(-)

lib/std/array_list.zig+26-2
...@@ -94,7 +94,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -94,7 +94,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
94 /// The caller owns the returned memory. ArrayList becomes empty.94 /// The caller owns the returned memory. ArrayList becomes empty.
95 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) ![:sentinel]T {95 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) ![:sentinel]T {
96 try self.append(sentinel);96 try self.append(sentinel);
97 const result = self.list.toOwnedSlice();97 const result = self.toOwnedSlice();
98 return result[0 .. result.len - 1 :sentinel];98 return result[0 .. result.len - 1 :sentinel];
99 }99 }
100100
...@@ -399,7 +399,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -399,7 +399,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
399 /// The caller owns the returned memory. ArrayList becomes empty.399 /// The caller owns the returned memory. ArrayList becomes empty.
400 pub fn toOwnedSliceSentinel(self: *Self, allocator: *Allocator, comptime sentinel: T) ![:sentinel]T {400 pub fn toOwnedSliceSentinel(self: *Self, allocator: *Allocator, comptime sentinel: T) ![:sentinel]T {
401 try self.append(allocator, sentinel);401 try self.append(allocator, sentinel);
402 const result = self.list.toOwnedSlice(allocator);402 const result = self.toOwnedSlice(allocator);
403 return result[0 .. result.len - 1 :sentinel];403 return result[0 .. result.len - 1 :sentinel];
404 }404 }
405405
...@@ -1135,3 +1135,27 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {...@@ -1135,3 +1135,27 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
1135 testing.expectEqualSlices(u8, list.items, "aoeuasdf");1135 testing.expectEqualSlices(u8, list.items, "aoeuasdf");
1136 }1136 }
1137}1137}
1138
1139test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" {
1140 const a = testing.allocator;
1141 {
1142 var list = ArrayList(u8).init(a);
1143 defer list.deinit();
1144
1145 try list.appendSlice("foobar");
1146
1147 const result = try list.toOwnedSliceSentinel(0);
1148 defer a.free(result);
1149 testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1150 }
1151 {
1152 var list = ArrayListUnmanaged(u8){};
1153 defer list.deinit(a);
1154
1155 try list.appendSlice(a, "foobar");
1156
1157 const result = try list.toOwnedSliceSentinel(a, 0);
1158 defer a.free(result);
1159 testing.expectEqualStrings(result, mem.spanZ(result.ptr));
1160 }
1161}
lib/std/child_process.zig+1-2
...@@ -748,9 +748,8 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1...@@ -748,9 +748,8 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1
748748
749/// Caller must dealloc.749/// Caller must dealloc.
750fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![:0]u8 {750fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![:0]u8 {
751 var buf = try ArrayList(u8).init(allocator);751 var buf = std.ArrayList(u8).init(allocator);
752 defer buf.deinit();752 defer buf.deinit();
753 const buf_wi = buf.outStream();
754753
755 for (argv) |arg, arg_i| {754 for (argv) |arg, arg_i| {
756 if (arg_i != 0) try buf.append(' ');755 if (arg_i != 0) try buf.append(' ');
lib/std/io.zig+1
...@@ -209,6 +209,7 @@ test "" {...@@ -209,6 +209,7 @@ test "" {
209 _ = @import("io/buffered_writer.zig");209 _ = @import("io/buffered_writer.zig");
210 _ = @import("io/c_writer.zig");210 _ = @import("io/c_writer.zig");
211 _ = @import("io/counting_writer.zig");211 _ = @import("io/counting_writer.zig");
212 _ = @import("io/counting_reader.zig");
212 _ = @import("io/fixed_buffer_stream.zig");213 _ = @import("io/fixed_buffer_stream.zig");
213 _ = @import("io/reader.zig");214 _ = @import("io/reader.zig");
214 _ = @import("io/writer.zig");215 _ = @import("io/writer.zig");
lib/std/io/counting_reader.zig+9-9
...@@ -12,16 +12,16 @@ pub fn CountingReader(comptime ReaderType: anytype) type {...@@ -12,16 +12,16 @@ pub fn CountingReader(comptime ReaderType: anytype) type {
12 return struct {12 return struct {
13 child_reader: ReaderType,13 child_reader: ReaderType,
14 bytes_read: u64 = 0,14 bytes_read: u64 = 0,
15 15
16 pub const Error = ReaderType.Error;16 pub const Error = ReaderType.Error;
17 pub const Reader = io.Reader(*@This(), Error, read);17 pub const Reader = io.Reader(*@This(), Error, read);
18 18
19 pub fn read(self: *@This(), buf: []u8) Error!usize {19 pub fn read(self: *@This(), buf: []u8) Error!usize {
20 const amt = try self.child_reader.read(buf);20 const amt = try self.child_reader.read(buf);
21 self.bytes_read += amt;21 self.bytes_read += amt;
22 return amt;22 return amt;
23 }23 }
24 24
25 pub fn reader(self: *@This()) Reader {25 pub fn reader(self: *@This()) Reader {
26 return .{ .context = self };26 return .{ .context = self };
27 }27 }
...@@ -29,20 +29,20 @@ pub fn CountingReader(comptime ReaderType: anytype) type {...@@ -29,20 +29,20 @@ pub fn CountingReader(comptime ReaderType: anytype) type {
29}29}
3030
31pub fn countingReader(reader: anytype) CountingReader(@TypeOf(reader)) {31pub fn countingReader(reader: anytype) CountingReader(@TypeOf(reader)) {
32 return .{ .child_reader = reader, };32 return .{ .child_reader = reader };
33}33}
3434
35test "io.CountingReader" {35test "io.CountingReader" {
36 const bytes = "yay" ** 100;36 const bytes = "yay" ** 100;
37 var fbs = io.fixedBufferStream(bytes);37 var fbs = io.fixedBufferStream(bytes);
38 38
39 var counting_stream = countingReader(fbs.reader());39 var counting_stream = countingReader(fbs.reader());
40 const stream = counting_stream.reader();40 const stream = counting_stream.reader();
41 41
42 //read and discard all bytes42 //read and discard all bytes
43 while(stream.readByte()) |_| {} else |err| {43 while (stream.readByte()) |_| {} else |err| {
44 testing.expect(err == error.EndOfStream);44 testing.expect(err == error.EndOfStream);
45 }45 }
46 46
47 testing.expect(counting_stream.bytes_read == bytes.len);47 testing.expect(counting_stream.bytes_read == bytes.len);
48}
\ No newline at end of file
48}
lib/std/json.zig+7-7
...@@ -1553,7 +1553,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:...@@ -1553,7 +1553,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
1553 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);1553 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
1554 switch (stringToken.escapes) {1554 switch (stringToken.escapes) {
1555 .None => mem.copy(u8, &r, source_slice),1555 .None => mem.copy(u8, &r, source_slice),
1556 .Some => try unescapeString(&r, source_slice),1556 .Some => try unescapeValidString(&r, source_slice),
1557 }1557 }
1558 return r;1558 return r;
1559 },1559 },
...@@ -1600,7 +1600,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:...@@ -1600,7 +1600,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
1600 .Some => |some_escapes| {1600 .Some => |some_escapes| {
1601 const output = try allocator.alloc(u8, stringToken.decodedLength());1601 const output = try allocator.alloc(u8, stringToken.decodedLength());
1602 errdefer allocator.free(output);1602 errdefer allocator.free(output);
1603 try unescapeString(output, source_slice);1603 try unescapeValidString(output, source_slice);
1604 return output;1604 return output;
1605 },1605 },
1606 }1606 }
...@@ -2084,7 +2084,7 @@ pub const Parser = struct {...@@ -2084,7 +2084,7 @@ pub const Parser = struct {
2084 .Some => |some_escapes| {2084 .Some => |some_escapes| {
2085 const output = try allocator.alloc(u8, s.decodedLength());2085 const output = try allocator.alloc(u8, s.decodedLength());
2086 errdefer allocator.free(output);2086 errdefer allocator.free(output);
2087 try unescapeString(output, slice);2087 try unescapeValidString(output, slice);
2088 return Value{ .String = output };2088 return Value{ .String = output };
2089 },2089 },
2090 }2090 }
...@@ -2098,10 +2098,10 @@ pub const Parser = struct {...@@ -2098,10 +2098,10 @@ pub const Parser = struct {
2098 }2098 }
2099};2099};
21002100
2101// Unescape a JSON string2101/// Unescape a JSON string
2102// Only to be used on strings already validated by the parser2102/// Only to be used on strings already validated by the parser
2103// (note the unreachable statements and lack of bounds checking)2103/// (note the unreachable statements and lack of bounds checking)
2104pub fn unescapeString(output: []u8, input: []const u8) !void {2104pub fn unescapeValidString(output: []u8, input: []const u8) !void {
2105 var inIndex: usize = 0;2105 var inIndex: usize = 0;
2106 var outIndex: usize = 0;2106 var outIndex: usize = 0;
21072107
lib/std/os/linux/io_uring.zig+3-4
...@@ -1378,11 +1378,10 @@ test "timeout_remove" {...@@ -1378,11 +1378,10 @@ test "timeout_remove" {
1378 // Timeout remove operations set the fd to -1, which results in EBADF before EINVAL.1378 // Timeout remove operations set the fd to -1, which results in EBADF before EINVAL.
1379 // We use IORING_FEAT_RW_CUR_POS as a safety check here to make sure we are at least pre-5.6.1379 // We use IORING_FEAT_RW_CUR_POS as a safety check here to make sure we are at least pre-5.6.
1380 // We don't want to skip this test for newer kernels.1380 // We don't want to skip this test for newer kernels.
1381 if (1381 if (cqe_timeout.user_data == 0x99999999 and
1382 cqe_timeout.user_data == 0x99999999 and
1383 cqe_timeout.res == -linux.EBADF and1382 cqe_timeout.res == -linux.EBADF and
1384 (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 01383 (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0)
1385 ) {1384 {
1386 return error.SkipZigTest;1385 return error.SkipZigTest;
1387 }1386 }
1388 testing.expectEqual(linux.io_uring_cqe{1387 testing.expectEqual(linux.io_uring_cqe{