gst/log: accept non-ref obj in macros

This commit is contained in:
François Laignel 2022-10-23 20:44:38 +02:00 committed by Sebastian Dröge
parent 83d5efbeb4
commit 2bec28e920
2 changed files with 20 additions and 8 deletions

View file

@ -1328,12 +1328,9 @@ unsafe extern "C" fn base_transform_copy_metadata<T: BaseTransformImpl>(
let imp = instance.imp(); let imp = instance.imp();
if gst::ffi::gst_mini_object_is_writable(outbuf as *mut _) == glib::ffi::GFALSE { if gst::ffi::gst_mini_object_is_writable(outbuf as *mut _) == glib::ffi::GFALSE {
gst::warning!( let instance = imp.instance();
gst::CAT_RUST, let obj = instance.unsafe_cast_ref::<BaseTransform>();
obj: imp.instance().unsafe_cast_ref::<BaseTransform>(), gst::warning!(gst::CAT_RUST, obj: obj, "buffer {:?} not writable", outbuf);
"buffer {:?} not writable",
outbuf
);
return glib::ffi::GFALSE; return glib::ffi::GFALSE;
} }

View file

@ -491,7 +491,11 @@ macro_rules! log_with_level(
// Check the log level before using `format_args!` otherwise // Check the log level before using `format_args!` otherwise
// formatted arguments are evaluated even if we end up not logging. // formatted arguments are evaluated even if we end up not logging.
if $level <= $cat.threshold() { if $level <= $cat.threshold() {
$crate::DebugCategory::log_unfiltered($cat.clone(), Some(&*$obj), use $crate::glib::Cast;
#[allow(unused_unsafe)]
let obj = unsafe { $obj.unsafe_cast_ref::<$crate::glib::Object>() };
$crate::DebugCategory::log_unfiltered($cat.clone(), Some(obj),
$level, file!(), module_path!(), line!(), format_args!($($args)*)) $level, file!(), module_path!(), line!(), format_args!($($args)*))
} }
}}; }};
@ -502,8 +506,9 @@ macro_rules! log_with_level(
use $crate::glib::Cast; use $crate::glib::Cast;
let obj = $imp.instance(); let obj = $imp.instance();
#[allow(unused_unsafe)]
let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() }; let obj = unsafe { obj.unsafe_cast_ref::<$crate::glib::Object>() };
$crate::DebugCategory::log_unfiltered($cat.clone(), Some(&*obj), $crate::DebugCategory::log_unfiltered($cat.clone(), Some(obj),
$level, file!(), module_path!(), line!(), format_args!($($args)*)) $level, file!(), module_path!(), line!(), format_args!($($args)*))
} }
}}; }};
@ -724,6 +729,7 @@ mod tests {
memdump!(cat, "meh"); memdump!(cat, "meh");
let obj = crate::Bin::new(Some("meh")); let obj = crate::Bin::new(Some("meh"));
error!(cat, obj: &obj, "meh"); error!(cat, obj: &obj, "meh");
warning!(cat, obj: &obj, "meh"); warning!(cat, obj: &obj, "meh");
fixme!(cat, obj: &obj, "meh"); fixme!(cat, obj: &obj, "meh");
@ -732,6 +738,15 @@ mod tests {
log!(cat, obj: &obj, "meh"); log!(cat, obj: &obj, "meh");
trace!(cat, obj: &obj, "meh"); trace!(cat, obj: &obj, "meh");
memdump!(cat, obj: &obj, "meh"); memdump!(cat, obj: &obj, "meh");
error!(cat, obj: obj, "meh");
warning!(cat, obj: obj, "meh");
fixme!(cat, obj: obj, "meh");
info!(cat, obj: obj, "meh");
debug!(cat, obj: obj, "meh");
log!(cat, obj: obj, "meh");
trace!(cat, obj: obj, "meh");
memdump!(cat, obj: obj, "meh");
} }
#[test] #[test]