From ffad1188b915b4181032eddb84a7e161a2acf7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Fri, 1 Mar 2024 17:39:39 +0100 Subject: [PATCH] net: fix faillible PtpClock::new() `PtpClock::new()` can fail in which case it panicked due to an assertion failure. This commit makes it return a `Result` instead. Also sets the `name` argument optional, similar to what is done for `NtpClock`. See also: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6251 Part-of: --- gstreamer-net/Gir.toml | 11 +++++++++++ gstreamer-net/src/auto/ptp_clock.rs | 10 +++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gstreamer-net/Gir.toml b/gstreamer-net/Gir.toml index f12223924..2b037b86d 100644 --- a/gstreamer-net/Gir.toml +++ b/gstreamer-net/Gir.toml @@ -57,3 +57,14 @@ final_type = true name = "GstNet.PtpClock" status = "generate" final_type = true + [[object.function]] + name = "new" + [[object.function.parameter]] + name = "name" + # See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6251 + nullable = true + + [object.function.return] + # See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6251 + nullable = true + nullable_return_is_error = "Can't create gst::PtpClock" diff --git a/gstreamer-net/src/auto/ptp_clock.rs b/gstreamer-net/src/auto/ptp_clock.rs index d9ea14bc7..50c4aad2e 100644 --- a/gstreamer-net/src/auto/ptp_clock.rs +++ b/gstreamer-net/src/auto/ptp_clock.rs @@ -21,11 +21,15 @@ glib::wrapper! { impl PtpClock { #[doc(alias = "gst_ptp_clock_new")] - pub fn new(name: &str, domain: u32) -> PtpClock { + pub fn new(name: Option<&str>, domain: u32) -> Result { assert_initialized_main_thread!(); unsafe { - gst::Clock::from_glib_full(ffi::gst_ptp_clock_new(name.to_glib_none().0, domain)) - .unsafe_cast() + Option::::from_glib_full(ffi::gst_ptp_clock_new( + name.to_glib_none().0, + domain, + )) + .map(|o| o.unsafe_cast()) + .ok_or_else(|| glib::bool_error!("Can't create gst::PtpClock")) } }