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 c2c7fa2
Showing 1 changed file with 47 additions and 29 deletions.
76 changes: 47 additions & 29 deletions system-configuration/src/network_reachability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand All @@ -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();
}
}
}

Expand All @@ -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!(
Expand All @@ -481,9 +494,14 @@ 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(), unsafe {
kCFRunLoopCommonModes
})
.unwrap();
}
reachability.set_callback(|_| {}).unwrap();
let _ = tx.send(reachability);
CFRunLoop::run_current();
Expand Down

0 comments on commit c2c7fa2

Please sign in to comment.