1- use clash_lib:: { shutdown , start_scaffold , Config , Options , TokioRuntime } ;
1+ use clash_lib:: { Config , Options , TokioRuntime , shutdown , start_scaffold } ;
22use std:: {
33 ffi:: { CStr , CString } ,
44 os:: raw:: { c_char, c_int} ,
55} ;
66
77/// # Safety
88/// This function is unsafe because it dereferences raw pointers.
9- #[ no_mangle]
9+ #[ unsafe ( no_mangle) ]
1010pub unsafe extern "C" fn clash_start (
1111 config : * const c_char ,
1212 log : * const c_char ,
1313 cwd : * const c_char ,
1414 multithread : c_int ,
1515) -> * mut c_char {
16- let config_str = CStr :: from_ptr ( config)
17- . to_str ( )
18- . unwrap_or_default ( )
19- . to_string ( ) ;
20- let log_str = CStr :: from_ptr ( log) . to_str ( ) . unwrap_or_default ( ) . to_string ( ) ;
21- let cwd_str = CStr :: from_ptr ( cwd) . to_str ( ) . unwrap_or_default ( ) . to_string ( ) ;
16+ unsafe {
17+ let config_str = CStr :: from_ptr ( config)
18+ . to_str ( )
19+ . unwrap_or_default ( )
20+ . to_string ( ) ;
21+ let log_str = CStr :: from_ptr ( log) . to_str ( ) . unwrap_or_default ( ) . to_string ( ) ;
22+ let cwd_str = CStr :: from_ptr ( cwd) . to_str ( ) . unwrap_or_default ( ) . to_string ( ) ;
2223
23- let rt = if multithread != 0 {
24- Some ( TokioRuntime :: MultiThread )
25- } else {
26- Some ( TokioRuntime :: SingleThread )
27- } ;
24+ let rt = if multithread != 0 {
25+ Some ( TokioRuntime :: MultiThread )
26+ } else {
27+ Some ( TokioRuntime :: SingleThread )
28+ } ;
2829
29- let options = Options {
30- config : Config :: Str ( config_str) ,
31- cwd : Some ( cwd_str) ,
32- rt,
33- log_file : Some ( log_str) ,
34- } ;
30+ let options = Options {
31+ config : Config :: Str ( config_str) ,
32+ cwd : Some ( cwd_str) ,
33+ rt,
34+ log_file : Some ( log_str) ,
35+ } ;
3536
36- match start_scaffold ( options) {
37- Ok ( _) => CString :: new ( "" ) . unwrap ( ) . into_raw ( ) ,
38- Err ( e) => CString :: new ( format ! ( "Error: {}" , e) ) . unwrap ( ) . into_raw ( ) ,
37+ match start_scaffold ( options) {
38+ Ok ( _) => CString :: new ( "" ) . unwrap ( ) . into_raw ( ) ,
39+ Err ( e) => CString :: new ( format ! ( "Error: {}" , e) ) . unwrap ( ) . into_raw ( ) ,
40+ }
3941 }
4042}
4143
42- #[ no_mangle]
44+ #[ unsafe ( no_mangle) ]
4345pub extern "C" fn clash_shutdown ( ) -> c_int {
4446 if shutdown ( ) {
4547 1 // Success
@@ -50,7 +52,7 @@ pub extern "C" fn clash_shutdown() -> c_int {
5052
5153/// # Safety
5254/// This function is unsafe because it dereferences raw pointers.
53- #[ no_mangle]
55+ #[ unsafe ( no_mangle) ]
5456#[ allow( unused_must_use) ]
5557pub unsafe extern "C" fn clash_free_string ( s : * mut c_char ) {
5658 if s. is_null ( ) {
0 commit comments