From c2c7fa2a5d7453713dced4ee035af4af8144e1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Tue, 30 Jan 2024 16:24:37 +0100 Subject: [PATCH] Wrap unsafe calls in unsafe {} --- .../src/network_reachability.rs | 76 ++++++++++++------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/system-configuration/src/network_reachability.rs b/system-configuration/src/network_reachability.rs index 081a757..60a65a5 100644 --- a/system-configuration/src/network_reachability.rs +++ b/system-configuration/src/network_reachability.rs @@ -393,14 +393,19 @@ mod test { addr ); reachability.set_callback(|_| {}).unwrap(); - reachability - .schedule_with_runloop(&CFRunLoop::get_current(), unsafe { kCFRunLoopCommonModes }) - .unwrap(); - reachability - .unschedule_from_runloop(&CFRunLoop::get_current(), unsafe { - kCFRunLoopCommonModes - }) - .unwrap(); + // SAFETY: We use the Apple provided run_loop_mode kCFRunLoopCommonModes + unsafe { + reachability + .schedule_with_runloop(&CFRunLoop::get_current(), unsafe { + kCFRunLoopCommonModes + }) + .unwrap(); + reachability + .unschedule_from_runloop(&CFRunLoop::get_current(), unsafe { + kCFRunLoopCommonModes + }) + .unwrap(); + } } } @@ -424,14 +429,19 @@ mod test { remote ); reachability.set_callback(|_| {}).unwrap(); - reachability - .schedule_with_runloop(&CFRunLoop::get_current(), unsafe { kCFRunLoopCommonModes }) - .unwrap(); - reachability - .unschedule_from_runloop(&CFRunLoop::get_current(), unsafe { - kCFRunLoopCommonModes - }) - .unwrap(); + // SAFETY: We use the Apple provided run_loop_mode kCFRunLoopCommonModes + unsafe { + reachability + .schedule_with_runloop(&CFRunLoop::get_current(), unsafe { + kCFRunLoopCommonModes + }) + .unwrap(); + reachability + .unschedule_from_runloop(&CFRunLoop::get_current(), unsafe { + kCFRunLoopCommonModes + }) + .unwrap(); + } } } @@ -445,16 +455,19 @@ mod test { match SCNetworkReachability::from_host(&input) { Some(mut reachability) => { reachability.set_callback(|_| {}).unwrap(); - reachability - .schedule_with_runloop(&CFRunLoop::get_current(), unsafe { - kCFRunLoopCommonModes - }) - .unwrap(); - reachability - .unschedule_from_runloop(&CFRunLoop::get_current(), unsafe { - kCFRunLoopCommonModes - }) - .unwrap(); + // SAFETY: We use the Apple provided run_loop_mode kCFRunLoopCommonModes + unsafe { + reachability + .schedule_with_runloop(&CFRunLoop::get_current(), unsafe { + kCFRunLoopCommonModes + }) + .unwrap(); + reachability + .unschedule_from_runloop(&CFRunLoop::get_current(), unsafe { + kCFRunLoopCommonModes + }) + .unwrap(); + } } None => { panic!( @@ -481,9 +494,14 @@ mod test { let mut reachability = SCNetworkReachability::from("0.0.0.0:0".parse::().unwrap()); reachability.set_callback(|_| {}).unwrap(); - reachability - .schedule_with_runloop(&CFRunLoop::get_current(), unsafe { kCFRunLoopCommonModes }) - .unwrap(); + // SAFETY: We use the Apple provided run_loop_mode kCFRunLoopCommonModes + unsafe { + reachability + .schedule_with_runloop(&CFRunLoop::get_current(), unsafe { + kCFRunLoopCommonModes + }) + .unwrap(); + } reachability.set_callback(|_| {}).unwrap(); let _ = tx.send(reachability); CFRunLoop::run_current();