authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2025-03-14 19:16:13+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-03-15 05:29:54+00:00
log11b49e90024da21e806a71a7ee62b23572836cee
tree1f69e50db41e470e176d9a5362783a002320d7d6
parent1f92b394e97ce13e49cce8838968c0dc848d0abb

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 files changed, 3 insertions(+), 11 deletions(-)

lib/std/Build/Watch.zig+3-11
......@@ -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 };