Skip to content

Commit 8370ad2

Browse files
committed
Mark schedule_with_runloop/unschedule_from_runloop as unsafe
1 parent 7633a12 commit 8370ad2

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Line wrap the file at 100 chars. Th
2424
## [Unreleased]
2525
### Changed
2626
- Bump minimum supported Rust version (MSRV) to 1.64.0.
27+
- Breaking: Mark `SCNetworkReachability::schedule_with_runloop` and `unschedule_from_runloop` as
28+
`unsafe`. They accept a raw pointer that it dereferences. Figuring out a safe API around this is
29+
left as an exercise for the future.
2730

2831
### Fixed
2932
- Fix memory leak in `SCNetworkReachability::set_callback`.

system-configuration/src/network_reachability.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ impl SCNetworkReachability {
186186
/// See [`SCNetworkReachabilityScheduleFromRunLoop`] for details.
187187
///
188188
/// [`SCNetworkReachabilityScheduleFromRunLoop`]: https://developer.apple.com/documentation/systemconfiguration/1514894-scnetworkreachabilityschedulewit?language=objc
189-
pub fn schedule_with_runloop(
189+
///
190+
/// # Safety
191+
///
192+
/// The `run_loop_mode` must not be NULL and must be a pointer to a valid run loop mode.
193+
/// Use `core_foundation::runloop::kCFRunLoopCommonModes` if you are unsure.
194+
pub unsafe fn schedule_with_runloop(
190195
&self,
191196
run_loop: &CFRunLoop,
192197
run_loop_mode: CFStringRef,
@@ -210,7 +215,12 @@ impl SCNetworkReachability {
210215
/// See [`SCNetworkReachabilityUnscheduleFromRunLoop`] for details.
211216
///
212217
/// [`SCNetworkReachabilityUnscheduleFromRunLoop`]: https://developer.apple.com/documentation/systemconfiguration/1514899-scnetworkreachabilityunschedulef?language=objc
213-
pub fn unschedule_from_runloop(
218+
///
219+
/// # Safety
220+
///
221+
/// The `run_loop_mode` must not be NULL and must be a pointer to a valid run loop mode.
222+
/// Use `core_foundation::runloop::kCFRunLoopCommonModes` if you are unsure.
223+
pub unsafe fn unschedule_from_runloop(
214224
&self,
215225
run_loop: &CFRunLoop,
216226
run_loop_mode: CFStringRef,

0 commit comments

Comments
 (0)