Skip to content

Commit fd53249

Browse files
author
Stephan Dilly
committed
pass tracing msg as slice instead of &str
1 parent 5938cfd commit fd53249

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/tracing.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Binding for TraceLevel {
5757
}
5858
}
5959

60-
pub type TracingCb = fn(TraceLevel, &str);
60+
pub type TracingCb = fn(TraceLevel, &[u8]);
6161

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

@@ -76,7 +76,10 @@ extern "C" fn tracing_cb_c(level: raw::git_trace_level_t, msg: *const c_char) {
7676
let cb = CALLBACK.load(Ordering::SeqCst);
7777
panic::wrap(|| unsafe {
7878
let cb: TracingCb = std::mem::transmute(cb);
79-
let msg = std::ffi::CStr::from_ptr(msg).to_string_lossy();
80-
cb(Binding::from_raw(level), msg.as_ref());
79+
80+
if !msg.is_null() {
81+
let msg = std::ffi::CStr::from_ptr(msg).to_bytes();
82+
cb(Binding::from_raw(level), msg);
83+
}
8184
});
8285
}

0 commit comments

Comments
 (0)