aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-06-26 18:29:19 -0400
committerGitHub <noreply@github.com>2019-06-26 18:29:19 -0400
commit01ff0d4d629c3800ebac68edfd91edb570aeaa59 (patch)
treefc1bdbf059e9bf9e99b212aae3056ed0e87e7e77 /std
parent07c0d484eec327ca3bd1e3ce081c1ced230536a9 (diff)
parent517bdea7549453d958c31cf2af5dc298ea5508a9 (diff)
downloadzig-01ff0d4d629c3800ebac68edfd91edb570aeaa59.tar.gz
zig-01ff0d4d629c3800ebac68edfd91edb570aeaa59.zip
Merge pull request #2602 from ziglang/copy-elision-3
result location mechanism (part of no-copy semantics)
Diffstat (limited to 'std')
-rw-r--r--std/event/fs.zig3
-rw-r--r--std/event/lock.zig1
-rw-r--r--std/event/net.zig4
-rw-r--r--std/event/rwlock.zig4
-rw-r--r--std/heap.zig4
-rw-r--r--std/io.zig20
-rw-r--r--std/io/test.zig5
-rw-r--r--std/json.zig3
-rw-r--r--std/os/windows.zig2
-rw-r--r--std/special/bootstrap.zig8
-rw-r--r--std/special/compiler_rt/comparetf2.zig15
-rw-r--r--std/special/panic.zig7
-rw-r--r--std/zig/parser_test.zig4
-rw-r--r--std/zig/render.zig6
14 files changed, 46 insertions, 40 deletions
diff --git a/std/event/fs.zig b/std/event/fs.zig
index 0f42375270..c25426b98a 100644
--- a/std/event/fs.zig
+++ b/std/event/fs.zig
@@ -1290,10 +1290,9 @@ pub fn Watch(comptime V: type) type {
error.FileDescriptorAlreadyPresentInSet => unreachable,
error.OperationCausesCircularLoop => unreachable,
error.FileDescriptorNotRegistered => unreachable,
- error.SystemResources => error.SystemResources,
- error.UserResourceLimitReached => error.UserResourceLimitReached,
error.FileDescriptorIncompatibleWithEpoll => unreachable,
error.Unexpected => unreachable,
+ else => |e| e,
};
await (async channel.put(transformed_err) catch unreachable);
};
diff --git a/std/event/lock.zig b/std/event/lock.zig
index a759c1e0a5..6c2b29b813 100644
--- a/std/event/lock.zig
+++ b/std/event/lock.zig
@@ -123,7 +123,6 @@ pub const Lock = struct {
};
test "std.event.Lock" {
- // https://github.com/ziglang/zig/issues/1908
if (builtin.single_threaded) return error.SkipZigTest;
const allocator = std.heap.direct_allocator;
diff --git a/std/event/net.zig b/std/event/net.zig
index 413bf1432c..46b724e32e 100644
--- a/std/event/net.zig
+++ b/std/event/net.zig
@@ -263,8 +263,8 @@ pub async fn connect(loop: *Loop, _address: *const std.net.Address) !File {
}
test "listen on a port, send bytes, receive bytes" {
- // https://github.com/ziglang/zig/issues/1908
- if (builtin.single_threaded) return error.SkipZigTest;
+ // https://github.com/ziglang/zig/issues/2377
+ if (true) return error.SkipZigTest;
if (builtin.os != builtin.Os.linux) {
// TODO build abstractions for other operating systems
diff --git a/std/event/rwlock.zig b/std/event/rwlock.zig
index 03e6f5ab92..7b97fa24c1 100644
--- a/std/event/rwlock.zig
+++ b/std/event/rwlock.zig
@@ -212,8 +212,8 @@ pub const RwLock = struct {
};
test "std.event.RwLock" {
- // https://github.com/ziglang/zig/issues/1908
- if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest;
+ // https://github.com/ziglang/zig/issues/2377
+ if (true) return error.SkipZigTest;
const allocator = std.heap.direct_allocator;
diff --git a/std/heap.zig b/std/heap.zig
index 648ba46252..c72c6456cd 100644
--- a/std/heap.zig
+++ b/std/heap.zig
@@ -360,9 +360,9 @@ pub const ArenaAllocator = struct {
var it = self.buffer_list.first;
while (it) |node| {
// this has to occur before the free because the free frees node
- it = node.next;
-
+ const next_it = node.next;
self.child_allocator.free(node.data);
+ it = next_it;
}
}
diff --git a/std/io.zig b/std/io.zig
index a02fb56e24..3a8da3ed3e 100644
--- a/std/io.zig
+++ b/std/io.zig
@@ -164,32 +164,32 @@ pub fn InStream(comptime ReadError: type) type {
/// Reads a native-endian integer
pub fn readIntNative(self: *Self, comptime T: type) !T {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
try self.readNoEof(bytes[0..]);
return mem.readIntNative(T, &bytes);
}
/// Reads a foreign-endian integer
pub fn readIntForeign(self: *Self, comptime T: type) !T {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
try self.readNoEof(bytes[0..]);
return mem.readIntForeign(T, &bytes);
}
pub fn readIntLittle(self: *Self, comptime T: type) !T {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
try self.readNoEof(bytes[0..]);
return mem.readIntLittle(T, &bytes);
}
pub fn readIntBig(self: *Self, comptime T: type) !T {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
try self.readNoEof(bytes[0..]);
return mem.readIntBig(T, &bytes);
}
pub fn readInt(self: *Self, comptime T: type, endian: builtin.Endian) !T {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
try self.readNoEof(bytes[0..]);
return mem.readInt(T, &bytes, endian);
}
@@ -249,32 +249,32 @@ pub fn OutStream(comptime WriteError: type) type {
/// Write a native-endian integer.
pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeIntNative(T, &bytes, value);
return self.writeFn(self, bytes);
}
/// Write a foreign-endian integer.
pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeIntForeign(T, &bytes, value);
return self.writeFn(self, bytes);
}
pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeIntLittle(T, &bytes, value);
return self.writeFn(self, bytes);
}
pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeIntBig(T, &bytes, value);
return self.writeFn(self, bytes);
}
pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {
- var bytes: [(T.bit_count + 7 )/ 8]u8 = undefined;
+ var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeInt(T, &bytes, value, endian);
return self.writeFn(self, bytes);
}
diff --git a/std/io/test.zig b/std/io/test.zig
index 4b25d645fc..40258eab5f 100644
--- a/std/io/test.zig
+++ b/std/io/test.zig
@@ -597,7 +597,10 @@ test "c out stream" {
const filename = c"tmp_io_test_file.txt";
const out_file = std.c.fopen(filename, c"w") orelse return error.UnableToOpenTestFile;
- defer fs.deleteFileC(filename) catch {};
+ defer {
+ _ = std.c.fclose(out_file);
+ fs.deleteFileC(filename) catch {};
+ }
const out_stream = &io.COutStream.init(out_file).stream;
try out_stream.print("hi: {}\n", i32(123));
diff --git a/std/json.zig b/std/json.zig
index 8d42d1bcf0..e135911170 100644
--- a/std/json.zig
+++ b/std/json.zig
@@ -876,8 +876,9 @@ pub const TokenStream = struct {
pub fn next(self: *TokenStream) !?Token {
if (self.token) |token| {
+ const copy = token;
self.token = null;
- return token;
+ return copy;
}
var t1: ?Token = undefined;
diff --git a/std/os/windows.zig b/std/os/windows.zig
index d10ab695db..ad5263dc0b 100644
--- a/std/os/windows.zig
+++ b/std/os/windows.zig
@@ -348,6 +348,7 @@ pub const DeleteFileError = error{
FileNotFound,
AccessDenied,
NameTooLong,
+ FileBusy,
Unexpected,
};
@@ -363,6 +364,7 @@ pub fn DeleteFileW(filename: [*]const u16) DeleteFileError!void {
ERROR.ACCESS_DENIED => return error.AccessDenied,
ERROR.FILENAME_EXCED_RANGE => return error.NameTooLong,
ERROR.INVALID_PARAMETER => return error.NameTooLong,
+ ERROR.SHARING_VIOLATION => return error.FileBusy,
else => |err| return unexpectedError(err),
}
}
diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig
index 45ce23c00f..f1286bd659 100644
--- a/std/special/bootstrap.zig
+++ b/std/special/bootstrap.zig
@@ -114,20 +114,20 @@ extern fn main(c_argc: i32, c_argv: [*][*]u8, c_envp: [*]?[*]u8) i32 {
// and we want fewer call frames in stack traces.
inline fn callMain() u8 {
switch (@typeId(@typeOf(root.main).ReturnType)) {
- builtin.TypeId.NoReturn => {
+ .NoReturn => {
root.main();
},
- builtin.TypeId.Void => {
+ .Void => {
root.main();
return 0;
},
- builtin.TypeId.Int => {
+ .Int => {
if (@typeOf(root.main).ReturnType.bit_count != 8) {
@compileError("expected return type of main to be 'u8', 'noreturn', 'void', or '!void'");
}
return root.main();
},
- builtin.TypeId.ErrorUnion => {
+ .ErrorUnion => {
root.main() catch |err| {
std.debug.warn("error: {}\n", @errorName(err));
if (builtin.os != builtin.Os.zen) {
diff --git a/std/special/compiler_rt/comparetf2.zig b/std/special/compiler_rt/comparetf2.zig
index 0912b71bd5..aaaba954d6 100644
--- a/std/special/compiler_rt/comparetf2.zig
+++ b/std/special/compiler_rt/comparetf2.zig
@@ -73,12 +73,15 @@ pub extern fn __getf2(a: f128, b: f128) c_int {
if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED;
if ((aAbs | bAbs) == 0) return GE_EQUAL;
- return if ((aInt & bInt) >= 0) if (aInt < bInt)
- GE_LESS
- else if (aInt == bInt)
- GE_EQUAL
- else
- GE_GREATER else if (aInt > bInt)
+ // zig fmt issue here, see https://github.com/ziglang/zig/issues/2661
+ return if ((aInt & bInt) >= 0)
+ if (aInt < bInt)
+ GE_LESS
+ else if (aInt == bInt)
+ GE_EQUAL
+ else
+ GE_GREATER
+ else if (aInt > bInt)
GE_LESS
else if (aInt == bInt)
GE_EQUAL
diff --git a/std/special/panic.zig b/std/special/panic.zig
index 40b1d5e7fe..92e0d9164c 100644
--- a/std/special/panic.zig
+++ b/std/special/panic.zig
@@ -9,16 +9,15 @@ const std = @import("std");
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
@setCold(true);
switch (builtin.os) {
- // TODO: fix panic in zen
- builtin.Os.freestanding, builtin.Os.zen => {
+ .freestanding => {
while (true) {}
},
- builtin.Os.wasi => {
+ .wasi => {
std.debug.warn("{}", msg);
_ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT);
unreachable;
},
- builtin.Os.uefi => {
+ .uefi => {
// TODO look into using the debug info and logging helpful messages
std.os.abort();
},
diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig
index 3998ca5070..f78e666779 100644
--- a/std/zig/parser_test.zig
+++ b/std/zig/parser_test.zig
@@ -1,4 +1,4 @@
-// TODO remove `use` keyword eventually
+// TODO remove `use` keyword eventually: https://github.com/ziglang/zig/issues/2591
test "zig fmt: change use to usingnamespace" {
try testTransform(
\\use @import("std");
@@ -1105,7 +1105,7 @@ test "zig fmt: first line comment in struct initializer" {
try testCanonical(
\\pub async fn acquire(self: *Self) HeldLock {
\\ return HeldLock{
- \\ // TODO guaranteed allocation elision
+ \\ // guaranteed allocation elision
\\ .held = await (async self.lock.acquire() catch unreachable),
\\ .value = &self.private_data,
\\ };
diff --git a/std/zig/render.zig b/std/zig/render.zig
index ef5c8f2346..2e8e4481be 100644
--- a/std/zig/render.zig
+++ b/std/zig/render.zig
@@ -939,10 +939,10 @@ fn renderExpression(
}
switch (container_decl.init_arg_expr) {
- ast.Node.ContainerDecl.InitArg.None => {
+ .None => {
try renderToken(tree, stream, container_decl.kind_token, indent, start_col, Space.Space); // union
},
- ast.Node.ContainerDecl.InitArg.Enum => |enum_tag_type| {
+ .Enum => |enum_tag_type| {
try renderToken(tree, stream, container_decl.kind_token, indent, start_col, Space.None); // union
const lparen = tree.nextToken(container_decl.kind_token);
@@ -962,7 +962,7 @@ fn renderExpression(
try renderToken(tree, stream, tree.nextToken(enum_token), indent, start_col, Space.Space); // )
}
},
- ast.Node.ContainerDecl.InitArg.Type => |type_expr| {
+ .Type => |type_expr| {
try renderToken(tree, stream, container_decl.kind_token, indent, start_col, Space.None); // union
const lparen = tree.nextToken(container_decl.kind_token);