Skip to content

Commit

Permalink
Wrap unsafe calls in unsafe {}
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Jan 30, 2024
1 parent 8370ad2 commit 4fcc05c
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions system-configuration/src/network_reachability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,15 @@ 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(), kCFRunLoopCommonModes)
.unwrap();
reachability
.unschedule_from_runloop(&CFRunLoop::get_current(), kCFRunLoopCommonModes)
.unwrap();
}
}
}

Expand All @@ -424,14 +425,15 @@ 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(), kCFRunLoopCommonModes)
.unwrap();
reachability
.unschedule_from_runloop(&CFRunLoop::get_current(), kCFRunLoopCommonModes)
.unwrap();
}
}
}

Expand All @@ -445,16 +447,18 @@ 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(), kCFRunLoopCommonModes)
.unwrap();
reachability
.unschedule_from_runloop(
&CFRunLoop::get_current(),
kCFRunLoopCommonModes,
)
.unwrap();
}
}
None => {
panic!(
Expand All @@ -481,9 +485,12 @@ mod test {
let mut reachability =
SCNetworkReachability::from("0.0.0.0:0".parse::<SocketAddr>().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(), kCFRunLoopCommonModes)
.unwrap();
}
reachability.set_callback(|_| {}).unwrap();
let _ = tx.send(reachability);
CFRunLoop::run_current();
Expand Down

0 comments on commit 4fcc05c

Please sign in to comment.