Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop-gpui): count exception-guard test calls atomically and trim narrating comments

Richie McIlroy352aabce3844
diff --git a/apps/desktop-gpui/native/exception_guard.m b/apps/desktop-gpui/native/exception_guard.m
index cda055fc2..458461420 100644
--- a/apps/desktop-gpui/native/exception_guard.m
+++ b/apps/desktop-gpui/native/exception_guard.m
@@ -1,4 +1,5 @@
#import <Foundation/Foundation.h>
+#include <stdatomic.h>
// Calls `imp` and catches an Objective-C exception it throws. No Rust frame
// sits between the throw and this catch, so the exception never unwinds
@@ -12,14 +13,14 @@ id cap_call_void_imp_catching(void (*imp)(id, SEL), id receiver, SEL selector) {
}
}
-unsigned long cap_test_unbalanced_removal_calls = 0;
+_Atomic unsigned long cap_test_unbalanced_removal_calls = 0;
// Test fixture: the crash report's exception, removing a key-value observer
// that was never added.
void cap_test_unbalanced_kvo_removal(id receiver, SEL selector) {
(void)receiver;
(void)selector;
- cap_test_unbalanced_removal_calls += 1;
+ atomic_fetch_add(&cap_test_unbalanced_removal_calls, 1);
NSObject *observed = [[NSObject new] autorelease];
NSObject *observer = [[NSObject new] autorelease];
[observed removeObserver:observer forKeyPath:@"touchBar"];
diff --git a/apps/desktop-gpui/src/platform.rs b/apps/desktop-gpui/src/platform.rs
index b5d42968c..59c20fa76 100644
--- a/apps/desktop-gpui/src/platform.rs
+++ b/apps/desktop-gpui/src/platform.rs
@@ -618,8 +618,7 @@ mod mac {
)
}
- /// Keeps AppKit exceptions Cap cannot cause or prevent (the Touch Bar
- /// finder's) from crashing the app. Call on the main thread at startup.
+ /// Must run on the main thread before the run loop starts.
pub fn install_appkit_exception_guards() {
super::macos_exception_guard::install();
}
diff --git a/apps/desktop-gpui/src/platform/macos_exception_guard.rs b/apps/desktop-gpui/src/platform/macos_exception_guard.rs
index ec2797203..0348df865 100644
--- a/apps/desktop-gpui/src/platform/macos_exception_guard.rs
+++ b/apps/desktop-gpui/src/platform/macos_exception_guard.rs
@@ -42,8 +42,6 @@ impl GuardedMethod {
}
}
- /// Routes `class`'s `selector` through `guard`. Returns false when the
- /// class does not implement it, or it is already guarded.
fn install(&self, class: &AnyClass, selector: Sel, guard: VoidMethod) -> bool {
if self.original.get().is_some() || class.verify_sel::<(), ()>(selector).is_err() {
return false;
@@ -69,8 +67,6 @@ impl GuardedMethod {
true
}
- /// Calls the original implementation; an Objective-C exception it throws
- /// is logged and dropped. Returns whether one was.
unsafe fn call(&self, receiver: *mut AnyObject, selector: Sel) -> bool {
let Some(original) = self.original.get().copied() else {
return false;
@@ -88,7 +84,6 @@ impl GuardedMethod {
}
}
-/// `name: reason` of an NSException.
fn describe(exception: &AnyObject) -> String {
fn utf8(value: *mut AnyObject) -> String {
if value.is_null() {