diff options
| -rw-r--r-- | lib/std/array_list.zig | 63 | ||||
| -rw-r--r-- | lib/std/c/darwin.zig | 8 | ||||
| -rw-r--r-- | lib/std/c/dragonfly.zig | 6 | ||||
| -rw-r--r-- | lib/std/c/freebsd.zig | 6 | ||||
| -rw-r--r-- | lib/std/c/netbsd.zig | 6 | ||||
| -rw-r--r-- | lib/std/c/openbsd.zig | 10 | ||||
| -rw-r--r-- | lib/std/c/solaris.zig | 8 | ||||
| -rw-r--r-- | lib/std/debug.zig | 2 | ||||
| -rw-r--r-- | lib/std/hash/auto_hash.zig | 4 | ||||
| -rw-r--r-- | lib/std/os.zig | 11 | ||||
| -rw-r--r-- | lib/std/os/linux.zig | 18 | ||||
| -rw-r--r-- | lib/std/os/test.zig | 2 | ||||
| -rw-r--r-- | lib/std/os/windows.zig | 4 | ||||
| -rw-r--r-- | src/link.zig | 1 | ||||
| -rw-r--r-- | src/link/MachO.zig | 6 | ||||
| -rw-r--r-- | src/link/MachO/Atom.zig | 2 | ||||
| -rw-r--r-- | src/link/MachO/Object.zig | 24 | ||||
| -rw-r--r-- | src/main.zig | 1 |
18 files changed, 127 insertions, 55 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 655bdeaa42..a8c53c3142 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -221,6 +221,30 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { mem.copy(T, self.items[old_len..], items); } + /// Append an unaligned slice of items to the list. Allocates more + /// memory as necessary. Only call this function if calling + /// `appendSlice` instead would be a compile error. + pub fn appendUnalignedSlice(self: *Self, items: []align(1) const T) Allocator.Error!void { + try self.ensureUnusedCapacity(items.len); + self.appendUnalignedSliceAssumeCapacity(items); + } + + /// Append the slice of items to the list, asserting the capacity is already + /// enough to store the new items. **Does not** invalidate pointers. + /// Only call this function if calling `appendSliceAssumeCapacity` instead + /// would be a compile error. + pub fn appendUnalignedSliceAssumeCapacity(self: *Self, items: []align(1) const T) void { + const old_len = self.items.len; + const new_len = old_len + items.len; + assert(new_len <= self.capacity); + self.items.len = new_len; + @memcpy( + @ptrCast([*]align(@alignOf(T)) u8, self.items.ptr + old_len), + @ptrCast([*]const u8, items.ptr), + items.len * @sizeOf(T), + ); + } + pub const Writer = if (T != u8) @compileError("The Writer interface is only defined for ArrayList(u8) " ++ "but the given type is ArrayList(" ++ @typeName(T) ++ ")") @@ -592,6 +616,29 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ mem.copy(T, self.items[old_len..], items); } + /// Append the slice of items to the list. Allocates more + /// memory as necessary. Only call this function if a call to `appendSlice` instead would + /// be a compile error. + pub fn appendUnalignedSlice(self: *Self, allocator: Allocator, items: []align(1) const T) Allocator.Error!void { + try self.ensureUnusedCapacity(allocator, items.len); + self.appendUnalignedSliceAssumeCapacity(items); + } + + /// Append an unaligned slice of items to the list, asserting the capacity is enough + /// to store the new items. Only call this function if a call to `appendSliceAssumeCapacity` + /// instead would be a compile error. + pub fn appendUnalignedSliceAssumeCapacity(self: *Self, items: []align(1) const T) void { + const old_len = self.items.len; + const new_len = old_len + items.len; + assert(new_len <= self.capacity); + self.items.len = new_len; + @memcpy( + @ptrCast([*]align(@alignOf(T)) u8, self.items.ptr + old_len), + @ptrCast([*]const u8, items.ptr), + items.len * @sizeOf(T), + ); + } + pub const WriterContext = struct { self: *Self, allocator: Allocator, @@ -899,6 +946,14 @@ test "std.ArrayList/ArrayListUnmanaged.basic" { try testing.expect(list.pop() == 1); try testing.expect(list.items.len == 9); + var unaligned: [3]i32 align(1) = [_]i32{ 4, 5, 6 }; + list.appendUnalignedSlice(&unaligned) catch unreachable; + try testing.expect(list.items.len == 12); + try testing.expect(list.pop() == 6); + try testing.expect(list.pop() == 5); + try testing.expect(list.pop() == 4); + try testing.expect(list.items.len == 9); + list.appendSlice(&[_]i32{}) catch unreachable; try testing.expect(list.items.len == 9); @@ -941,6 +996,14 @@ test "std.ArrayList/ArrayListUnmanaged.basic" { try testing.expect(list.pop() == 1); try testing.expect(list.items.len == 9); + var unaligned: [3]i32 align(1) = [_]i32{ 4, 5, 6 }; + list.appendUnalignedSlice(a, &unaligned) catch unreachable; + try testing.expect(list.items.len == 12); + try testing.expect(list.pop() == 6); + try testing.expect(list.pop() == 5); + try testing.expect(list.pop() == 4); + try testing.expect(list.items.len == 9); + list.appendSlice(a, &[_]i32{}) catch unreachable; try testing.expect(list.items.len == 9); diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index e7fd3cde44..0a65fa5242 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -814,10 +814,10 @@ pub const sigset_t = u32; pub const empty_sigset: sigset_t = 0; pub const SIG = struct { - pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); - pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); - pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); - pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 5); + pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize)); + pub const DFL = @intToPtr(?Sigaction.handler_fn, 0); + pub const IGN = @intToPtr(?Sigaction.handler_fn, 1); + pub const HOLD = @intToPtr(?Sigaction.handler_fn, 5); /// block specified signal set pub const _BLOCK = 1; diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index 1a60f94a1e..5d7822e8e9 100644 --- a/lib/std/c/dragonfly.zig +++ b/lib/std/c/dragonfly.zig @@ -609,9 +609,9 @@ pub const S = struct { pub const BADSIG = SIG.ERR; pub const SIG = struct { - pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); - pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); - pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); + pub const DFL = @intToPtr(?Sigaction.handler_fn, 0); + pub const IGN = @intToPtr(?Sigaction.handler_fn, 1); + pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize)); pub const BLOCK = 1; pub const UNBLOCK = 2; diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig index dac239094e..6f01886986 100644 --- a/lib/std/c/freebsd.zig +++ b/lib/std/c/freebsd.zig @@ -670,9 +670,9 @@ pub const SIG = struct { pub const UNBLOCK = 2; pub const SETMASK = 3; - pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); - pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); - pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); + pub const DFL = @intToPtr(?Sigaction.handler_fn, 0); + pub const IGN = @intToPtr(?Sigaction.handler_fn, 1); + pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize)); pub const WORDS = 4; pub const MAXSIG = 128; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index 3de14da7a2..a8287033d7 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -910,9 +910,9 @@ pub const winsize = extern struct { const NSIG = 32; pub const SIG = struct { - pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); - pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); - pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); + pub const DFL = @intToPtr(?Sigaction.handler_fn, 0); + pub const IGN = @intToPtr(?Sigaction.handler_fn, 1); + pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize)); pub const WORDS = 4; pub const MAXSIG = 128; diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index 0863cc5a5e..5c259bc41a 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -982,11 +982,11 @@ pub const winsize = extern struct { const NSIG = 33; pub const SIG = struct { - pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); - pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); - pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); - pub const CATCH = @intToPtr(?Sigaction.sigaction_fn, 2); - pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 3); + pub const DFL = @intToPtr(?Sigaction.handler_fn, 0); + pub const IGN = @intToPtr(?Sigaction.handler_fn, 1); + pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize)); + pub const CATCH = @intToPtr(?Sigaction.handler_fn, 2); + pub const HOLD = @intToPtr(?Sigaction.handler_fn, 3); pub const HUP = 1; pub const INT = 2; diff --git a/lib/std/c/solaris.zig b/lib/std/c/solaris.zig index 61e52cfe30..1e726beb75 100644 --- a/lib/std/c/solaris.zig +++ b/lib/std/c/solaris.zig @@ -879,10 +879,10 @@ pub const winsize = extern struct { const NSIG = 75; pub const SIG = struct { - pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); - pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); - pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); - pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 2); + pub const DFL = @intToPtr(?Sigaction.handler_fn, 0); + pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize)); + pub const IGN = @intToPtr(?Sigaction.handler_fn, 1); + pub const HOLD = @intToPtr(?Sigaction.handler_fn, 2); pub const WORDS = 4; pub const MAXSIG = 75; diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 847298e54b..0738b5af0b 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1787,7 +1787,7 @@ fn resetSegfaultHandler() void { return; } var act = os.Sigaction{ - .handler = .{ .sigaction = os.SIG.DFL }, + .handler = .{ .handler = os.SIG.DFL }, .mask = os.empty_sigset, .flags = 0, }; diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index c4060e9182..951c0148d9 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -193,8 +193,8 @@ fn typeContainsSlice(comptime K: type) bool { pub fn autoHash(hasher: anytype, key: anytype) void { const Key = @TypeOf(key); if (comptime typeContainsSlice(Key)) { - @compileError("std.auto_hash.autoHash does not allow slices as well as unions and structs containing slices here (" ++ @typeName(Key) ++ - ") because the intent is unclear. Consider using std.auto_hash.hash or providing your own hash function instead."); + @compileError("std.hash.autoHash does not allow slices as well as unions and structs containing slices here (" ++ @typeName(Key) ++ + ") because the intent is unclear. Consider using std.hash.autoHashStrat or providing your own hash function instead."); } hash(hasher, key, .Shallow); diff --git a/lib/std/os.zig b/lib/std/os.zig index 1192c72629..984758565c 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -475,10 +475,9 @@ pub fn abort() noreturn { // Install default handler so that the tkill below will terminate. const sigact = Sigaction{ - .handler = .{ .sigaction = SIG.DFL }, - .mask = undefined, - .flags = undefined, - .restorer = undefined, + .handler = .{ .handler = SIG.DFL }, + .mask = empty_sigset, + .flags = 0, }; sigaction(SIG.ABRT, &sigact, null) catch |err| switch (err) { error.OperationNotSupported => unreachable, @@ -953,6 +952,10 @@ pub const WriteError = error{ OperationAborted, NotOpenForWriting, + /// The process cannot access the file because another process has locked + /// a portion of the file. Windows-only. + LockViolation, + /// This error occurs when no global event loop is configured, /// and reading from the file descriptor would block. WouldBlock, diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index ae9b441b60..539f3612f9 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1945,9 +1945,9 @@ pub const SIG = if (is_mips) struct { pub const SYS = 31; pub const UNUSED = SIG.SYS; - pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); - pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); - pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize)); + pub const DFL = @intToPtr(?Sigaction.handler_fn, 0); + pub const IGN = @intToPtr(?Sigaction.handler_fn, 1); } else if (is_sparc) struct { pub const BLOCK = 1; pub const UNBLOCK = 2; @@ -1989,9 +1989,9 @@ pub const SIG = if (is_mips) struct { pub const PWR = LOST; pub const IO = SIG.POLL; - pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); - pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); - pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize)); + pub const DFL = @intToPtr(?Sigaction.handler_fn, 0); + pub const IGN = @intToPtr(?Sigaction.handler_fn, 1); } else struct { pub const BLOCK = 0; pub const UNBLOCK = 1; @@ -2032,9 +2032,9 @@ pub const SIG = if (is_mips) struct { pub const SYS = 31; pub const UNUSED = SIG.SYS; - pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); - pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0); - pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1); + pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize)); + pub const DFL = @intToPtr(?Sigaction.handler_fn, 0); + pub const IGN = @intToPtr(?Sigaction.handler_fn, 1); }; pub const kernel_rwf = u32; diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 44f8b16b9e..a8497586f9 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -785,7 +785,7 @@ test "sigaction" { try testing.expect(signal_test_failed == false); // Check if the handler has been correctly reset to SIG_DFL try os.sigaction(os.SIG.USR1, null, &old_sa); - try testing.expectEqual(os.SIG.DFL, old_sa.handler.sigaction); + try testing.expectEqual(os.SIG.DFL, old_sa.handler.handler); } test "dup & dup2" { diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 3e42ee5f2d..c79ccb5113 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -517,6 +517,9 @@ pub const WriteFileError = error{ OperationAborted, BrokenPipe, NotOpenForWriting, + /// The process cannot access the file because another process has locked + /// a portion of the file. + LockViolation, Unexpected, }; @@ -597,6 +600,7 @@ pub fn WriteFile( .IO_PENDING => unreachable, .BROKEN_PIPE => return error.BrokenPipe, .INVALID_HANDLE => return error.NotOpenForWriting, + .LOCK_VIOLATION => return error.LockViolation, else => |err| return unexpectedError(err), } } diff --git a/src/link.zig b/src/link.zig index a69dcc4c6e..14ae142a3f 100644 --- a/src/link.zig +++ b/src/link.zig @@ -435,6 +435,7 @@ pub const File = struct { EmitFail, NameTooLong, CurrentWorkingDirectoryUnlinked, + LockViolation, }; /// Called from within the CodeGen to lower a local variable instantion as an unnamed diff --git a/src/link/MachO.zig b/src/link/MachO.zig index db207af5f5..3da086a382 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -5315,10 +5315,10 @@ fn writeFunctionStarts(self: *MachO, ncmds: *u32, lc_writer: anytype) !void { } fn filterDataInCode( - dices: []const macho.data_in_code_entry, + dices: []align(1) const macho.data_in_code_entry, start_addr: u64, end_addr: u64, -) []const macho.data_in_code_entry { +) []align(1) const macho.data_in_code_entry { const Predicate = struct { addr: u64, @@ -5825,7 +5825,7 @@ pub fn getEntryPoint(self: MachO) error{MissingMainEntrypoint}!SymbolWithLoc { return global; } -pub fn findFirst(comptime T: type, haystack: []const T, start: usize, predicate: anytype) usize { +pub fn findFirst(comptime T: type, haystack: []align(1) const T, start: usize, predicate: anytype) usize { if (!@hasDecl(@TypeOf(predicate), "predicate")) @compileError("Predicate is required to define fn predicate(@This(), T) bool"); diff --git a/src/link/MachO/Atom.zig b/src/link/MachO/Atom.zig index 4871276f3c..dd818ea936 100644 --- a/src/link/MachO/Atom.zig +++ b/src/link/MachO/Atom.zig @@ -218,7 +218,7 @@ const RelocContext = struct { base_offset: i32 = 0, }; -pub fn parseRelocs(self: *Atom, relocs: []const macho.relocation_info, context: RelocContext) !void { +pub fn parseRelocs(self: *Atom, relocs: []align(1) const macho.relocation_info, context: RelocContext) !void { const tracy = trace(@src()); defer tracy.end(); diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index 098917e81f..935183bbc6 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -24,7 +24,7 @@ mtime: u64, contents: []align(@alignOf(u64)) const u8, header: macho.mach_header_64 = undefined, -in_symtab: []const macho.nlist_64 = undefined, +in_symtab: []align(1) const macho.nlist_64 = undefined, in_strtab: []const u8 = undefined, symtab: std.ArrayListUnmanaged(macho.nlist_64) = .{}, @@ -100,12 +100,12 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) .SYMTAB => { const symtab = cmd.cast(macho.symtab_command).?; // Sadly, SYMTAB may be at an unaligned offset within the object file. - self.in_symtab = @alignCast(@alignOf(macho.nlist_64), @ptrCast( + self.in_symtab = @ptrCast( [*]align(1) const macho.nlist_64, self.contents.ptr + symtab.symoff, - ))[0..symtab.nsyms]; + )[0..symtab.nsyms]; self.in_strtab = self.contents[symtab.stroff..][0..symtab.strsize]; - try self.symtab.appendSlice(allocator, self.in_symtab); + try self.symtab.appendUnalignedSlice(allocator, self.in_symtab); }, else => {}, } @@ -197,10 +197,10 @@ fn filterSymbolsByAddress( } fn filterRelocs( - relocs: []const macho.relocation_info, + relocs: []align(1) const macho.relocation_info, start_addr: u64, end_addr: u64, -) []const macho.relocation_info { +) []align(1) const macho.relocation_info { const Predicate = struct { addr: u64, @@ -303,10 +303,10 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) const code: ?[]const u8 = if (!sect.isZerofill()) try self.getSectionContents(sect) else null; // Read section's list of relocations - const relocs = @alignCast(@alignOf(macho.relocation_info), @ptrCast( + const relocs = @ptrCast( [*]align(1) const macho.relocation_info, self.contents.ptr + sect.reloff, - ))[0..sect.nreloc]; + )[0..sect.nreloc]; // Symbols within this section only. const filtered_syms = filterSymbolsByAddress( @@ -473,7 +473,7 @@ fn createAtomFromSubsection( size: u64, alignment: u32, code: ?[]const u8, - relocs: []const macho.relocation_info, + relocs: []align(1) const macho.relocation_info, indexes: []const SymbolAtIndex, match: u8, sect: macho.section_64, @@ -539,7 +539,7 @@ pub fn getSourceSection(self: Object, index: u16) macho.section_64 { return self.sections.items[index]; } -pub fn parseDataInCode(self: Object) ?[]const macho.data_in_code_entry { +pub fn parseDataInCode(self: Object) ?[]align(1) const macho.data_in_code_entry { var it = LoadCommandIterator{ .ncmds = self.header.ncmds, .buffer = self.contents[@sizeOf(macho.mach_header_64)..][0..self.header.sizeofcmds], @@ -549,10 +549,10 @@ pub fn parseDataInCode(self: Object) ?[]const macho.data_in_code_entry { .DATA_IN_CODE => { const dice = cmd.cast(macho.linkedit_data_command).?; const ndice = @divExact(dice.datasize, @sizeOf(macho.data_in_code_entry)); - return @alignCast(@alignOf(macho.data_in_code_entry), @ptrCast( + return @ptrCast( [*]align(1) const macho.data_in_code_entry, self.contents.ptr + dice.dataoff, - ))[0..ndice]; + )[0..ndice]; }, else => {}, } diff --git a/src/main.zig b/src/main.zig index c103cddcd4..971fe19e36 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4227,6 +4227,7 @@ const FmtError = error{ NotOpenForWriting, UnsupportedEncoding, ConnectionResetByPeer, + LockViolation, } || fs.File.OpenError; fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool, dir: fs.Dir, sub_path: []const u8) FmtError!void { |
