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 {
9494 /// The caller owns the returned memory. ArrayList becomes empty.
9595 pub fn toOwnedSliceSentinel(self: *Self, comptime sentinel: T) ![:sentinel]T {
9696 try self.append(sentinel);
97 const result = self.list.toOwnedSlice();
97 const result = self.toOwnedSlice();
9898 return result[0 .. result.len - 1 :sentinel];
9999 }
100100
......@@ -399,7 +399,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
399399 /// The caller owns the returned memory. ArrayList becomes empty.
400400 pub fn toOwnedSliceSentinel(self: *Self, allocator: *Allocator, comptime sentinel: T) ![:sentinel]T {
401401 try self.append(allocator, sentinel);
402 const result = self.list.toOwnedSlice(allocator);
402 const result = self.toOwnedSlice(allocator);
403403 return result[0 .. result.len - 1 :sentinel];
404404 }
405405
......@@ -1135,3 +1135,27 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" {
11351135 testing.expectEqualSlices(u8, list.items, "aoeuasdf");
11361136 }
11371137}
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
748748
749749/// Caller must dealloc.
750750fn 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);
752752 defer buf.deinit();
753 const buf_wi = buf.outStream();
754753
755754 for (argv) |arg, arg_i| {
756755 if (arg_i != 0) try buf.append(' ');
lib/std/io.zig+1
......@@ -209,6 +209,7 @@ test "" {
209209 _ = @import("io/buffered_writer.zig");
210210 _ = @import("io/c_writer.zig");
211211 _ = @import("io/counting_writer.zig");
212 _ = @import("io/counting_reader.zig");
212213 _ = @import("io/fixed_buffer_stream.zig");
213214 _ = @import("io/reader.zig");
214215 _ = @import("io/writer.zig");
lib/std/io/counting_reader.zig+9-9
......@@ -12,16 +12,16 @@ pub fn CountingReader(comptime ReaderType: anytype) type {
1212 return struct {
1313 child_reader: ReaderType,
1414 bytes_read: u64 = 0,
15
15
1616 pub const Error = ReaderType.Error;
1717 pub const Reader = io.Reader(*@This(), Error, read);
18
18
1919 pub fn read(self: *@This(), buf: []u8) Error!usize {
2020 const amt = try self.child_reader.read(buf);
2121 self.bytes_read += amt;
2222 return amt;
2323 }
24
24
2525 pub fn reader(self: *@This()) Reader {
2626 return .{ .context = self };
2727 }
......@@ -29,20 +29,20 @@ pub fn CountingReader(comptime ReaderType: anytype) type {
2929}
3030
3131pub fn countingReader(reader: anytype) CountingReader(@TypeOf(reader)) {
32 return .{ .child_reader = reader, };
32 return .{ .child_reader = reader };
3333}
3434
3535test "io.CountingReader" {
3636 const bytes = "yay" ** 100;
3737 var fbs = io.fixedBufferStream(bytes);
38
38
3939 var counting_stream = countingReader(fbs.reader());
4040 const stream = counting_stream.reader();
41
41
4242 //read and discard all bytes
43 while(stream.readByte()) |_| {} else |err| {
43 while (stream.readByte()) |_| {} else |err| {
4444 testing.expect(err == error.EndOfStream);
4545 }
46
46
4747 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:
15531553 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
15541554 switch (stringToken.escapes) {
15551555 .None => mem.copy(u8, &r, source_slice),
1556 .Some => try unescapeString(&r, source_slice),
1556 .Some => try unescapeValidString(&r, source_slice),
15571557 }
15581558 return r;
15591559 },
......@@ -1600,7 +1600,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
16001600 .Some => |some_escapes| {
16011601 const output = try allocator.alloc(u8, stringToken.decodedLength());
16021602 errdefer allocator.free(output);
1603 try unescapeString(output, source_slice);
1603 try unescapeValidString(output, source_slice);
16041604 return output;
16051605 },
16061606 }
......@@ -2084,7 +2084,7 @@ pub const Parser = struct {
20842084 .Some => |some_escapes| {
20852085 const output = try allocator.alloc(u8, s.decodedLength());
20862086 errdefer allocator.free(output);
2087 try unescapeString(output, slice);
2087 try unescapeValidString(output, slice);
20882088 return Value{ .String = output };
20892089 },
20902090 }
......@@ -2098,10 +2098,10 @@ pub const Parser = struct {
20982098 }
20992099};
21002100
2101// Unescape a JSON string
2102// Only to be used on strings already validated by the parser
2103// (note the unreachable statements and lack of bounds checking)
2104pub fn unescapeString(output: []u8, input: []const u8) !void {
2101/// Unescape a JSON string
2102/// Only to be used on strings already validated by the parser
2103/// (note the unreachable statements and lack of bounds checking)
2104pub fn unescapeValidString(output: []u8, input: []const u8) !void {
21052105 var inIndex: usize = 0;
21062106 var outIndex: usize = 0;
21072107
lib/std/os/linux/io_uring.zig+3-4
......@@ -1378,11 +1378,10 @@ test "timeout_remove" {
13781378 // Timeout remove operations set the fd to -1, which results in EBADF before EINVAL.
13791379 // We use IORING_FEAT_RW_CUR_POS as a safety check here to make sure we are at least pre-5.6.
13801380 // We don't want to skip this test for newer kernels.
1381 if (
1382 cqe_timeout.user_data == 0x99999999 and
1381 if (cqe_timeout.user_data == 0x99999999 and
13831382 cqe_timeout.res == -linux.EBADF and
1384 (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0
1385 ) {
1383 (ring.features & linux.IORING_FEAT_RW_CUR_POS) == 0)
1384 {
13861385 return error.SkipZigTest;
13871386 }
13881387 testing.expectEqual(linux.io_uring_cqe{