Silence a bunch of clippy warnings.

https://github.com/mozilla/cubeb-pulse-rs/issues/95 tracks fixing these
in the future.
This commit is contained in:
Miriam Zimmerman 2024-10-08 21:18:05 -04:00 коммит произвёл Matthew Gregan
Родитель 33037038ca
Коммит 1161a7b5d9
5 изменённых файлов: 61 добавлений и 2 удалений

Просмотреть файл

@ -48,6 +48,9 @@ use *;
// mem::forget(object);
// result
// For all clippy-ignored warnings in this file, see
// https://github.com/mozilla/cubeb-pulse-rs/issues/95 for the effort to fix.
// Aid in returning Operation from callbacks
macro_rules! op_or_err {
($self_:ident, $e:expr) => {{
@ -78,6 +81,7 @@ impl Context {
}
#[doc(hidden)]
#[allow(clippy::mut_from_ref)]
pub fn raw_mut(&self) -> &mut ffi::pa_context {
unsafe { &mut *self.0 }
}
@ -94,6 +98,7 @@ impl Context {
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_state_callback<CB>(&self, _: CB, userdata: *mut c_void)
where
CB: Fn(&Context, *mut c_void),
@ -108,6 +113,7 @@ impl Context {
let ctx = context::from_raw_ptr(c);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}
@ -125,6 +131,7 @@ impl Context {
.expect("pa_context_get_state returned invalid ContextState")
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn connect<'a, OPT>(
&self,
server: OPT,
@ -151,6 +158,7 @@ impl Context {
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn drain<CB>(&self, _: CB, userdata: *mut c_void) -> Result<Operation>
where
CB: Fn(&Context, *mut c_void),
@ -165,6 +173,7 @@ impl Context {
let ctx = context::from_raw_ptr(c);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}
@ -174,6 +183,7 @@ impl Context {
)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn rttime_new<CB>(
&self,
usec: USec,
@ -198,12 +208,14 @@ impl Context {
let timeval = &*tv;
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&api, e, timeval, userdata);
#[allow(clippy::forget_non_drop)]
forget(api);
}
unsafe { ffi::pa_context_rttime_new(self.raw_mut(), usec, Some(wrapped::<CB>), userdata) }
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn get_server_info<CB>(&self, _: CB, userdata: *mut c_void) -> Result<Operation>
where
CB: Fn(&Context, Option<&ServerInfo>, *mut c_void),
@ -222,6 +234,7 @@ impl Context {
let ctx = context::from_raw_ptr(c);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, info, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}
@ -231,6 +244,7 @@ impl Context {
)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn get_sink_info_by_name<'str, CS, CB>(
&self,
name: CS,
@ -255,6 +269,7 @@ impl Context {
let ctx = context::from_raw_ptr(c);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, info, eol, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}
@ -269,6 +284,7 @@ impl Context {
)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn get_sink_info_list<CB>(&self, _: CB, userdata: *mut c_void) -> Result<Operation>
where
CB: Fn(&Context, *const SinkInfo, i32, *mut c_void),
@ -287,6 +303,7 @@ impl Context {
let ctx = context::from_raw_ptr(c);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, info, eol, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}
@ -296,6 +313,7 @@ impl Context {
)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn get_sink_input_info<CB>(
&self,
idx: u32,
@ -319,6 +337,7 @@ impl Context {
let ctx = context::from_raw_ptr(c);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, info, eol, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}
@ -328,6 +347,7 @@ impl Context {
)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn get_source_info_list<CB>(&self, _: CB, userdata: *mut c_void) -> Result<Operation>
where
CB: Fn(&Context, *const SourceInfo, i32, *mut c_void),
@ -346,6 +366,7 @@ impl Context {
let ctx = context::from_raw_ptr(c);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, info, eol, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}
@ -355,6 +376,7 @@ impl Context {
)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_sink_input_volume<CB>(
&self,
idx: u32,
@ -378,6 +400,7 @@ impl Context {
let ctx = context::from_raw_ptr(c);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, success, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}
@ -393,6 +416,7 @@ impl Context {
)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn subscribe<CB>(
&self,
m: SubscriptionMask,
@ -415,6 +439,7 @@ impl Context {
let ctx = context::from_raw_ptr(c);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, success, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}
@ -430,6 +455,7 @@ impl Context {
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_subscribe_callback<CB>(&self, _: CB, userdata: *mut c_void)
where
CB: Fn(&Context, SubscriptionEvent, u32, *mut c_void),
@ -450,6 +476,7 @@ impl Context {
.expect("pa_context_subscribe_cb_t passed invalid pa_subscription_event_type_t");
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&ctx, event, idx, userdata);
#[allow(clippy::forget_non_drop)]
forget(ctx);
}

Просмотреть файл

@ -7,6 +7,9 @@ use ffi;
use std::mem;
use std::os::raw::c_void;
// Note: For all clippy allowed warnings, see https://github.com/mozilla/cubeb-pulse-rs/issues/95
// for the effort to fix them.
#[allow(non_camel_case_types)]
type pa_once_cb_t =
Option<unsafe extern "C" fn(m: *mut ffi::pa_mainloop_api, userdata: *mut c_void)>;
@ -21,7 +24,9 @@ where
F: Fn(&MainloopApi, *mut c_void),
{
let api = from_raw_ptr(m);
#[allow(clippy::missing_transmute_annotations)]
mem::transmute::<_, &F>(&())(&api, userdata);
#[allow(clippy::forget_non_drop)]
mem::forget(api);
}
@ -31,10 +36,12 @@ where
pub struct MainloopApi(*mut ffi::pa_mainloop_api);
impl MainloopApi {
#[allow(clippy::mut_from_ref)]
pub fn raw_mut(&self) -> &mut ffi::pa_mainloop_api {
unsafe { &mut *self.0 }
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn once<CB>(&self, cb: CB, userdata: *mut c_void)
where
CB: Fn(&MainloopApi, *mut c_void),
@ -45,6 +52,7 @@ impl MainloopApi {
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn time_free(&self, e: *mut ffi::pa_time_event) {
unsafe {
if let Some(f) = self.raw_mut().time_free {

Просмотреть файл

@ -9,6 +9,8 @@ use ffi;
pub struct Operation(*mut ffi::pa_operation);
impl Operation {
// See https://github.com/mozilla/cubeb-pulse-rs/issues/95
#[allow(clippy::missing_safety_doc)]
pub unsafe fn from_raw_ptr(raw: *mut ffi::pa_operation) -> Operation {
Operation(raw)
}

Просмотреть файл

@ -16,6 +16,9 @@ use *;
#[derive(Debug)]
pub struct Stream(*mut ffi::pa_stream);
// Note: For all clippy allowed warnings, see https://github.com/mozilla/cubeb-pulse-rs/issues/95
// for the effort to fix them.
impl Stream {
pub fn new<'a, CM>(
c: &Context,
@ -42,6 +45,7 @@ impl Stream {
}
#[doc(hidden)]
#[allow(clippy::mut_from_ref)]
pub fn raw_mut(&self) -> &mut ffi::pa_stream {
unsafe { &mut *self.0 }
}
@ -154,6 +158,7 @@ impl Stream {
error_result!((), r)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn write(
&self,
data: *const c_void,
@ -167,6 +172,7 @@ impl Stream {
error_result!((), r)
}
#[allow(clippy::missing_safety_doc)]
pub unsafe fn peek(&self, data: *mut *const c_void, length: *mut usize) -> Result<()> {
let r = ffi::pa_stream_peek(self.raw_mut(), data, length);
error_result!((), r)
@ -179,7 +185,7 @@ impl Stream {
pub fn writable_size(&self) -> Result<usize> {
let r = unsafe { ffi::pa_stream_writable_size(self.raw_mut()) };
if r == ::std::usize::MAX {
if r == usize::MAX {
let err = if let Some(c) = self.get_context() {
c.errno()
} else {
@ -192,7 +198,7 @@ impl Stream {
pub fn readable_size(&self) -> Result<usize> {
let r = unsafe { ffi::pa_stream_readable_size(self.raw_mut()) };
if r == ::std::usize::MAX {
if r == usize::MAX {
let err = if let Some(c) = self.get_context() {
c.errno()
} else {
@ -203,6 +209,7 @@ impl Stream {
Ok(r)
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn update_timing_info<CB>(&self, _: CB, userdata: *mut c_void) -> Result<Operation>
where
CB: Fn(&Stream, i32, *mut c_void),
@ -220,6 +227,7 @@ impl Stream {
let mut stm = stream::from_raw_ptr(s);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&mut stm, success, userdata);
#[allow(clippy::forget_non_drop)]
forget(stm);
}
@ -243,6 +251,7 @@ impl Stream {
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_state_callback<CB>(&self, _: CB, userdata: *mut c_void)
where
CB: Fn(&Stream, *mut c_void),
@ -257,6 +266,7 @@ impl Stream {
let mut stm = stream::from_raw_ptr(s);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&mut stm, userdata);
#[allow(clippy::forget_non_drop)]
forget(stm);
}
@ -271,6 +281,7 @@ impl Stream {
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_write_callback<CB>(&self, _: CB, userdata: *mut c_void)
where
CB: Fn(&Stream, usize, *mut c_void),
@ -288,6 +299,7 @@ impl Stream {
let mut stm = stream::from_raw_ptr(s);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&mut stm, nbytes, userdata);
#[allow(clippy::forget_non_drop)]
forget(stm);
}
@ -302,6 +314,7 @@ impl Stream {
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_read_callback<CB>(&self, _: CB, userdata: *mut c_void)
where
CB: Fn(&Stream, usize, *mut c_void),
@ -319,6 +332,7 @@ impl Stream {
let mut stm = stream::from_raw_ptr(s);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&mut stm, nbytes, userdata);
#[allow(clippy::forget_non_drop)]
forget(stm);
}
@ -327,6 +341,7 @@ impl Stream {
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn cork<CB>(&self, b: i32, _: CB, userdata: *mut c_void) -> Result<Operation>
where
CB: Fn(&Stream, i32, *mut c_void),
@ -344,6 +359,7 @@ impl Stream {
let mut stm = stream::from_raw_ptr(s);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&mut stm, success, userdata);
#[allow(clippy::forget_non_drop)]
forget(stm);
}
@ -403,6 +419,7 @@ impl Stream {
}
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn set_name<CB>(&self, name: &CStr, _: CB, userdata: *mut c_void) -> Result<Operation>
where
CB: Fn(&Stream, i32, *mut c_void),
@ -420,6 +437,7 @@ impl Stream {
let mut stm = stream::from_raw_ptr(s);
let cb = MaybeUninit::<F>::uninit();
(*cb.as_ptr())(&mut stm, success, userdata);
#[allow(clippy::forget_non_drop)]
forget(stm);
}

Просмотреть файл

@ -13,6 +13,8 @@ use Result;
pub struct ThreadedMainloop(*mut ffi::pa_threaded_mainloop);
impl ThreadedMainloop {
// see https://github.com/mozilla/cubeb-pulse-rs/issues/95
#[allow(clippy::missing_safety_doc)]
pub unsafe fn from_raw_ptr(raw: *mut ffi::pa_threaded_mainloop) -> Self {
ThreadedMainloop(raw)
}
@ -21,6 +23,8 @@ impl ThreadedMainloop {
unsafe { ThreadedMainloop::from_raw_ptr(ffi::pa_threaded_mainloop_new()) }
}
// see https://github.com/mozilla/cubeb-pulse-rs/issues/95
#[allow(clippy::mut_from_ref)]
pub fn raw_mut(&self) -> &mut ffi::pa_threaded_mainloop {
unsafe { &mut *self.0 }
}