1
1
#![ allow( clippy:: missing_safety_doc) ]
2
2
3
3
use std:: {
4
- collections:: HashSet , ffi:: { c_char, c_long, c_ulong, CString } , mem:: transmute, num:: * , ptr:: NonNull
4
+ collections:: HashSet ,
5
+ ffi:: { c_char, c_long, c_ulong, CString } ,
6
+ mem:: transmute,
7
+ num:: * ,
8
+ ptr:: NonNull ,
5
9
} ;
6
10
7
11
mod counter;
@@ -398,7 +402,9 @@ pub extern "C" fn alloc_c_string() -> *mut c_char {
398
402
399
403
#[ no_mangle]
400
404
pub unsafe extern "C" fn free_c_string ( str : * mut c_char ) {
401
- unsafe { let _ = CString :: from_raw ( str) ; } ;
405
+ unsafe {
406
+ let _ = CString :: from_raw ( str) ;
407
+ } ;
402
408
}
403
409
404
410
#[ no_mangle]
@@ -451,7 +457,9 @@ pub extern "C" fn create_context() -> *mut Context {
451
457
452
458
#[ no_mangle]
453
459
pub unsafe extern "C" fn delete_context ( context : * mut Context ) {
454
- unsafe { let _ = Box :: from_raw ( context) ; } ;
460
+ unsafe {
461
+ let _ = Box :: from_raw ( context) ;
462
+ } ;
455
463
}
456
464
457
465
#[ no_mangle]
@@ -644,7 +652,7 @@ pub struct InternalHiddenContext {
644
652
}
645
653
646
654
pub struct TreatAsEmptyStruct {
647
- _internal : std:: sync:: Arc < InternalHiddenContext >
655
+ _internal : std:: sync:: Arc < InternalHiddenContext > ,
648
656
}
649
657
650
658
#[ no_mangle]
@@ -690,7 +698,6 @@ pub extern "C" fn set_callback(alloc_callback: MyCallback) {
690
698
println ! ( "Your callback is {alloc_callback:p}" ) ;
691
699
}
692
700
693
-
694
701
#[ no_mangle]
695
702
pub extern "C" fn callback_test10 ( cb : extern "C" fn ( a : i32 ) -> i32 ) -> i32 {
696
703
cb ( 100 )
@@ -700,12 +707,12 @@ use counter::Args;
700
707
use counter:: Counter ;
701
708
702
709
#[ no_mangle]
703
- pub extern fn counterCreate ( args : Args ) -> * mut Counter {
710
+ pub extern "C" fn counterCreate ( args : Args ) -> * mut Counter {
704
711
unsafe { transmute :: < Box < _ > , * mut _ > ( Box :: new ( Counter :: new ( args) ) ) }
705
712
}
706
713
707
714
#[ no_mangle]
708
- pub unsafe extern fn counterGetValue ( ptr : * mut Counter ) -> u32 {
715
+ pub unsafe extern "C" fn counterGetValue ( ptr : * mut Counter ) -> u32 {
709
716
let mut _counter = unsafe { & mut * ptr } ;
710
717
_counter. get ( )
711
718
}
@@ -719,4 +726,4 @@ pub enum CResultStatus {
719
726
#[ no_mangle]
720
727
pub extern "C" fn enum_test2 ( status : CResultStatus ) -> i32 {
721
728
status as i32
722
- }
729
+ }
0 commit comments