Skip to content

Commit 2d62411

Browse files
Merge branch 'master' into master
2 parents 58fbf12 + f78f70d commit 2d62411

File tree

18 files changed

+199
-47
lines changed

18 files changed

+199
-47
lines changed

lib/std/Build/Step/CheckObject.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,7 @@ const ElfDumper = struct {
22262226
try writer.print(" {s}", .{sym_bind});
22272227
}
22282228

2229-
const sym_vis = @as(elf.STV, @enumFromInt(@as(u2, @truncate(sym.st_other))));
2229+
const sym_vis = @as(elf.STV, @enumFromInt(@as(u3, @truncate(sym.st_other))));
22302230
try writer.print(" {s}", .{@tagName(sym_vis)});
22312231

22322232
const sym_name = switch (sym.st_type()) {

lib/std/c.zig

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,6 +4171,39 @@ pub const msghdr_const = switch (native_os) {
41714171
},
41724172
else => void,
41734173
};
4174+
pub const cmsghdr = switch (native_os) {
4175+
// https://github.com/emscripten-core/emscripten/blob/96371ed7888fc78c040179f4d4faa82a6a07a116/system/lib/libc/musl/include/sys/socket.h#L44
4176+
.linux, .emscripten => linux.cmsghdr,
4177+
// https://github.com/freebsd/freebsd-src/blob/b197d2abcb6895d78bc9df8404e374397aa44748/sys/sys/socket.h#L492
4178+
.freebsd,
4179+
// https://github.com/DragonFlyBSD/DragonFlyBSD/blob/107c0518337ba90e7fa49e74845d8d44320c9a6d/sys/sys/socket.h#L452
4180+
.dragonfly,
4181+
// https://github.com/NetBSD/src/blob/ba8e1774fd9c0c26ecca461c07bc95d9ebb69579/sys/sys/socket.h#L528
4182+
.netbsd,
4183+
// https://github.com/openbsd/src/blob/master/sys/sys/socket.h#L527
4184+
.openbsd,
4185+
// https://github.com/kofemann/opensolaris/blob/80192cd83bf665e708269dae856f9145f7190f74/usr/src/uts/common/sys/socket.h#L416
4186+
.solaris,
4187+
// https://github.com/illumos/illumos-gate/blob/afdf2e523873cb523df379676067bf9785a0f456/usr/src/uts/common/sys/socket.h#L460
4188+
.illumos,
4189+
// https://github.com/SerenityOS/serenity/blob/4ee360a348a5e2490eeaeeabb3eb19e70dd450eb/Kernel/API/POSIX/sys/socket.h#L68
4190+
.serenity,
4191+
// https://github.com/haiku/haiku/blob/b54f586058fd6623645512e4631468cede9933b9/headers/posix/sys/socket.h#L132
4192+
.haiku,
4193+
// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/socket.h#L1041
4194+
.macos,
4195+
.driverkit,
4196+
.ios,
4197+
.tvos,
4198+
.visionos,
4199+
.watchos,
4200+
=> extern struct {
4201+
len: socklen_t,
4202+
level: c_int,
4203+
type: c_int,
4204+
},
4205+
else => void,
4206+
};
41744207
pub const nfds_t = switch (native_os) {
41754208
.linux => linux.nfds_t,
41764209
.emscripten => emscripten.nfds_t,
@@ -10353,7 +10386,7 @@ pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_
1035310386

1035410387
pub const arc4random_buf = switch (native_os) {
1035510388
.linux => if (builtin.abi.isAndroid()) private.arc4random_buf else {},
10356-
.dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .macos, .ios, .tvos, .watchos, .visionos => private.arc4random_buf,
10389+
.dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .serenity, .macos, .ios, .tvos, .watchos, .visionos => private.arc4random_buf,
1035710390
else => {},
1035810391
};
1035910392
pub const getentropy = switch (native_os) {
@@ -10756,6 +10789,8 @@ pub extern "c" fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) c_int;
1075610789
pub extern "c" fn setpgid(pid: pid_t, pgid: pid_t) c_int;
1075710790
pub extern "c" fn getuid() uid_t;
1075810791
pub extern "c" fn geteuid() uid_t;
10792+
pub extern "c" fn getresuid(ruid: *uid_t, euid: *uid_t, suid: *uid_t) c_int;
10793+
pub extern "c" fn getresgid(rgid: *gid_t, egid: *gid_t, sgid: *gid_t) c_int;
1075910794

1076010795
pub extern "c" fn malloc(usize) ?*anyopaque;
1076110796
pub extern "c" fn calloc(usize, usize) ?*anyopaque;
@@ -11008,7 +11043,6 @@ pub const SCM = solaris.SCM;
1100811043
pub const SETCONTEXT = solaris.SETCONTEXT;
1100911044
pub const SETUSTACK = solaris.GETUSTACK;
1101011045
pub const SFD = solaris.SFD;
11011-
pub const cmsghdr = solaris.cmsghdr;
1101211046
pub const ctid_t = solaris.ctid_t;
1101311047
pub const file_obj = solaris.file_obj;
1101411048
pub const fpregset_t = solaris.fpregset_t;

lib/std/c/dragonfly.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ pub const BADSIG = SIG.ERR;
158158

159159
pub const sig_t = *const fn (i32) callconv(.c) void;
160160

161-
pub const cmsghdr = extern struct {
162-
len: socklen_t,
163-
level: c_int,
164-
type: c_int,
165-
};
166-
167161
pub const cmsgcred = extern struct {
168162
pid: pid_t,
169163
uid: uid_t,

lib/std/c/solaris.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ pub const poolid_t = id_t;
3131
pub const zoneid_t = id_t;
3232
pub const ctid_t = id_t;
3333

34-
pub const cmsghdr = extern struct {
35-
len: socklen_t,
36-
level: i32,
37-
type: i32,
38-
};
39-
4034
pub const SCM = struct {
4135
pub const UCRED = 0x1012;
4236
pub const RIGHTS = 0x1010;

lib/std/compress/lzma2.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ pub const Decode = struct {
233233

234234
while (true) {
235235
if (accum.len >= expected_unpacked_size) break;
236-
if (range_decoder.isFinished()) break;
237236
switch (try ld.process(reader, allocating, accum, &range_decoder, &n_read)) {
238237
.more => continue,
239238
.finished => break,

lib/std/debug.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ pub const runtime_safety = switch (builtin.mode) {
169169
pub const sys_can_stack_trace = switch (builtin.cpu.arch) {
170170
// Observed to go into an infinite loop.
171171
// TODO: Make this work.
172+
.loongarch32,
173+
.loongarch64,
172174
.mips,
173175
.mipsel,
174176
.mips64,

lib/std/elf.zig

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,17 +1122,17 @@ pub const OSABI = enum(u8) {
11221122
CLOUDABI = 17,
11231123
/// Stratus Technologies OpenVOS
11241124
OPENVOS = 18,
1125-
/// NVIDIA CUDA architecture
1125+
/// NVIDIA CUDA architecture (not gABI assigned)
11261126
CUDA = 51,
1127-
/// AMD HSA Runtime
1127+
/// AMD HSA Runtime (not gABI assigned)
11281128
AMDGPU_HSA = 64,
1129-
/// AMD PAL Runtime
1129+
/// AMD PAL Runtime (not gABI assigned)
11301130
AMDGPU_PAL = 65,
1131-
/// AMD Mesa3D Runtime
1131+
/// AMD Mesa3D Runtime (not gABI assigned)
11321132
AMDGPU_MESA3D = 66,
1133-
/// ARM
1133+
/// ARM (not gABI assigned)
11341134
ARM = 97,
1135-
/// Standalone (embedded) application
1135+
/// Standalone (embedded) application (not gABI assigned)
11361136
STANDALONE = 255,
11371137

11381138
_,
@@ -1165,11 +1165,11 @@ pub const EM = enum(u16) {
11651165
S370 = 9,
11661166
/// MIPS R3000 (and R4000) little-endian, Oct 4 1993 Draft (deprecated)
11671167
MIPS_RS3_LE = 10,
1168-
/// Old version of Sparc v9, from before the ABI (deprecated)
1168+
/// Old version of Sparc v9, from before the ABI (not gABI assigned)
11691169
OLD_SPARCV9 = 11,
11701170
/// HPPA
11711171
PARISC = 15,
1172-
/// Fujitsu VPP500 (also old version of PowerPC; deprecated)
1172+
/// Fujitsu VPP500 (also old version of PowerPC, which was not gABI assigned)
11731173
VPP500 = 17,
11741174
/// Sun's "v8plus"
11751175
SPARC32PLUS = 18,
@@ -1189,7 +1189,7 @@ pub const EM = enum(u16) {
11891189
FR20 = 37,
11901190
/// TRW RH32
11911191
RH32 = 38,
1192-
/// Motorola M*Core, aka RCE (also Fujitsu MMA)
1192+
/// Motorola M*Core, aka RCE (also old Fujitsu MMA, which was not gABI assigned)
11931193
MCORE = 39,
11941194
/// ARM
11951195
ARM = 40,
@@ -1301,15 +1301,15 @@ pub const EM = enum(u16) {
13011301
ARC_COMPACT = 93,
13021302
/// Tensilica Xtensa Architecture
13031303
XTENSA = 94,
1304-
/// Alphamosaic VideoCore processor (also old Sunplus S+core7 backend magic number)
1304+
/// Alphamosaic VideoCore processor (also old Sunplus S+core7 backend magic number, which was not gABI assigned)
13051305
VIDEOCORE = 95,
13061306
/// Thompson Multimedia General Purpose Processor
13071307
TMM_GPP = 96,
13081308
/// National Semiconductor 32000 series
13091309
NS32K = 97,
13101310
/// Tenor Network TPC processor
13111311
TPC = 98,
1312-
/// Trebia SNP 1000 processor (also old value for picoJava; deprecated)
1312+
/// Trebia SNP 1000 processor (also old value for picoJava, which was not gABI assigned)
13131313
SNP1K = 99,
13141314
/// STMicroelectronics ST200 microcontroller
13151315
ST200 = 100,
@@ -1341,7 +1341,7 @@ pub const EM = enum(u16) {
13411341
ALTERA_NIOS2 = 113,
13421342
/// National Semiconductor CRX
13431343
CRX = 114,
1344-
/// Motorola XGATE embedded processor (also old value for National Semiconductor CompactRISC; deprecated)
1344+
/// Motorola XGATE embedded processor (also old value for National Semiconductor CompactRISC, which was not gABI assigned)
13451345
XGATE = 115,
13461346
/// Infineon C16x/XC16x processor
13471347
C166 = 116,
@@ -1377,6 +1377,8 @@ pub const EM = enum(u16) {
13771377
TI_C2000 = 141,
13781378
/// Texas Instruments TMS320C55x DSP family
13791379
TI_C5500 = 142,
1380+
/// Texas Instruments Application Specific RISC Processor, 32bit fetch
1381+
TI_ARP32 = 143,
13801382
/// Texas Instruments Programmable Realtime Unit
13811383
TI_PRU = 144,
13821384
/// STMicroelectronics 64bit VLIW Data Signal Processor
@@ -1537,6 +1539,18 @@ pub const EM = enum(u16) {
15371539
TACHYUM = 261,
15381540
/// NXP 56800EF Digital Signal Controller (DSC)
15391541
@"56800EF" = 262,
1542+
/// Solana Bytecode Format
1543+
SBF = 263,
1544+
/// AMD/Xilinx AIEngine architecture
1545+
AIENGINE = 264,
1546+
/// SiMa MLA
1547+
SIMA_MLA = 265,
1548+
/// Cambricon BANG
1549+
BANG = 266,
1550+
/// Loongson LoongGPU
1551+
LOONGGPU = 267,
1552+
/// Wuxi Institute of Advanced Technology SW64
1553+
SW64 = 268,
15401554
/// AVR
15411555
AVR_OLD = 0x1057,
15421556
/// MSP430
@@ -2289,7 +2303,7 @@ pub const R_PPC64 = enum(u32) {
22892303
_,
22902304
};
22912305

2292-
pub const STV = enum(u2) {
2306+
pub const STV = enum(u3) {
22932307
DEFAULT = 0,
22942308
INTERNAL = 1,
22952309
HIDDEN = 2,

lib/std/fs/File.zig

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ pub const Writer = struct {
15051505
sendfile_err: ?SendfileError = null,
15061506
copy_file_range_err: ?CopyFileRangeError = null,
15071507
fcopyfile_err: ?FcopyfileError = null,
1508-
seek_err: ?SeekError = null,
1508+
seek_err: ?Writer.SeekError = null,
15091509
interface: std.Io.Writer,
15101510

15111511
pub const Mode = Reader.Mode;
@@ -1527,6 +1527,8 @@ pub const Writer = struct {
15271527
Unexpected,
15281528
};
15291529

1530+
pub const SeekError = File.SeekError;
1531+
15301532
/// Number of slices to store on the stack, when trying to send as many byte
15311533
/// vectors through the underlying write calls as possible.
15321534
const max_buffers_len = 16;
@@ -2000,7 +2002,14 @@ pub const Writer = struct {
20002002
return n;
20012003
}
20022004

2003-
pub fn seekTo(w: *Writer, offset: u64) SeekError!void {
2005+
pub fn seekTo(w: *Writer, offset: u64) (Writer.SeekError || std.Io.Writer.Error)!void {
2006+
try w.interface.flush();
2007+
try seekToUnbuffered(w, offset);
2008+
}
2009+
2010+
/// Asserts that no data is currently buffered.
2011+
pub fn seekToUnbuffered(w: *Writer, offset: u64) Writer.SeekError!void {
2012+
assert(w.interface.buffered().len == 0);
20042013
switch (w.mode) {
20052014
.positional, .positional_reading => {
20062015
w.pos = offset;

lib/std/fs/test.zig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,3 +2155,28 @@ test "seekBy" {
21552155
try testing.expectEqual(15, n);
21562156
try testing.expectEqualStrings("t's test seekBy", buffer[0..15]);
21572157
}
2158+
2159+
test "seekTo flushes buffered data" {
2160+
var tmp = std.testing.tmpDir(.{});
2161+
defer tmp.cleanup();
2162+
2163+
const contents = "data";
2164+
2165+
const file = try tmp.dir.createFile("seek.bin", .{ .read = true });
2166+
defer file.close();
2167+
{
2168+
var buf: [16]u8 = undefined;
2169+
var file_writer = std.fs.File.writer(file, &buf);
2170+
2171+
try file_writer.interface.writeAll(contents);
2172+
try file_writer.seekTo(8);
2173+
try file_writer.interface.flush();
2174+
}
2175+
2176+
var read_buffer: [16]u8 = undefined;
2177+
var file_reader: std.fs.File.Reader = .init(file, &read_buffer);
2178+
2179+
var buf: [4]u8 = undefined;
2180+
try file_reader.interface.readSliceAll(&buf);
2181+
try std.testing.expectEqualStrings(contents, &buf);
2182+
}

lib/std/mem/Allocator.zig

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ pub const VTable = struct {
8181
free: *const fn (*anyopaque, memory: []u8, alignment: Alignment, ret_addr: usize) void,
8282
};
8383

84+
pub fn noAlloc(
85+
self: *anyopaque,
86+
len: usize,
87+
alignment: Alignment,
88+
ret_addr: usize,
89+
) ?[*]u8 {
90+
_ = self;
91+
_ = len;
92+
_ = alignment;
93+
_ = ret_addr;
94+
return null;
95+
}
96+
8497
pub fn noResize(
8598
self: *anyopaque,
8699
memory: []u8,
@@ -445,3 +458,62 @@ pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) Error![:0]T {
445458
new_buf[m.len] = 0;
446459
return new_buf[0..m.len :0];
447460
}
461+
462+
/// An allocator that always fails to allocate.
463+
pub const failing: Allocator = .{
464+
.ptr = undefined,
465+
.vtable = &.{
466+
.alloc = noAlloc,
467+
.resize = unreachableResize,
468+
.remap = unreachableRemap,
469+
.free = unreachableFree,
470+
},
471+
};
472+
473+
fn unreachableResize(
474+
self: *anyopaque,
475+
memory: []u8,
476+
alignment: Alignment,
477+
new_len: usize,
478+
ret_addr: usize,
479+
) bool {
480+
_ = self;
481+
_ = memory;
482+
_ = alignment;
483+
_ = new_len;
484+
_ = ret_addr;
485+
unreachable;
486+
}
487+
488+
fn unreachableRemap(
489+
self: *anyopaque,
490+
memory: []u8,
491+
alignment: Alignment,
492+
new_len: usize,
493+
ret_addr: usize,
494+
) ?[*]u8 {
495+
_ = self;
496+
_ = memory;
497+
_ = alignment;
498+
_ = new_len;
499+
_ = ret_addr;
500+
unreachable;
501+
}
502+
503+
fn unreachableFree(
504+
self: *anyopaque,
505+
memory: []u8,
506+
alignment: Alignment,
507+
ret_addr: usize,
508+
) void {
509+
_ = self;
510+
_ = memory;
511+
_ = alignment;
512+
_ = ret_addr;
513+
unreachable;
514+
}
515+
516+
test failing {
517+
const f: Allocator = .failing;
518+
try std.testing.expectError(error.OutOfMemory, f.alloc(u8, 123));
519+
}

0 commit comments

Comments
 (0)