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.
This commit is contained in:
Marijn Suijten 2021-01-10 14:21:50 +01:00
parent 6b94083a07
commit 89c7883202
4 changed files with 32 additions and 58 deletions

View file

@ -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"

View file

@ -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<Memory, glib::BoolError>;
}
impl<O: IsA<Allocator>> AllocatorExtManual for O {
fn alloc(
&self,
size: usize,
params: Option<&AllocationParams>,
) -> Result<Memory, glib::BoolError> {
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))
}
}
}
}

View file

@ -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<Memory>;
//#[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<Memory, glib::BoolError>;
#[doc(alias = "gst_allocator_set_default")]
fn set_default(&self);
}
impl<O: IsA<Allocator>> AllocatorExt for O {
//fn alloc(&self, size: usize, params: /*Ignored*/Option<&mut AllocationParams>) -> /*Ignored*/Option<Memory> {
// 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<Memory, glib::BoolError> {
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 {

View file

@ -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};