Skip to content

Commit 66c0fd3

Browse files
committed
docs: ProfileStatus -> Cow<'static, CStr> cases
1 parent d3fe67c commit 66c0fd3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

libdd-profiling-ffi/src/profile_status.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,21 @@ impl From<ProfileStatus> for Result<(), Cow<'static, CStr>> {
163163
if cfg!(debug_assertions) && (status.flags & MASK_UNUSED) != 0 {
164164
panic!("invalid bit pattern: {flags:b}");
165165
}
166+
167+
// There are 4 cases:
168+
// - not-allocated, not-error -> Ok(())
169+
// - not-allocated, error -> Err(Cow::Borrowed)
170+
// - allocated, error -> Err(Cow::Owned)
171+
// - allocated, not-error -> nonsense, panic! in debug mode
166172
match (is_allocated, is_error) {
167173
(false, false) => Ok(()),
168174
(false, true) => Err(Cow::Borrowed(unsafe { CStr::from_ptr(status.err) })),
169175
(true, true) => Err(Cow::Owned(unsafe {
170176
CString::from_raw(status.err.cast_mut())
171177
})),
178+
// This would mean there's an allocated error, but there isn't an
179+
// error. That doesn't make sense, and the Rust code doesn't make
180+
// them, only FFI might (but that would violate the usage docs).
172181
(true, false) => {
173182
#[allow(clippy::panic)]
174183
if cfg!(debug_assertions) {

0 commit comments

Comments
 (0)