From 89c7883202e36fcc4fa3b5d5f95d908089ee898a Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sun, 10 Jan 2021 14:21:50 +0100 Subject: [PATCH] gstreamer: Automatically generate Allocator::alloc Parameter mutability has been fixed (and reverted, hence overridden with const=true)for this function in gstreamer; it can now be automatically generated. --- gstreamer/Gir.toml | 11 ++++++++- gstreamer/src/allocator.rs | 42 --------------------------------- gstreamer/src/auto/allocator.rs | 34 ++++++++++++++++---------- gstreamer/src/lib.rs | 3 --- 4 files changed, 32 insertions(+), 58 deletions(-) delete mode 100644 gstreamer/src/allocator.rs diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index cb7bf4d13..9fe5ebf4a 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -64,6 +64,8 @@ manual = [ "GLib.Source", "GObject.Object", "GObject.Value", + "Gst.AllocationParams", + "Gst.Memory", "Gst.Segment", "Gst.StaticCaps", "Gst.StaticPadTemplate", @@ -72,7 +74,14 @@ manual = [ [[object]] name = "Gst.Allocator" status = "generate" -manual_traits = ["AllocatorExtManual"] + + [[object.function]] + name = "alloc" + [object.function.return] + nullable_return_is_error = "Failed to allocate memory" + [[object.function.parameter]] + name = "params" + const = true [[object]] name = "Gst.Bin" diff --git a/gstreamer/src/allocator.rs b/gstreamer/src/allocator.rs deleted file mode 100644 index 5c9d5b547..000000000 --- a/gstreamer/src/allocator.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Take a look at the license at the top of the repository in the LICENSE file. - -use std::ptr; - -use glib::translate::from_glib_full; -use glib::IsA; - -use crate::AllocationParams; -use crate::Allocator; -use crate::Memory; - -pub trait AllocatorExtManual: 'static { - fn alloc( - &self, - size: usize, - params: Option<&AllocationParams>, - ) -> Result; -} - -impl> AllocatorExtManual for O { - fn alloc( - &self, - size: usize, - params: Option<&AllocationParams>, - ) -> Result { - unsafe { - let ret = ffi::gst_allocator_alloc( - self.as_ptr() as *mut _, - size, - match params { - Some(val) => val.as_ptr() as *mut _, - None => ptr::null_mut(), - }, - ); - if ret.is_null() { - Err(glib::bool_error!("Failed to allocate memory")) - } else { - Ok(from_glib_full(ret)) - } - } - } -} diff --git a/gstreamer/src/auto/allocator.rs b/gstreamer/src/auto/allocator.rs index 15e46d152..07dfab90f 100644 --- a/gstreamer/src/auto/allocator.rs +++ b/gstreamer/src/auto/allocator.rs @@ -2,6 +2,8 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +use crate::AllocationParams; +use crate::Memory; use crate::Object; use glib::object::IsA; use glib::translate::*; @@ -36,24 +38,32 @@ unsafe impl Sync for Allocator {} pub const NONE_ALLOCATOR: Option<&Allocator> = None; pub trait AllocatorExt: 'static { - //#[doc(alias = "gst_allocator_alloc")] - //fn alloc(&self, size: usize, params: /*Ignored*/Option<&mut AllocationParams>) -> /*Ignored*/Option; - - //#[doc(alias = "gst_allocator_free")] - //fn free(&self, memory: /*Ignored*/&mut Memory); + #[doc(alias = "gst_allocator_alloc")] + fn alloc( + &self, + size: usize, + params: Option<&AllocationParams>, + ) -> Result; #[doc(alias = "gst_allocator_set_default")] fn set_default(&self); } impl> AllocatorExt for O { - //fn alloc(&self, size: usize, params: /*Ignored*/Option<&mut AllocationParams>) -> /*Ignored*/Option { - // unsafe { TODO: call ffi:gst_allocator_alloc() } - //} - - //fn free(&self, memory: /*Ignored*/&mut Memory) { - // unsafe { TODO: call ffi:gst_allocator_free() } - //} + fn alloc( + &self, + size: usize, + params: Option<&AllocationParams>, + ) -> Result { + unsafe { + Option::<_>::from_glib_full(ffi::gst_allocator_alloc( + self.as_ref().to_glib_none().0, + size, + mut_override(params.to_glib_none().0), + )) + .ok_or_else(|| glib::bool_error!("Failed to allocate memory")) + } + } fn set_default(&self) { unsafe { diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 3002034e5..9c1b2cebf 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -126,8 +126,6 @@ mod element; mod bin; -mod allocator; -pub use crate::allocator::AllocatorExtManual; mod pipeline; pub use crate::pipeline::GstPipelineExtManual; @@ -317,7 +315,6 @@ pub mod prelude { pub use crate::meta::MetaAPI; - pub use crate::allocator::AllocatorExtManual; pub use crate::bin::GstBinExtManual; pub use crate::element::{ElementClassExt, ElementExtManual};