From e06e0fb33ece48cd4115766b383f1063ede61576 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 30 Oct 2024 20:59:39 -0300 Subject: [PATCH] validate: Fix refcount handling for action.set_done() Also fix the test making proper use of it. Part-of: --- gstreamer-validate/src/action.rs | 20 +++++++++----------- gstreamer-validate/tests/validate.rs | 5 ++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/gstreamer-validate/src/action.rs b/gstreamer-validate/src/action.rs index 4b9d2640d..8c0b18ccf 100644 --- a/gstreamer-validate/src/action.rs +++ b/gstreamer-validate/src/action.rs @@ -27,15 +27,6 @@ impl ActionRef { gst::StructureRef::from_glib_borrow_mut((*action).structure) } } - - #[doc(alias = "gst_validate_action_set_done")] - pub fn set_done(&self) { - unsafe { - let action = self.as_mut_ptr(); - - ffi::gst_validate_action_set_done(action); - } - } } impl Action { @@ -65,9 +56,9 @@ impl Action { } #[doc(alias = "gst_validate_execute_action")] - pub fn execute(&self) -> Result { + pub fn execute(self) -> Result { unsafe { - let action: *mut ffi::GstValidateAction = self.to_glib_none().0; + let action: *mut ffi::GstValidateAction = self.to_glib_full(); let action_type = ffi::gst_validate_get_action_type((*action).type_); let res = ffi::gst_validate_execute_action(action_type, action); @@ -79,6 +70,13 @@ impl Action { } } } + + #[doc(alias = "gst_validate_action_set_done")] + pub fn set_done(self) { + unsafe { + ffi::gst_validate_action_set_done(self.into_glib_ptr()); + } + } } impl std::fmt::Debug for Action { diff --git a/gstreamer-validate/tests/validate.rs b/gstreamer-validate/tests/validate.rs index 1416ed5dc..e7fd874a1 100644 --- a/gstreamer-validate/tests/validate.rs +++ b/gstreamer-validate/tests/validate.rs @@ -60,7 +60,7 @@ fn test_action_types() { // Write scenario to temporary file let mut file = tempfile::NamedTempFile::new().unwrap(); - file.write_all(b"succeeds").unwrap(); + file.write_all(b"stop, on-message=eos").unwrap(); let runner = gst_validate::Runner::new(); let pipeline = gst::Pipeline::new(); @@ -89,6 +89,7 @@ fn test_action_types() { assert!(!*fails_called.lock().unwrap()); action.execute().expect_err("Action should have failed"); assert!(*fails_called.lock().unwrap()); + action.set_done(); gst_validate::ActionParameterBuilder::new("async", "Verify unused param are properly cleaned") .default_value("true") @@ -105,8 +106,6 @@ fn test_action_types() { std::thread::spawn(glib::clone!( #[strong] async_called, - #[strong] - action, move || { *async_called.0.lock().unwrap() = true; action.set_done();