Skip to content

Commit 11b49e9

Browse files
kristoff-itmlugg
authored andcommitted
std.Build.Watch: fix macos implementation
The code did one useless thing and two wrong things: - ref counting was basically a noop - last_dir_fd was chosen from the wrong index and also under the wrong condition This caused regular crashes on macOS which are now gone.
1 parent 1f92b39 commit 11b49e9

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

lib/std/Build/Watch.zig

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,6 @@ const Os = switch (builtin.os.tag) {
612612
/// -1. Otherwise, it needs to be opened in update(), and will be
613613
/// stored here.
614614
dir_fd: i32,
615-
/// Number of files being watched by this directory handle.
616-
ref_count: u32,
617615
}),
618616

619617
const dir_open_flags: posix.O = f: {
@@ -673,11 +671,9 @@ const Os = switch (builtin.os.tag) {
673671
try handles.append(gpa, .{
674672
.rs = .{},
675673
.dir_fd = if (skip_open_dir) -1 else dir_fd,
676-
.ref_count = 1,
677674
});
678-
} else {
679-
handles.items(.ref_count)[gop.index] += 1;
680675
}
676+
681677
break :rs &handles.items(.rs)[gop.index];
682678
};
683679
for (files.items) |basename| {
@@ -718,10 +714,6 @@ const Os = switch (builtin.os.tag) {
718714
}
719715
}
720716

721-
const ref_count_ptr = &handles.items(.ref_count)[i];
722-
ref_count_ptr.* -= 1;
723-
if (ref_count_ptr.* > 0) continue;
724-
725717
// If the sub_path == "" then this patch has already the
726718
// dir fd that we need to use as the ident to remove the
727719
// event. If it was opened above with openat() then we need
@@ -738,10 +730,10 @@ const Os = switch (builtin.os.tag) {
738730
// index in the udata field.
739731
const last_dir_fd = fd: {
740732
const last_path = w.dir_table.keys()[handles.len - 1];
741-
const last_dir_fd = if (last_path.sub_path.len != 0)
733+
const last_dir_fd = if (last_path.sub_path.len == 0)
742734
last_path.root_dir.handle.fd
743735
else
744-
handles.items(.dir_fd)[i];
736+
handles.items(.dir_fd)[handles.len - 1];
745737
assert(last_dir_fd != -1);
746738
break :fd last_dir_fd;
747739
};

0 commit comments

Comments
 (0)