Skip to content

Commit 7634e67

Browse files
authored
Merge pull request #5158 from ziglang/zir-to-elf
beginnings of (non-LLVM) self-hosted machine code generation and linking
2 parents c829f2f + 9ebf25d commit 7634e67

File tree

8 files changed

+1388
-930
lines changed

8 files changed

+1388
-930
lines changed

lib/std/fs.zig

+4-2
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,10 @@ pub const Dir = struct {
13451345
mode: File.Mode = File.default_mode,
13461346
};
13471347

1348-
/// `dest_path` must remain valid for the lifetime of `AtomicFile`.
1349-
/// Call `AtomicFile.finish` to atomically replace `dest_path` with contents.
1348+
/// Directly access the `.file` field, and then call `AtomicFile.finish`
1349+
/// to atomically replace `dest_path` with contents.
1350+
/// Always call `AtomicFile.deinit` to clean up, regardless of whether `AtomicFile.finish` succeeded.
1351+
/// `dest_path` must remain valid until `AtomicFile.deinit` is called.
13501352
pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile {
13511353
if (path.dirname(dest_path)) |dirname| {
13521354
const dir = try self.openDir(dirname, .{});

lib/std/fs/file.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub const File = struct {
9393
/// This means that a process that does not respect the locking API can still get access
9494
/// to the file, despite the lock.
9595
///
96-
/// Windows' file locks are mandatory, and any process attempting to access the file will
96+
/// Windows's file locks are mandatory, and any process attempting to access the file will
9797
/// receive an error.
9898
///
9999
/// [1]: https://www.kernel.org/doc/Documentation/filesystems/mandatory-locking.txt

lib/std/mem.zig

+15-3
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,13 @@ test "sliceAsBytes and bytesAsSlice back" {
20272027
/// Round an address up to the nearest aligned address
20282028
/// The alignment must be a power of 2 and greater than 0.
20292029
pub fn alignForward(addr: usize, alignment: usize) usize {
2030-
return alignBackward(addr + (alignment - 1), alignment);
2030+
return alignForwardGeneric(usize, addr, alignment);
2031+
}
2032+
2033+
/// Round an address up to the nearest aligned address
2034+
/// The alignment must be a power of 2 and greater than 0.
2035+
pub fn alignForwardGeneric(comptime T: type, addr: T, alignment: T) T {
2036+
return alignBackwardGeneric(T, addr + (alignment - 1), alignment);
20312037
}
20322038

20332039
test "alignForward" {
@@ -2048,8 +2054,14 @@ test "alignForward" {
20482054
/// Round an address up to the previous aligned address
20492055
/// The alignment must be a power of 2 and greater than 0.
20502056
pub fn alignBackward(addr: usize, alignment: usize) usize {
2051-
assert(@popCount(usize, alignment) == 1);
2052-
// 000010000 // example addr
2057+
return alignBackwardGeneric(usize, addr, alignment);
2058+
}
2059+
2060+
/// Round an address up to the previous aligned address
2061+
/// The alignment must be a power of 2 and greater than 0.
2062+
pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T {
2063+
assert(@popCount(T, alignment) == 1);
2064+
// 000010000 // example alignment
20532065
// 000001111 // subtract 1
20542066
// 111110000 // binary not
20552067
return addr & ~(alignment - 1);

0 commit comments

Comments
 (0)