Skip to content

Commit

Permalink
we have to expect non-utf8 strings in tracing messages (#770)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Stephan Dilly authored Nov 30, 2021
1 parent c7025a7 commit 4979a86
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ impl Binding for TraceLevel {
}
}

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

static CALLBACK: AtomicUsize = AtomicUsize::new(0);
Expand All @@ -76,7 +79,7 @@ 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_str().unwrap();
cb(Binding::from_raw(level), msg);
let msg = std::ffi::CStr::from_ptr(msg).to_string_lossy();
cb(Binding::from_raw(level), msg.as_ref());
});
}

0 comments on commit 4979a86

Please sign in to comment.