File tree 1 file changed +2
-9
lines changed
1 file changed +2
-9
lines changed Original file line number Diff line number Diff line change @@ -35,19 +35,12 @@ fn default_callback(lvl: PrintLevel, msg: &str) {
35
35
let _ = io:: stderr ( ) . write ( msg. as_bytes ( ) ) ;
36
36
}
37
37
38
- // not allowed to use function pointers in const functions, so it needs to be a macro
39
- macro_rules! to_ptr {
40
- ( $x: expr) => {
41
- unsafe { std:: mem:: transmute:: <PrintCallback , * mut ( ) >( $x) }
42
- } ;
43
- }
44
-
45
38
fn from_ptr ( ptr : * mut ( ) ) -> PrintCallback {
46
39
unsafe { std:: mem:: transmute :: < * mut ( ) , PrintCallback > ( ptr) }
47
40
}
48
41
49
42
// There is no AtomicFnPtr. This is a workaround.
50
- static PRINT_CB : AtomicPtr < ( ) > = AtomicPtr :: new ( to_ptr ! ( default_callback) ) ;
43
+ static PRINT_CB : AtomicPtr < ( ) > = AtomicPtr :: new ( default_callback as * mut ( ) ) ;
51
44
52
45
/// libbpf's default cb uses vfprintf's return code...which is ignored everywhere. Mimic that for
53
46
/// completeness
@@ -81,7 +74,7 @@ extern "C" fn outer_print_cb(
81
74
///
82
75
/// This overrides (and is overridden by) [`ObjectBuilder::debug`]
83
76
pub fn set_print ( func : PrintCallback ) -> PrintCallback {
84
- let cb = to_ptr ! ( func) ;
77
+ let cb = func as * mut ( ) ;
85
78
let prev = PRINT_CB . swap ( cb, Ordering :: Relaxed ) ;
86
79
unsafe { libbpf_sys:: libbpf_set_print ( Some ( outer_print_cb) ) } ;
87
80
from_ptr ( prev)
You can’t perform that action at this time.
0 commit comments