Skip to content

Commit

Permalink
pass tracing msg as slice instead of &str
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed Nov 22, 2021
1 parent 5938cfd commit fd53249
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Binding for TraceLevel {
}
}

pub type TracingCb = fn(TraceLevel, &str);
pub type TracingCb = fn(TraceLevel, &[u8]);

static CALLBACK: AtomicUsize = AtomicUsize::new(0);

Expand All @@ -76,7 +76,10 @@ extern "C" fn tracing_cb_c(level: raw::git_trace_level_t, msg: *const c_char) {
let cb = CALLBACK.load(Ordering::SeqCst);
panic::wrap(|| unsafe {
let cb: TracingCb = std::mem::transmute(cb);
let msg = std::ffi::CStr::from_ptr(msg).to_string_lossy();
cb(Binding::from_raw(level), msg.as_ref());

if !msg.is_null() {
let msg = std::ffi::CStr::from_ptr(msg).to_bytes();
cb(Binding::from_raw(level), msg);
}
});
}

0 comments on commit fd53249

Please sign in to comment.