Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions cairo/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ impl Surface {
#[doc(alias = "cairo_surface_get_mime_data")]
#[doc(alias = "get_mime_data")]
pub fn mime_data(&self, mime_type: &str) -> Option<Vec<u8>> {
let data_ptr: *mut u8 = ptr::null_mut();
let mut data_ptr: *mut u8 = ptr::null_mut();
let mut length: c_ulong = 0;
// The function actually needs a mutable pointer
#[allow(clippy::unnecessary_mut_passed)]
unsafe {
let mime_type = CString::new(mime_type).unwrap();
ffi::cairo_surface_get_mime_data(
self.to_raw_none(),
mime_type.as_ptr(),
&data_ptr,
&mut data_ptr,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not a false positive. That code was completely broken

&mut length,
);
if !data_ptr.is_null() && length != 0 {
Expand All @@ -99,15 +101,19 @@ impl Surface {
#[doc(alias = "cairo_surface_get_mime_data")]
#[doc(alias = "get_mime_data_raw")]
pub unsafe fn mime_data_raw(&self, mime_type: &str) -> Option<&[u8]> {
let data_ptr: *mut u8 = ptr::null_mut();
let mut data_ptr: *mut u8 = ptr::null_mut();
let mut length: c_ulong = 0;
let mime_type = CString::new(mime_type).unwrap();
ffi::cairo_surface_get_mime_data(
self.to_raw_none(),
mime_type.as_ptr(),
&data_ptr,
&mut length,
);
// The function actually needs a mutable pointer
#[allow(clippy::unnecessary_mut_passed)]
{
ffi::cairo_surface_get_mime_data(
self.to_raw_none(),
mime_type.as_ptr(),
&mut data_ptr,
&mut length,
);
}
if !data_ptr.is_null() && length != 0 {
Some(slice::from_raw_parts(
data_ptr as *const u8,
Expand Down
2 changes: 1 addition & 1 deletion gdk-pixbuf/src/pixbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Pixbuf {
let bits_per_sample = bits_per_sample as usize;

let n_channels = if has_alpha { 4 } else { 3 };
let last_row_len = width * ((n_channels * bits_per_sample + 7) / 8);
let last_row_len = width * (n_channels * bits_per_sample).div_ceil(8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a 7 isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a +7 before and that change seemed unrelated to clippy fixes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That (x + 7) / 8 is the same as dividing by 8 and rounding up (which is what div_ceil() does)


let mut data: Box<T> = Box::new(data);

Expand Down
2 changes: 1 addition & 1 deletion gio/src/input_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl<T: IsA<InputStream>> InputStreamAsyncBufRead<T> {

fn set_has_data(&mut self, buffer: Vec<u8>, valid: (usize, usize)) {
match self.state {
State::Reading { .. } | State::Transitioning { .. } => {
State::Reading { .. } | State::Transitioning => {
self.state = State::HasData { buffer, valid }
}
_ => panic!("Invalid state"),
Expand Down
43 changes: 28 additions & 15 deletions gio/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#[cfg(unix)]
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket};
use std::os::windows::io::{
AsRawSocket, AsSocket, BorrowedSocket, FromRawSocket, IntoRawSocket, OwnedSocket, RawSocket,
};
#[cfg(feature = "v2_60")]
use std::time::Duration;
use std::{cell::RefCell, marker::PhantomData, mem::transmute, pin::Pin, ptr};
Expand All @@ -27,22 +29,24 @@ impl Socket {
if error.is_null() {
Ok(from_glib_full(ret))
} else {
libc::close(fd);
let _ = OwnedFd::from_raw_fd(fd);
Err(from_glib_full(error))
}
}
}
#[cfg(windows)]
#[cfg_attr(docsrs, doc(cfg(windows)))]
#[allow(clippy::missing_safety_doc)]
pub unsafe fn from_socket(socket: impl IntoRawSocket) -> Result<Socket, glib::Error> {
pub fn from_socket(socket: OwnedSocket) -> Result<Socket, glib::Error> {
let socket = socket.into_raw_socket();
let mut error = ptr::null_mut();
let ret = ffi::g_socket_new_from_fd(socket as i32, &mut error);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
unsafe {
let ret = ffi::g_socket_new_from_fd(socket as i32, &mut error);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
let _ = OwnedSocket::from_raw_socket(socket);
Err(from_glib_full(error))
}
}
}
}
Expand Down Expand Up @@ -74,6 +78,17 @@ impl AsRawSocket for Socket {
}
}

#[cfg(windows)]
#[cfg_attr(docsrs, doc(cfg(windows)))]
impl AsSocket for Socket {
fn as_socket(&self) -> BorrowedSocket<'_> {
unsafe {
let raw_socket = self.as_raw_socket();
BorrowedSocket::borrow_raw(raw_socket)
}
}
}

#[doc(alias = "GInputVector")]
#[repr(transparent)]
#[derive(Debug)]
Expand Down Expand Up @@ -646,18 +661,16 @@ pub trait SocketExtManual: IsA<Socket> + Sized {
#[cfg_attr(docsrs, doc(cfg(unix)))]
#[doc(alias = "get_fd")]
#[doc(alias = "g_socket_get_fd")]
fn fd<T: FromRawFd>(&self) -> T {
unsafe { FromRawFd::from_raw_fd(ffi::g_socket_get_fd(self.as_ref().to_glib_none().0)) }
fn fd(&self) -> BorrowedFd<'_> {
self.as_ref().as_fd()
}

#[cfg(windows)]
#[cfg_attr(docsrs, doc(cfg(windows)))]
#[doc(alias = "get_socket")]
#[doc(alias = "g_socket_get_fd")]
fn socket<T: FromRawSocket>(&self) -> T {
unsafe {
FromRawSocket::from_raw_socket(ffi::g_socket_get_fd(self.as_ref().to_glib_none().0) as _)
}
fn socket(&self) -> BorrowedSocket<'_> {
self.as_ref().as_socket()
}

#[doc(alias = "g_socket_create_source")]
Expand Down
Loading