aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-09-06 19:06:09 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-09-06 19:45:02 -0700
commitb7900de1684021ff86c67105e14e34968821ea02 (patch)
treeb881a288071705ffb8cd65ede5f8e7a1452b6dce /lib/std
parent20145016ac0d098e8e63d5107a05eca376d1e7bb (diff)
parente2bb92b2e27dc54852a0227345e294ae383358fd (diff)
downloadzig-b7900de1684021ff86c67105e14e34968821ea02.tar.gz
zig-b7900de1684021ff86c67105e14e34968821ea02.zip
Merge remote-tracking branch 'origin/master' into llvm15
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Thread.zig7
-rw-r--r--lib/std/coff.zig85
-rw-r--r--lib/std/log.zig2
-rw-r--r--lib/std/math/big/rational.zig16
-rw-r--r--lib/std/os.zig4
-rw-r--r--lib/std/zig/c_translation.zig2
-rw-r--r--lib/std/zig/parser_test.zig37
-rw-r--r--lib/std/zig/render.zig25
8 files changed, 163 insertions, 15 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig
index d52515b88d..20985c36a0 100644
--- a/lib/std/Thread.zig
+++ b/lib/std/Thread.zig
@@ -769,16 +769,13 @@ const LinuxThreadImpl = struct {
),
.x86_64 => asm volatile (
\\ movq $11, %%rax
- \\ movq %[ptr], %%rbx
- \\ movq %[len], %%rcx
\\ syscall
\\ movq $60, %%rax
\\ movq $1, %%rdi
\\ syscall
:
- : [ptr] "r" (@ptrToInt(self.mapped.ptr)),
- [len] "r" (self.mapped.len),
- : "memory"
+ : [ptr] "{rdi}" (@ptrToInt(self.mapped.ptr)),
+ [len] "{rsi}" (self.mapped.len),
),
.arm, .armeb, .thumb, .thumbeb => asm volatile (
\\ mov r7, #91
diff --git a/lib/std/coff.zig b/lib/std/coff.zig
index 1caec57c4a..ad440e7757 100644
--- a/lib/std/coff.zig
+++ b/lib/std/coff.zig
@@ -419,6 +419,91 @@ pub const DebugType = enum(u32) {
EX_DLLCHARACTERISTICS = 20,
};
+pub const ImportDirectoryEntry = extern struct {
+ /// The RVA of the import lookup table.
+ /// This table contains a name or ordinal for each import.
+ /// (The name "Characteristics" is used in Winnt.h, but no longer describes this field.)
+ import_lookup_table_rva: u32,
+
+ /// The stamp that is set to zero until the image is bound.
+ /// After the image is bound, this field is set to the time/data stamp of the DLL.
+ time_date_stamp: u32,
+
+ /// The index of the first forwarder reference.
+ forwarder_chain: u32,
+
+ /// The address of an ASCII string that contains the name of the DLL.
+ /// This address is relative to the image base.
+ name_rva: u32,
+
+ /// The RVA of the import address table.
+ /// The contents of this table are identical to the contents of the import lookup table until the image is bound.
+ import_address_table_rva: u32,
+};
+
+pub const ImportLookupEntry32 = struct {
+ pub const ByName = packed struct {
+ name_table_rva: u31,
+ flag: u1 = 0,
+ };
+
+ pub const ByOrdinal = packed struct {
+ ordinal_number: u16,
+ unused: u15 = 0,
+ flag: u1 = 1,
+ };
+
+ const mask = 0x80000000;
+
+ pub fn getImportByName(raw: u32) ?ByName {
+ if (mask & raw != 0) return null;
+ return @bitCast(ByName, raw);
+ }
+
+ pub fn getImportByOrdinal(raw: u32) ?ByOrdinal {
+ if (mask & raw == 0) return null;
+ return @bitCast(ByOrdinal, raw);
+ }
+};
+
+pub const ImportLookupEntry64 = struct {
+ pub const ByName = packed struct {
+ name_table_rva: u31,
+ unused: u32 = 0,
+ flag: u1 = 0,
+ };
+
+ pub const ByOrdinal = packed struct {
+ ordinal_number: u16,
+ unused: u47 = 0,
+ flag: u1 = 1,
+ };
+
+ const mask = 0x8000000000000000;
+
+ pub fn getImportByName(raw: u64) ?ByName {
+ if (mask & raw != 0) return null;
+ return @bitCast(ByName, raw);
+ }
+
+ pub fn getImportByOrdinal(raw: u64) ?ByOrdinal {
+ if (mask & raw == 0) return null;
+ return @bitCast(ByOrdinal, raw);
+ }
+};
+
+/// Every name ends with a NULL byte. IF the NULL byte does not fall on
+/// 2byte boundary, the entry structure is padded to ensure 2byte alignment.
+pub const ImportHintNameEntry = extern struct {
+ /// An index into the export name pointer table.
+ /// A match is attempted first with this value. If it fails, a binary search is performed on the DLL's export name pointer table.
+ hint: u16,
+
+ /// Pointer to NULL terminated ASCII name.
+ /// Variable length...
+ name: [1]u8,
+};
+
pub const SectionHeader = extern struct {
name: [8]u8,
virtual_size: u32,
diff --git a/lib/std/log.zig b/lib/std/log.zig
index 081344f2c8..e0e002d600 100644
--- a/lib/std/log.zig
+++ b/lib/std/log.zig
@@ -38,7 +38,7 @@
//! return,
//! } ++ "): ";
//!
-//! const prefix = "[" ++ level.asText() ++ "] " ++ scope_prefix;
+//! const prefix = "[" ++ comptime level.asText() ++ "] " ++ scope_prefix;
//!
//! // Print the message to stderr, silently ignoring any errors
//! std.debug.getStderrMutex().lock();
diff --git a/lib/std/math/big/rational.zig b/lib/std/math/big/rational.zig
index 895b20d9b5..61e2194eea 100644
--- a/lib/std/math/big/rational.zig
+++ b/lib/std/math/big/rational.zig
@@ -334,13 +334,13 @@ pub const Rational = struct {
/// Returns math.Order.lt, math.Order.eq, math.Order.gt if a < b, a == b or a
/// > b respectively.
pub fn order(a: Rational, b: Rational) !math.Order {
- return cmpInternal(a, b, true);
+ return cmpInternal(a, b, false);
}
/// Returns math.Order.lt, math.Order.eq, math.Order.gt if |a| < |b|, |a| ==
/// |b| or |a| > |b| respectively.
pub fn orderAbs(a: Rational, b: Rational) !math.Order {
- return cmpInternal(a, b, false);
+ return cmpInternal(a, b, true);
}
// p/q > x/y iff p*y > x*q
@@ -704,6 +704,18 @@ test "big.rational order" {
try testing.expect((try a.order(b)) == .eq);
}
+test "big.rational order/orderAbs with negative" {
+ var a = try Rational.init(testing.allocator);
+ defer a.deinit();
+ var b = try Rational.init(testing.allocator);
+ defer b.deinit();
+
+ try a.setRatio(1, 1);
+ try b.setRatio(-2, 1);
+ try testing.expect((try a.order(b)) == .gt);
+ try testing.expect((try a.orderAbs(b)) == .lt);
+}
+
test "big.rational add single-limb" {
var a = try Rational.init(testing.allocator);
defer a.deinit();
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 59f2a2173f..a707331a47 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -3447,6 +3447,9 @@ pub const BindError = error{
/// A nonexistent interface was requested or the requested address was not local.
AddressNotAvailable,
+ /// The address is not valid for the address family of socket.
+ AddressFamilyNotSupported,
+
/// Too many symbolic links were encountered in resolving addr.
SymLinkLoop,
@@ -3502,6 +3505,7 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi
.BADF => unreachable, // always a race condition if this error is returned
.INVAL => unreachable, // invalid parameters
.NOTSOCK => unreachable, // invalid `sockfd`
+ .AFNOSUPPORT => return error.AddressFamilyNotSupported,
.ADDRNOTAVAIL => return error.AddressNotAvailable,
.FAULT => unreachable, // invalid `addr` pointer
.LOOP => return error.SymLinkLoop,
diff --git a/lib/std/zig/c_translation.zig b/lib/std/zig/c_translation.zig
index 348e3a7133..6847a92eae 100644
--- a/lib/std/zig/c_translation.zig
+++ b/lib/std/zig/c_translation.zig
@@ -268,7 +268,7 @@ test "sizeof" {
pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
fn PromoteIntLiteralReturnType(comptime SuffixType: type, comptime number: comptime_int, comptime radix: CIntLiteralRadix) type {
- const signed_decimal = [_]type{ c_int, c_long, c_longlong };
+ const signed_decimal = [_]type{ c_int, c_long, c_longlong, c_ulonglong };
const signed_oct_hex = [_]type{ c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong };
const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index 2bb8c848bc..0e1817ffab 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -16,6 +16,28 @@ test "zig fmt: preserves clobbers in inline asm with stray comma" {
);
}
+test "zig fmt: remove trailing comma at the end of assembly clobber" {
+ try testTransform(
+ \\fn foo() void {
+ \\ asm volatile (""
+ \\ : [_] "" (-> type),
+ \\ :
+ \\ : "clobber1", "clobber2",
+ \\ );
+ \\}
+ \\
+ ,
+ \\fn foo() void {
+ \\ asm volatile (""
+ \\ : [_] "" (-> type),
+ \\ :
+ \\ : "clobber1", "clobber2"
+ \\ );
+ \\}
+ \\
+ );
+}
+
test "zig fmt: respect line breaks in struct field value declaration" {
try testCanonical(
\\const Foo = struct {
@@ -5035,6 +5057,21 @@ test "zig fmt: make single-line if no trailing comma" {
);
}
+test "zig fmt: preserve container doc comment in container without trailing comma" {
+ try testTransform(
+ \\const A = enum(u32) {
+ \\//! comment
+ \\_ };
+ \\
+ ,
+ \\const A = enum(u32) {
+ \\ //! comment
+ \\ _,
+ \\};
+ \\
+ );
+}
+
test "zig fmt: make single-line if no trailing comma" {
try testCanonical(
\\// Test trailing comma syntax
diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig
index 03f951d0f1..bc59ddc279 100644
--- a/lib/std/zig/render.zig
+++ b/lib/std/zig/render.zig
@@ -1933,12 +1933,15 @@ fn renderContainerDecl(
break :one_line;
}
- // 2. A member of the container has a doc comment.
+ // 2. The container has a container comment.
+ if (token_tags[lbrace + 1] == .container_doc_comment) break :one_line;
+
+ // 3. A member of the container has a doc comment.
for (token_tags[lbrace + 1 .. rbrace - 1]) |tag| {
if (tag == .doc_comment) break :one_line;
}
- // 3. The container has non-field members.
+ // 4. The container has non-field members.
for (container_decl.ast.members) |member| {
if (!node_tags[member].isContainerField()) break :one_line;
}
@@ -2114,9 +2117,19 @@ fn renderAsm(
return renderToken(ais, tree, tok_i + 1, space);
},
.comma => {
- try renderToken(ais, tree, tok_i, .none);
- try renderToken(ais, tree, tok_i + 1, .space);
- tok_i += 2;
+ switch (token_tags[tok_i + 2]) {
+ .r_paren => {
+ ais.setIndentDelta(indent_delta);
+ ais.popIndent();
+ try renderToken(ais, tree, tok_i, .newline);
+ return renderToken(ais, tree, tok_i + 2, space);
+ },
+ else => {
+ try renderToken(ais, tree, tok_i, .none);
+ try renderToken(ais, tree, tok_i + 1, .space);
+ tok_i += 2;
+ },
+ }
},
else => unreachable,
}
@@ -2348,7 +2361,7 @@ fn renderSpace(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex, lexeme_len: us
}
}
-/// Returns true if there exists a comment between any of the tokens from
+/// Returns true if there exists a line comment between any of the tokens from
/// `start_token` to `end_token`. This is used to determine if e.g. a
/// fn_proto should be wrapped and have a trailing comma inserted even if
/// there is none in the source.