@@ -9,7 +9,7 @@ use tracing::{Level, debug};
9
9
10
10
#[ cfg( feature = "load-dynamic" ) ]
11
11
use crate :: G_ORT_DYLIB_PATH ;
12
- use crate :: { error:: Result , execution_providers:: ExecutionProviderDispatch , extern_system_fn, ortsys} ;
12
+ use crate :: { AsPointer , error:: Result , execution_providers:: ExecutionProviderDispatch , extern_system_fn, ortsys} ;
13
13
14
14
struct EnvironmentSingleton {
15
15
lock : RwLock < Option < Arc < Environment > > >
@@ -33,24 +33,25 @@ static G_ENV: EnvironmentSingleton = EnvironmentSingleton { lock: RwLock::new(No
33
33
#[ derive( Debug ) ]
34
34
pub struct Environment {
35
35
pub ( crate ) execution_providers : Vec < ExecutionProviderDispatch > ,
36
- pub ( crate ) env_ptr : NonNull < ort_sys:: OrtEnv > ,
36
+ ptr : NonNull < ort_sys:: OrtEnv > ,
37
37
pub ( crate ) has_global_threadpool : bool
38
38
}
39
39
40
40
unsafe impl Send for Environment { }
41
41
unsafe impl Sync for Environment { }
42
42
43
- impl Environment {
44
- /// Returns the underlying [`ort_sys::OrtEnv`] pointer.
45
- pub fn ptr ( & self ) -> * mut ort_sys:: OrtEnv {
46
- self . env_ptr . as_ptr ( )
43
+ impl AsPointer for Environment {
44
+ type Sys = ort_sys:: OrtEnv ;
45
+
46
+ fn ptr ( & self ) -> * const Self :: Sys {
47
+ self . ptr . as_ptr ( )
47
48
}
48
49
}
49
50
50
51
impl Drop for Environment {
51
52
fn drop ( & mut self ) {
52
- debug ! ( ptr = ?self . env_ptr . as_ptr ( ) , "Releasing environment" ) ;
53
- ortsys ! [ unsafe ReleaseEnv ( self . env_ptr . as_ptr ( ) ) ] ;
53
+ debug ! ( ptr = ?self . ptr ( ) , "Releasing environment" ) ;
54
+ ortsys ! [ unsafe ReleaseEnv ( self . ptr_mut ( ) ) ] ;
54
55
}
55
56
}
56
57
@@ -213,7 +214,7 @@ impl EnvironmentBuilder {
213
214
let env = Arc :: new ( Environment {
214
215
execution_providers : self . execution_providers ,
215
216
// we already asserted the env pointer is non-null in the `CreateEnvWithCustomLogger` call
216
- env_ptr : unsafe { NonNull :: new_unchecked ( env_ptr) } ,
217
+ ptr : unsafe { NonNull :: new_unchecked ( env_ptr) } ,
217
218
has_global_threadpool
218
219
} ) ;
219
220
env_lock. replace ( Arc :: clone ( & env) ) ;
0 commit comments