comparison src/libpam/memory.rs @ 105:13b4d2a19674

Support Rust v1.75.0. This is the version included in Ubuntu 24.04 LTS and Debian Trixie, so it's old enough to have wide penetration without being too old to get new features (Debian Stable, I love you but v1.63 is just not going to work out).
author Paul Fisher <paul@pfish.zone>
date Thu, 26 Jun 2025 00:48:51 -0400
parents 3f11b8d30f63
children 49d9e2b5c189
comparison
equal deleted inserted replaced
104:a2676475e86b 105:13b4d2a19674
4 use crate::{BinaryData, ErrorCode}; 4 use crate::{BinaryData, ErrorCode};
5 use std::error::Error; 5 use std::error::Error;
6 use std::ffi::{c_char, CStr, CString}; 6 use std::ffi::{c_char, CStr, CString};
7 use std::fmt::{Display, Formatter, Result as FmtResult}; 7 use std::fmt::{Display, Formatter, Result as FmtResult};
8 use std::marker::{PhantomData, PhantomPinned}; 8 use std::marker::{PhantomData, PhantomPinned};
9 use std::mem::{offset_of, ManuallyDrop}; 9 use std::mem::{ManuallyDrop};
10 use std::ops::{Deref, DerefMut}; 10 use std::ops::{Deref, DerefMut};
11 use std::ptr::NonNull; 11 use std::ptr::NonNull;
12 use std::result::Result as StdResult; 12 use std::result::Result as StdResult;
13 use std::{mem, ptr, slice}; 13 use std::{mem, ptr, slice};
14 use memoffset::offset_of;
14 15
15 /// Raised from `calloc` when you have no memory! 16 /// Raised from `calloc` when you have no memory!
16 #[derive(Debug)] 17 #[derive(Debug)]
17 pub struct NoMem; 18 pub struct NoMem;
18 19
32 33
33 /// Allocates `count` elements to hold `T`. 34 /// Allocates `count` elements to hold `T`.
34 #[inline] 35 #[inline]
35 pub fn calloc<T>(count: usize) -> StdResult<NonNull<T>, NoMem> { 36 pub fn calloc<T>(count: usize) -> StdResult<NonNull<T>, NoMem> {
36 // SAFETY: it's always safe to allocate! Leaking memory is fun! 37 // SAFETY: it's always safe to allocate! Leaking memory is fun!
37 NonNull::new(unsafe { libc::calloc(count, size_of::<T>()) }.cast()).ok_or(NoMem) 38 NonNull::new(unsafe { libc::calloc(count, mem::size_of::<T>()) }.cast()).ok_or(NoMem)
38 } 39 }
39 40
40 /// Wrapper for [`libc::free`] to make debugging calls/frees easier. 41 /// Wrapper for [`libc::free`] to make debugging calls/frees easier.
41 /// 42 ///
42 /// # Safety 43 /// # Safety