Skip to content

Commit 4979a86

Browse files
author
Stephan Dilly
authored
we have to expect non-utf8 strings in tracing messages (#770)
* we can expect non-utf8 strings in tracing messages * pass tracing msg as slice instead of &str * doc comment * Revert "pass tracing msg as slice instead of &str" This reverts commit 50a990f. # Conflicts: # src/tracing.rs * update doc comment and add todo
1 parent c7025a7 commit 4979a86

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/tracing.rs

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

60+
//TODO: pass raw &[u8] and leave conversion to consumer (breaking API)
61+
/// Callback type used to pass tracing events to the subscriber.
62+
/// see `trace_set` to register a scubscriber.
6063
pub type TracingCb = fn(TraceLevel, &str);
6164

6265
static CALLBACK: AtomicUsize = AtomicUsize::new(0);
@@ -76,7 +79,7 @@ extern "C" fn tracing_cb_c(level: raw::git_trace_level_t, msg: *const c_char) {
7679
let cb = CALLBACK.load(Ordering::SeqCst);
7780
panic::wrap(|| unsafe {
7881
let cb: TracingCb = std::mem::transmute(cb);
79-
let msg = std::ffi::CStr::from_ptr(msg).to_str().unwrap();
80-
cb(Binding::from_raw(level), msg);
82+
let msg = std::ffi::CStr::from_ptr(msg).to_string_lossy();
83+
cb(Binding::from_raw(level), msg.as_ref());
8184
});
8285
}

0 commit comments

Comments
 (0)