diff options
| author | Mason Reed <mason@vector35.com> | 2025-12-17 21:23:46 -0500 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2026-01-11 10:36:01 -0800 |
| commit | 168a3fd34824adc9c6a606cd144219701f15cccf (patch) | |
| tree | 9bbac31ece5ea6ab6627998d995a77f7f7e2f8e6 /rust/src/custom_binary_view.rs | |
| parent | ca91bc1933976c62d24248f0f7c35af38451ff11 (diff) | |
[Rust] Replace `log` with `tracing`
- Added more documentation
- Replaced global named logger for plugins, fixing the issue when the CU has multiple (e.g. statically linked demo)
- Simplified some misc code
This is a breaking change, but I believe there is no better time to make it, we cannot continue to use the `log` crate, it is too limited for our needs.
Diffstat (limited to 'rust/src/custom_binary_view.rs')
| -rw-r--r-- | rust/src/custom_binary_view.rs | 52 |
1 files changed, 16 insertions, 36 deletions
diff --git a/rust/src/custom_binary_view.rs b/rust/src/custom_binary_view.rs index aff7b3b6..8e070b15 100644 --- a/rust/src/custom_binary_view.rs +++ b/rust/src/custom_binary_view.rs @@ -96,10 +96,7 @@ where // to the core -- we're transferring ownership of the Ref here Ref::into_raw(bv.handle).handle } - Err(_) => { - log::error!("CustomBinaryViewType::create_custom_view returned Err"); - ptr::null_mut() - } + Err(_) => ptr::null_mut(), } }) } @@ -124,10 +121,7 @@ where // to the core -- we're transferring ownership of the Ref here Ref::into_raw(bv.handle).handle } - Err(_) => { - log::error!("CustomBinaryViewType::parse returned Err"); - ptr::null_mut() - } + Err(_) => ptr::null_mut(), } }) } @@ -173,7 +167,6 @@ where // be one since view types live for the life of the process) as // MaybeUninit suppress the Drop implementation of it's inner type drop(Box::from_raw(ctxt)); - panic!("bvt registration failed"); } @@ -303,10 +296,7 @@ pub trait BinaryViewTypeExt: BinaryViewTypeBase { let handle = unsafe { BNCreateBinaryViewOfType(self.as_ref().handle, data.handle) }; if handle.is_null() { - log::error!( - "failed to create BinaryView of BinaryViewType '{}'", - self.name() - ); + // TODO: Proper Result, possibly introduce BNSetError to populate. return Err(()); } @@ -317,10 +307,7 @@ pub trait BinaryViewTypeExt: BinaryViewTypeBase { let handle = unsafe { BNParseBinaryViewOfType(self.as_ref().handle, data.handle) }; if handle.is_null() { - log::error!( - "failed to parse BinaryView of BinaryViewType '{}'", - self.name() - ); + // TODO: Proper Result, possibly introduce BNSetError to populate. return Err(()); } @@ -503,7 +490,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { if let Some(bv) = file.view_of_type(&view_name) { // while it seems to work most of the time, you can get really unlucky - // if the a free of the existing view of the same type kicks off while + // if a free of the existing view of the same type kicks off while // BNCreateBinaryViewOfType is still running. the freeObject callback // will run for the new view before we've even finished initializing, // and that's all she wrote. @@ -511,7 +498,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { // even if we deal with it gracefully in cb_free_object, // BNCreateBinaryViewOfType is still going to crash, so we're just // going to try and stop this from happening in the first place. - log::error!( + tracing::error!( "attempt to create duplicate view of type '{}' (existing: {:?})", view_name, bv.handle @@ -572,12 +559,14 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { true } Err(_) => { - log::error!("CustomBinaryView::init failed; custom view returned Err"); + tracing::error!( + "CustomBinaryView::init failed; custom view returned Err" + ); false } }, Err(_) => { - log::error!("CustomBinaryView::new failed; custom view returned Err"); + tracing::error!("CustomBinaryView::new failed; custom view returned Err"); false } } @@ -607,7 +596,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { // // if we're here, it's too late to do anything about it, though we can at least not // run the destructor on the custom view since that memory is uninitialized. - log::error!( + tracing::error!( "BinaryViewBase::freeObject called on partially initialized object! crash imminent!" ); } else if matches!( @@ -626,7 +615,7 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { // // we can't do anything to prevent this, but we can at least have the crash // not be our fault. - log::error!("BinaryViewBase::freeObject called on leaked/never initialized custom view!"); + tracing::error!("BinaryViewBase::freeObject called on leaked/never initialized custom view!"); } }) } @@ -884,20 +873,11 @@ impl<'a, T: CustomBinaryViewType> CustomViewBuilder<'a, T> { parent.handle, &mut bn_obj, ); - - if res.is_null() { - // TODO not sure when this can even happen, let alone what we're supposed to do about - // it. cb_init isn't normally called until later, and cb_free_object definitely won't - // have been called, so we'd at least be on the hook for freeing that stuff... - // probably. - // - // no idea how to force this to fail so I can test this, so just going to do the - // reasonable thing and panic. - panic!("failed to create custom binary view!"); - } - + assert!( + !res.is_null(), + "BNCreateCustomBinaryView cannot return null" + ); (*ctxt).raw_handle = res; - Ok(CustomView { handle: BinaryView::ref_from_raw(res), _builder: PhantomData, |
