authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2025-03-14 19:16:13+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-18 04:57:31+01:00
logf9549504851c9445ea474e78cedc5d52a5b21f36
tree8dc08e4caf6265fd78f5528ef5e9acf4a6c5eb45
parentf79dacbfc4876c2799c7a2dcd2b29af71d43d006
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

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) {...@@ -612,8 +612,6 @@ const Os = switch (builtin.os.tag) {
612 /// -1. Otherwise, it needs to be opened in update(), and will be612 /// -1. Otherwise, it needs to be opened in update(), and will be
613 /// stored here.613 /// stored here.
614 dir_fd: i32,614 dir_fd: i32,
615 /// Number of files being watched by this directory handle.
616 ref_count: u32,
617 }),615 }),
618616
619 const dir_open_flags: posix.O = f: {617 const dir_open_flags: posix.O = f: {
...@@ -673,11 +671,9 @@ const Os = switch (builtin.os.tag) {...@@ -673,11 +671,9 @@ const Os = switch (builtin.os.tag) {
673 try handles.append(gpa, .{671 try handles.append(gpa, .{
674 .rs = .{},672 .rs = .{},
675 .dir_fd = if (skip_open_dir) -1 else dir_fd,673 .dir_fd = if (skip_open_dir) -1 else dir_fd,
676 .ref_count = 1,
677 });674 });
678 } else {
679 handles.items(.ref_count)[gop.index] += 1;
680 }675 }
676
681 break :rs &handles.items(.rs)[gop.index];677 break :rs &handles.items(.rs)[gop.index];
682 };678 };
683 for (files.items) |basename| {679 for (files.items) |basename| {
...@@ -718,10 +714,6 @@ const Os = switch (builtin.os.tag) {...@@ -718,10 +714,6 @@ const Os = switch (builtin.os.tag) {
718 }714 }
719 }715 }
720716
721 const ref_count_ptr = &handles.items(.ref_count)[i];
722 ref_count_ptr.* -= 1;
723 if (ref_count_ptr.* > 0) continue;
724
725 // If the sub_path == "" then this patch has already the717 // If the sub_path == "" then this patch has already the
726 // dir fd that we need to use as the ident to remove the718 // dir fd that we need to use as the ident to remove the
727 // event. If it was opened above with openat() then we need719 // event. If it was opened above with openat() then we need
...@@ -738,10 +730,10 @@ const Os = switch (builtin.os.tag) {...@@ -738,10 +730,10 @@ const Os = switch (builtin.os.tag) {
738 // index in the udata field.730 // index in the udata field.
739 const last_dir_fd = fd: {731 const last_dir_fd = fd: {
740 const last_path = w.dir_table.keys()[handles.len - 1];732 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)
742 last_path.root_dir.handle.fd734 last_path.root_dir.handle.fd
743 else735 else
744 handles.items(.dir_fd)[i];736 handles.items(.dir_fd)[handles.len - 1];
745 assert(last_dir_fd != -1);737 assert(last_dir_fd != -1);
746 break :fd last_dir_fd;738 break :fd last_dir_fd;
747 };739 };