@@ -40,13 +40,9 @@ use std::{
4040 os:: raw:: { c_char, c_void} ,
4141 sync:: atomic:: { AtomicBool , Ordering } ,
4242} ;
43- use dispatch2:: ffi:: { dispatch_object_t, dispatch_queue_t, DISPATCH_QUEUE_SERIAL , dispatch_queue_create} ;
44- use core_foundation:: {
45- array:: CFArray ,
46- base:: { kCFAllocatorDefault, TCFType } ,
47- string:: CFString ,
48- } ;
49- use fsevent_sys:: { self as fse} ;
43+ use dispatch2:: { DispatchQueue , DispatchQueueAttr , DispatchRetained } ;
44+ use objc2_core_foundation:: { CFArray , CFRetained , CFString } ;
45+ use objc2_core_services:: { self as fse} ;
5046
5147pub enum Kind { // Ordinals need to be consistent with enum `Kind` in Java
5248 OVERFLOW =0 ,
@@ -58,8 +54,8 @@ pub enum Kind { // Ordinals need to be consistent with enum `Kind` in Java
5854pub struct NativeEventStream {
5955 since_when : fse:: FSEventStreamEventId ,
6056 closed : AtomicBool ,
61- path : CFArray < CFString > ,
62- queue : dispatch_queue_t ,
57+ path : CFRetained < CFArray < CFString > > ,
58+ queue : DispatchRetained < DispatchQueue > ,
6359 stream : Option < fse:: FSEventStreamRef > ,
6460 info : * mut ContextInfo ,
6561}
@@ -69,8 +65,8 @@ impl NativeEventStream {
6965 Self {
7066 since_when : unsafe { fse:: FSEventsGetCurrentEventId ( ) } ,
7167 closed : AtomicBool :: new ( false ) ,
72- path : CFArray :: from_CFTypes ( & [ CFString :: new ( & path) ] ) ,
73- queue : unsafe { dispatch_queue_create ( ptr :: null ( ) , DISPATCH_QUEUE_SERIAL ) } ,
68+ path : CFArray :: from_retained_objects ( & [ CFString :: from_str ( & path) ] ) ,
69+ queue : DispatchQueue :: new ( "java-watch" , DispatchQueueAttr :: SERIAL ) ,
7470 stream : None ,
7571 info : Box :: into_raw ( Box :: new ( ContextInfo { handler : Box :: new ( handler) } ) ) ,
7672 }
@@ -79,23 +75,23 @@ impl NativeEventStream {
7975 pub fn start ( & mut self ) {
8076 unsafe {
8177 let stream = fse:: FSEventStreamCreate (
82- kCFAllocatorDefault ,
83- callback,
84- & fse:: FSEventStreamContext {
78+ None ,
79+ Some ( callback) ,
80+ & mut fse:: FSEventStreamContext {
8581 version : 0 ,
8682 info : self . info as * mut _ ,
8783 retain : None ,
8884 release : Some ( release_context) ,
89- copy_description : None
85+ copyDescription : None
9086 } ,
91- self . path . as_concrete_TypeRef ( ) ,
87+ self . path . as_opaque ( ) ,
9288 self . since_when ,
9389 0.15 ,
9490 FLAGS ) ;
9591
9692 self . stream = Some ( stream) ;
9793
98- fse:: FSEventStreamSetDispatchQueue ( stream, self . queue ) ;
94+ fse:: FSEventStreamSetDispatchQueue ( stream, Some ( & self . queue ) ) ;
9995 fse:: FSEventStreamStart ( stream) ;
10096 } ;
10197 }
@@ -107,13 +103,11 @@ impl NativeEventStream {
107103 match self . stream {
108104 Some ( stream) => unsafe {
109105 fse:: FSEventStreamStop ( stream) ;
110- fse:: FSEventStreamSetDispatchQueue ( stream, ptr :: null_mut ( ) ) ;
106+ fse:: FSEventStreamSetDispatchQueue ( stream, None ) ;
111107 fse:: FSEventStreamInvalidate ( stream) ;
112- dispatch2:: ffi:: dispatch_release ( self . queue as dispatch_object_t ) ;
113108 fse:: FSEventStreamRelease ( stream) ;
114109 }
115- None => unsafe {
116- dispatch2:: ffi:: dispatch_release ( self . queue as dispatch_object_t ) ;
110+ None => {
117111 }
118112 } ;
119113 }
@@ -128,28 +122,28 @@ const FLAGS : fse::FSEventStreamCreateFlags
128122 | fse:: kFSEventStreamCreateFlagWatchRoot
129123 | fse:: kFSEventStreamCreateFlagFileEvents;
130124
131- extern "C" fn release_context ( info : * mut c_void ) {
125+ unsafe extern "C-unwind " fn release_context ( info : * const c_void ) {
132126 let ctx_ptr = info as * mut ContextInfo ;
133127 unsafe { drop ( Box :: from_raw ( ctx_ptr) ) ; }
134128}
135129
136- extern "C" fn callback (
137- _stream_ref : fse:: FSEventStreamRef ,
130+ unsafe extern "C-unwind " fn callback (
131+ _stream_ref : fse:: ConstFSEventStreamRef ,
138132 info : * mut c_void ,
139133 num_events : usize ,
140- event_paths : * mut c_void ,
141- event_flags : * const fse:: FSEventStreamEventFlags ,
142- _event_ids : * const fse:: FSEventStreamEventId ,
134+ event_paths : ptr :: NonNull < c_void > ,
135+ event_flags : ptr :: NonNull < fse:: FSEventStreamEventFlags > ,
136+ _event_ids : ptr :: NonNull < fse:: FSEventStreamEventId > ,
143137) {
144138 let info = unsafe { & mut * ( info as * mut ContextInfo ) } ;
145139 let handler = info. handler . as_ref ( ) ;
146140
147- let event_paths = event_paths as * const * const c_char ;
141+ let event_paths = event_paths. as_ptr ( ) as * const * const c_char ;
148142 for i in 0 ..num_events {
149143 // TODO: We're currently going from C strings to Rust strings to JNI
150144 // strings. If possible, go directly from C strings to JNI strings.
151145 let path = unsafe { CStr :: from_ptr ( * event_paths. add ( i) ) . to_str ( ) . unwrap ( ) . to_string ( ) } ;
152- let flags: fse:: FSEventStreamEventFlags = unsafe { * event_flags. add ( i) } ;
146+ let flags: fse:: FSEventStreamEventFlags = unsafe { * event_flags. as_ptr ( ) . add ( i) } ;
153147
154148 // Note: Multiple "physical" native events might be coalesced into a
155149 // single "logical" native event, so the following series of checks
0 commit comments