Skip to content

Commit b3e34c4

Browse files
committed
Merge branch 'ziglang:master' into rename_offsetOf
2 parents 1c44f34 + a3f7a48 commit b3e34c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+940
-385
lines changed

doc/langref.html.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
color: #bbb;
134134
}
135135
a {
136-
color: #88f;
136+
color: #f7a31d;
137137
}
138138
table, th, td {
139139
border-color: grey;
@@ -193,7 +193,7 @@
193193
<a href="https://ziglang.org/documentation/0.4.0/">0.4.0</a> |
194194
<a href="https://ziglang.org/documentation/0.5.0/">0.5.0</a> |
195195
<a href="https://ziglang.org/documentation/0.6.0/">0.6.0</a> |
196-
<a href="https://ziglang.org/documentation/0.7.0/">0.7.0</a> |
196+
<a href="https://ziglang.org/documentation/0.7.1/">0.7.1</a> |
197197
<a href="https://ziglang.org/documentation/0.8.0/">0.8.0</a> |
198198
master
199199
<h1>Contents</h1>
@@ -220,10 +220,6 @@
220220
all on one page so you can search with your browser's search tool.
221221
</p>
222222
<p>
223-
If you search for something specific in this documentation and do not find it,
224-
please <a href="https://github.com/ziglang/www.ziglang.org/issues/new?title=I%20searched%20for%20___%20in%20the%20docs%20and%20didn%27t%20find%20it">file an issue</a> or <a href="https://webchat.freenode.net/?channels=%23zig">say something on IRC</a>.
225-
</p>
226-
<p>
227223
The code samples in this document are compiled and tested as part of the main test suite of Zig.
228224
</p>
229225
<p>

lib/std/Progress.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ fn refreshWithHeldLock(self: *Progress) void {
234234
self.terminal = null;
235235
break :winapi;
236236
}
237-
if (windows.kernel32.FillConsoleOutputCharacterA(
237+
if (windows.kernel32.FillConsoleOutputCharacterW(
238238
file.handle,
239239
' ',
240240
fill_chars,

lib/std/crypto/aes.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ test "expand 128-bit key" {
115115
"2b7e151628aed2a6abf7158809cf4f3c", "a0fafe1788542cb123a339392a6c7605", "f2c295f27a96b9435935807a7359f67f", "3d80477d4716fe3e1e237e446d7a883b", "ef44a541a8525b7fb671253bdb0bad00", "d4d1c6f87c839d87caf2b8bc11f915bc", "6d88a37a110b3efddbf98641ca0093fd", "4e54f70e5f5fc9f384a64fb24ea6dc4f", "ead27321b58dbad2312bf5607f8d292f", "ac7766f319fadc2128d12941575c006e", "d014f9a8c9ee2589e13f0cc8b6630ca6",
116116
};
117117
const exp_dec = [_]*const [32:0]u8{
118-
"2b7e151628aed2a6abf7158809cf4f3c", "a0fafe1788542cb123a339392a6c7605", "f2c295f27a96b9435935807a7359f67f", "3d80477d4716fe3e1e237e446d7a883b", "ef44a541a8525b7fb671253bdb0bad00", "d4d1c6f87c839d87caf2b8bc11f915bc", "6d88a37a110b3efddbf98641ca0093fd", "4e54f70e5f5fc9f384a64fb24ea6dc4f", "ead27321b58dbad2312bf5607f8d292f", "ac7766f319fadc2128d12941575c006e", "d014f9a8c9ee2589e13f0cc8b6630ca6",
118+
"d014f9a8c9ee2589e13f0cc8b6630ca6", "0c7b5a631319eafeb0398890664cfbb4", "df7d925a1f62b09da320626ed6757324", "12c07647c01f22c7bc42d2f37555114a", "6efcd876d2df54807c5df034c917c3b9", "6ea30afcbc238cf6ae82a4b4b54a338d", "90884413d280860a12a128421bc89739", "7c1f13f74208c219c021ae480969bf7b", "cc7505eb3e17d1ee82296c51c9481133", "2b3708a7f262d405bc3ebdbf4b617d62", "2b7e151628aed2a6abf7158809cf4f3c",
119119
};
120120
const enc = Aes128.initEnc(key);
121121
const dec = Aes128.initDec(key);
@@ -125,7 +125,7 @@ test "expand 128-bit key" {
125125
_ = try std.fmt.hexToBytes(&exp, exp_enc[i]);
126126
try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
127127
}
128-
for (enc.key_schedule.round_keys) |round_key, i| {
128+
for (dec.key_schedule.round_keys) |round_key, i| {
129129
_ = try std.fmt.hexToBytes(&exp, exp_dec[i]);
130130
try testing.expectEqualSlices(u8, &exp, &round_key.toBytes());
131131
}

lib/std/debug.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI
957957
}
958958

959959
/// TODO resources https://github.com/ziglang/zig/issues/4353
960-
/// This takes ownership of coff_file: users of this function should not close
960+
/// This takes ownership of macho_file: users of this function should not close
961961
/// it themselves, even on error.
962962
/// TODO it's weird to take ownership even on error, rework this code.
963963
fn readMachODebugInfo(allocator: *mem.Allocator, macho_file: File) !ModuleDebugInfo {

lib/std/fmt.zig

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,15 @@ pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @T
370370
.Pointer => |info| {
371371
try writer.writeAll(@typeName(info.child) ++ "@");
372372
if (info.size == .Slice)
373-
try formatInt(@ptrToInt(value.ptr), 16, false, FormatOptions{}, writer)
373+
try formatInt(@ptrToInt(value.ptr), 16, .lower, FormatOptions{}, writer)
374374
else
375-
try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);
375+
try formatInt(@ptrToInt(value), 16, .lower, FormatOptions{}, writer);
376376
return;
377377
},
378378
.Optional => |info| {
379379
if (@typeInfo(info.child) == .Pointer) {
380380
try writer.writeAll(@typeName(info.child) ++ "@");
381-
try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);
381+
try formatInt(@ptrToInt(value), 16, .lower, FormatOptions{}, writer);
382382
return;
383383
}
384384
},
@@ -651,7 +651,7 @@ pub fn formatIntValue(
651651
writer: anytype,
652652
) !void {
653653
comptime var radix = 10;
654-
comptime var uppercase = false;
654+
comptime var case: Case = .lower;
655655

656656
const int_value = if (@TypeOf(value) == comptime_int) blk: {
657657
const Int = math.IntFittingRange(value, value);
@@ -660,7 +660,7 @@ pub fn formatIntValue(
660660

661661
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "d")) {
662662
radix = 10;
663-
uppercase = false;
663+
case = .lower;
664664
} else if (comptime std.mem.eql(u8, fmt, "c")) {
665665
if (@typeInfo(@TypeOf(int_value)).Int.bits <= 8) {
666666
return formatAsciiChar(@as(u8, int_value), options, writer);
@@ -675,21 +675,21 @@ pub fn formatIntValue(
675675
}
676676
} else if (comptime std.mem.eql(u8, fmt, "b")) {
677677
radix = 2;
678-
uppercase = false;
678+
case = .lower;
679679
} else if (comptime std.mem.eql(u8, fmt, "x")) {
680680
radix = 16;
681-
uppercase = false;
681+
case = .lower;
682682
} else if (comptime std.mem.eql(u8, fmt, "X")) {
683683
radix = 16;
684-
uppercase = true;
684+
case = .upper;
685685
} else if (comptime std.mem.eql(u8, fmt, "o")) {
686686
radix = 8;
687-
uppercase = false;
687+
case = .lower;
688688
} else {
689689
@compileError("Unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
690690
}
691691

692-
return formatInt(int_value, radix, uppercase, options, writer);
692+
return formatInt(int_value, radix, case, options, writer);
693693
}
694694

695695
fn formatFloatValue(
@@ -724,8 +724,10 @@ fn formatFloatValue(
724724
return formatBuf(buf_stream.getWritten(), options, writer);
725725
}
726726

727-
fn formatSliceHexImpl(comptime uppercase: bool) type {
728-
const charset = "0123456789" ++ if (uppercase) "ABCDEF" else "abcdef";
727+
pub const Case = enum { lower, upper };
728+
729+
fn formatSliceHexImpl(comptime case: Case) type {
730+
const charset = "0123456789" ++ if (case == .upper) "ABCDEF" else "abcdef";
729731

730732
return struct {
731733
pub fn f(
@@ -745,23 +747,23 @@ fn formatSliceHexImpl(comptime uppercase: bool) type {
745747
};
746748
}
747749

748-
const formatSliceHexLower = formatSliceHexImpl(false).f;
749-
const formatSliceHexUpper = formatSliceHexImpl(true).f;
750+
const formatSliceHexLower = formatSliceHexImpl(.lower).f;
751+
const formatSliceHexUpper = formatSliceHexImpl(.upper).f;
750752

751753
/// Return a Formatter for a []const u8 where every byte is formatted as a pair
752754
/// of lowercase hexadecimal digits.
753755
pub fn fmtSliceHexLower(bytes: []const u8) std.fmt.Formatter(formatSliceHexLower) {
754756
return .{ .data = bytes };
755757
}
756758

757-
/// Return a Formatter for a []const u8 where every byte is formatted as a pair
759+
/// Return a Formatter for a []const u8 where every byte is formatted as pair
758760
/// of uppercase hexadecimal digits.
759761
pub fn fmtSliceHexUpper(bytes: []const u8) std.fmt.Formatter(formatSliceHexUpper) {
760762
return .{ .data = bytes };
761763
}
762764

763-
fn formatSliceEscapeImpl(comptime uppercase: bool) type {
764-
const charset = "0123456789" ++ if (uppercase) "ABCDEF" else "abcdef";
765+
fn formatSliceEscapeImpl(comptime case: Case) type {
766+
const charset = "0123456789" ++ if (case == .upper) "ABCDEF" else "abcdef";
765767

766768
return struct {
767769
pub fn f(
@@ -788,8 +790,8 @@ fn formatSliceEscapeImpl(comptime uppercase: bool) type {
788790
};
789791
}
790792

791-
const formatSliceEscapeLower = formatSliceEscapeImpl(false).f;
792-
const formatSliceEscapeUpper = formatSliceEscapeImpl(true).f;
793+
const formatSliceEscapeLower = formatSliceEscapeImpl(.lower).f;
794+
const formatSliceEscapeUpper = formatSliceEscapeImpl(.upper).f;
793795

794796
/// Return a Formatter for a []const u8 where every non-printable ASCII
795797
/// character is escaped as \xNN, where NN is the character in lowercase
@@ -1034,13 +1036,13 @@ pub fn formatFloatScientific(
10341036
if (exp > -10 and exp < 10) {
10351037
try writer.writeAll("0");
10361038
}
1037-
try formatInt(exp, 10, false, FormatOptions{ .width = 0 }, writer);
1039+
try formatInt(exp, 10, .lower, FormatOptions{ .width = 0 }, writer);
10381040
} else {
10391041
try writer.writeAll("-");
10401042
if (exp > -10 and exp < 10) {
10411043
try writer.writeAll("0");
10421044
}
1043-
try formatInt(-exp, 10, false, FormatOptions{ .width = 0 }, writer);
1045+
try formatInt(-exp, 10, .lower, FormatOptions{ .width = 0 }, writer);
10441046
}
10451047
}
10461048

@@ -1133,7 +1135,7 @@ pub fn formatFloatHexadecimal(
11331135

11341136
// +1 for the decimal part.
11351137
var buf: [1 + mantissa_digits]u8 = undefined;
1136-
const N = formatIntBuf(&buf, mantissa, 16, false, .{ .fill = '0', .width = 1 + mantissa_digits });
1138+
const N = formatIntBuf(&buf, mantissa, 16, .lower, .{ .fill = '0', .width = 1 + mantissa_digits });
11371139

11381140
try writer.writeAll("0x");
11391141
try writer.writeByte(buf[0]);
@@ -1150,7 +1152,7 @@ pub fn formatFloatHexadecimal(
11501152
try writer.writeByteNTimes('0', precision - trimmed.len);
11511153
};
11521154
try writer.writeAll("p");
1153-
try formatInt(exponent - exponent_bias, 10, false, .{}, writer);
1155+
try formatInt(exponent - exponent_bias, 10, .lower, .{}, writer);
11541156
}
11551157

11561158
/// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.
@@ -1299,7 +1301,7 @@ pub fn formatFloatDecimal(
12991301
pub fn formatInt(
13001302
value: anytype,
13011303
base: u8,
1302-
uppercase: bool,
1304+
case: Case,
13031305
options: FormatOptions,
13041306
writer: anytype,
13051307
) !void {
@@ -1326,7 +1328,7 @@ pub fn formatInt(
13261328
while (true) {
13271329
const digit = a % base;
13281330
index -= 1;
1329-
buf[index] = digitToChar(@intCast(u8, digit), uppercase);
1331+
buf[index] = digitToChar(@intCast(u8, digit), case);
13301332
a /= base;
13311333
if (a == 0) break;
13321334
}
@@ -1348,9 +1350,9 @@ pub fn formatInt(
13481350
return formatBuf(buf[index..], options, writer);
13491351
}
13501352

1351-
pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) usize {
1353+
pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, case: Case, options: FormatOptions) usize {
13521354
var fbs = std.io.fixedBufferStream(out_buf);
1353-
formatInt(value, base, uppercase, options, fbs.writer()) catch unreachable;
1355+
formatInt(value, base, case, options, fbs.writer()) catch unreachable;
13541356
return fbs.pos;
13551357
}
13561358

@@ -1365,7 +1367,7 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti
13651367
}) |unit| {
13661368
if (ns_remaining >= unit.ns) {
13671369
const units = ns_remaining / unit.ns;
1368-
try formatInt(units, 10, false, .{}, writer);
1370+
try formatInt(units, 10, .lower, .{}, writer);
13691371
try writer.writeByte(unit.sep);
13701372
ns_remaining -= units * unit.ns;
13711373
if (ns_remaining == 0) return;
@@ -1379,12 +1381,12 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti
13791381
}) |unit| {
13801382
const kunits = ns_remaining * 1000 / unit.ns;
13811383
if (kunits >= 1000) {
1382-
try formatInt(kunits / 1000, 10, false, .{}, writer);
1384+
try formatInt(kunits / 1000, 10, .lower, .{}, writer);
13831385
const frac = kunits % 1000;
13841386
if (frac > 0) {
13851387
// Write up to 3 decimal places
13861388
var buf = [_]u8{ '.', 0, 0, 0 };
1387-
_ = formatIntBuf(buf[1..], frac, 10, false, .{ .fill = '0', .width = 3 });
1389+
_ = formatIntBuf(buf[1..], frac, 10, .lower, .{ .fill = '0', .width = 3 });
13881390
var end: usize = 4;
13891391
while (end > 1) : (end -= 1) {
13901392
if (buf[end - 1] != '0') break;
@@ -1396,7 +1398,7 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti
13961398
}
13971399
}
13981400

1399-
try formatInt(ns_remaining, 10, false, .{}, writer);
1401+
try formatInt(ns_remaining, 10, .lower, .{}, writer);
14001402
try writer.writeAll("ns");
14011403
return;
14021404
}
@@ -1673,10 +1675,10 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
16731675
return value;
16741676
}
16751677

1676-
pub fn digitToChar(digit: u8, uppercase: bool) u8 {
1678+
pub fn digitToChar(digit: u8, case: Case) u8 {
16771679
return switch (digit) {
16781680
0...9 => digit + '0',
1679-
10...35 => digit + ((if (uppercase) @as(u8, 'A') else @as(u8, 'a')) - 10),
1681+
10...35 => digit + ((if (case == .upper) @as(u8, 'A') else @as(u8, 'a')) - 10),
16801682
else => unreachable,
16811683
};
16821684
}
@@ -1728,25 +1730,25 @@ test "bufPrintInt" {
17281730
var buffer: [100]u8 = undefined;
17291731
const buf = buffer[0..];
17301732

1731-
try std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{}));
1733+
try std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, .lower, FormatOptions{}));
17321734

1733-
try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));
1734-
try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));
1735-
try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));
1736-
try std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));
1735+
try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, .lower, FormatOptions{}));
1736+
try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, .lower, FormatOptions{}));
1737+
try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, .lower, FormatOptions{}));
1738+
try std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, .upper, FormatOptions{}));
17371739

1738-
try std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}));
1740+
try std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, .upper, FormatOptions{}));
17391741

1740-
try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }));
1741-
try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));
1742-
try std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }));
1742+
try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, .lower, FormatOptions{ .width = 6 }));
1743+
try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, .lower, FormatOptions{ .width = 6 }));
1744+
try std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, .lower, FormatOptions{ .width = 1 }));
17431745

1744-
try std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }));
1745-
try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));
1746+
try std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, .lower, FormatOptions{ .width = 3 }));
1747+
try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, .lower, FormatOptions{ .width = 3 }));
17461748
}
17471749

1748-
pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {
1749-
return buf[0..formatIntBuf(buf, value, base, uppercase, options)];
1750+
pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, case: Case, options: FormatOptions) []u8 {
1751+
return buf[0..formatIntBuf(buf, value, base, case, options)];
17501752
}
17511753

17521754
pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8 {
@@ -2412,10 +2414,6 @@ test "vector" {
24122414
// https://github.com/ziglang/zig/issues/4486
24132415
return error.SkipZigTest;
24142416
}
2415-
if (builtin.target.cpu.arch == .wasm32) {
2416-
// https://github.com/ziglang/zig/issues/5339
2417-
return error.SkipZigTest;
2418-
}
24192417

24202418
const vbool: std.meta.Vector(4, bool) = [_]bool{ true, false, true, false };
24212419
const vi64: std.meta.Vector(4, i64) = [_]i64{ -2, -1, 0, 1 };

lib/std/heap.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const maxInt = std.math.maxInt;
1616

1717
pub const LoggingAllocator = @import("heap/logging_allocator.zig").LoggingAllocator;
1818
pub const loggingAllocator = @import("heap/logging_allocator.zig").loggingAllocator;
19+
pub const ScopedLoggingAllocator = @import("heap/logging_allocator.zig").ScopedLoggingAllocator;
20+
pub const LogToWriterAllocator = @import("heap/log_to_writer_allocator.zig").LogToWriterAllocator;
21+
pub const logToWriterAllocator = @import("heap/log_to_writer_allocator.zig").logToWriterAllocator;
1922
pub const ArenaAllocator = @import("heap/arena_allocator.zig").ArenaAllocator;
2023
pub const GeneralPurposeAllocator = @import("heap/general_purpose_allocator.zig").GeneralPurposeAllocator;
2124

@@ -1162,4 +1165,5 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) !void {
11621165

11631166
test "heap" {
11641167
_ = @import("heap/logging_allocator.zig");
1168+
_ = @import("heap/log_to_writer_allocator.zig");
11651169
}

0 commit comments

Comments
 (0)