gstreamer: Use glib::StrV internally instead of a custom version of it

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1180>
This commit is contained in:
Sebastian Dröge 2023-01-03 12:23:21 +02:00 committed by GStreamer Marge Bot
parent 81bcf5c8dd
commit 0ed3d95c60
2 changed files with 9 additions and 27 deletions

View file

@ -7,6 +7,7 @@ use glib::{
Cast, StaticType,
};
use libc::c_char;
use std::ptr;
use crate::{BufferPool, BufferPoolAcquireParams, BufferPoolConfigRef};
@ -278,17 +279,6 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
}
}
// Send+Sync wrapper around a NULL-terminated C string array
struct CStrV(*mut *const libc::c_char);
unsafe impl Send for CStrV {}
unsafe impl Sync for CStrV {}
impl Drop for CStrV {
fn drop(&mut self) {
unsafe { glib::ffi::g_strfreev(self.0 as *mut _) };
}
}
unsafe impl<T: BufferPoolImpl> IsSubclassable<T> for BufferPool {
fn class_init(klass: &mut glib::Class<Self>) {
Self::parent_class_init::<T>(klass);
@ -312,8 +302,7 @@ unsafe impl<T: BufferPoolImpl> IsSubclassable<T> for BufferPool {
// Store the pool options in the instance data
// for later retrieval in buffer_pool_get_options
let options = T::options();
let options = options.to_glib_full();
instance.set_instance_data(T::type_(), CStrV(options));
instance.set_instance_data(T::type_(), glib::StrV::from(options));
}
}
@ -468,9 +457,9 @@ unsafe extern "C" fn buffer_pool_get_options<T: BufferPoolImpl>(
) -> *mut *const c_char {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
T::instance_data::<CStrV>(imp, T::type_())
.unwrap_or(&CStrV(std::ptr::null_mut()))
.0
T::instance_data::<glib::StrV>(imp, T::type_())
.map(|p| p.as_ptr() as *mut *const _)
.unwrap_or(ptr::null_mut())
}
unsafe extern "C" fn buffer_pool_set_config<T: BufferPoolImpl>(

View file

@ -78,11 +78,6 @@ impl<T: URIHandlerImpl> URIHandlerImplExt for T {
}
}
// Send+Sync wrapper around a NULL-terminated C string array
struct CStrV(*const *const libc::c_char);
unsafe impl Send for CStrV {}
unsafe impl Sync for CStrV {}
unsafe impl<T: URIHandlerImpl> IsImplementable<T> for URIHandler {
fn interface_init(iface: &mut glib::Interface<Self>) {
let iface = iface.as_mut();
@ -91,10 +86,8 @@ unsafe impl<T: URIHandlerImpl> IsImplementable<T> for URIHandler {
unsafe {
let mut data = T::type_data();
let protocols = T::protocols();
let protocols = protocols.to_glib_full();
let data = data.as_mut();
data.set_class_data(Self::static_type(), CStrV(protocols));
data.set_class_data(Self::static_type(), glib::StrV::from(protocols));
}
iface.get_type = Some(uri_handler_get_type::<T>);
@ -115,9 +108,9 @@ unsafe extern "C" fn uri_handler_get_protocols<T: URIHandlerImpl>(
) -> *const *const libc::c_char {
let data = <T as ObjectSubclassType>::type_data();
data.as_ref()
.class_data::<CStrV>(URIHandler::static_type())
.unwrap_or(&CStrV(std::ptr::null()))
.0
.class_data::<glib::StrV>(URIHandler::static_type())
.map(|p| p.as_ptr() as *const *const _)
.unwrap_or(ptr::null())
}
unsafe extern "C" fn uri_handler_get_uri<T: URIHandlerImpl>(