Mercurial > crates > nonstick
comparison src/libpam/memory.rs @ 100:3f11b8d30f63
Implement environment variable management.
This actually wires up the environment variable handling to libpam,
so that applications and modules can manage the environment through
the authentication process.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 24 Jun 2025 17:08:01 -0400 |
parents | b87100c5eed4 |
children |
comparison
equal
deleted
inserted
replaced
99:8840fa6534f6 | 100:3f11b8d30f63 |
---|---|
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; | 9 use std::mem::{offset_of, 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 | 14 |
94 Self(ptr) | 94 Self(ptr) |
95 } | 95 } |
96 | 96 |
97 /// Converts this CBox into a raw pointer. | 97 /// Converts this CBox into a raw pointer. |
98 pub fn into_ptr(this: Self) -> NonNull<T> { | 98 pub fn into_ptr(this: Self) -> NonNull<T> { |
99 let ret = this.0; | 99 ManuallyDrop::new(this).0 |
100 mem::forget(this); | |
101 ret | |
102 } | 100 } |
103 | 101 |
104 /// Gets a pointer from this but doesn't convert this into a raw pointer. | 102 /// Gets a pointer from this but doesn't convert this into a raw pointer. |
105 /// | 103 /// |
106 /// You are responsible for ensuring the CHeapBox lives long enough. | 104 /// You are responsible for ensuring the CHeapBox lives long enough. |
175 | 173 |
176 /// Converts this C heap string into a raw pointer. | 174 /// Converts this C heap string into a raw pointer. |
177 /// | 175 /// |
178 /// You are responsible for freeing it later. | 176 /// You are responsible for freeing it later. |
179 pub fn into_ptr(self) -> NonNull<c_char> { | 177 pub fn into_ptr(self) -> NonNull<c_char> { |
180 let ptr = CHeapBox::as_ptr(&self.0); | 178 let this = ManuallyDrop::new(self); |
181 mem::forget(self); | 179 CHeapBox::as_ptr(&this.0) |
182 ptr | |
183 } | 180 } |
184 | 181 |
185 /// Converts this into a dumb box. It will no longer be zeroed upon drop. | 182 /// Converts this into a dumb box. It will no longer be zeroed upon drop. |
186 pub fn into_box(self) -> CHeapBox<c_char> { | 183 pub fn into_box(self) -> CHeapBox<c_char> { |
187 unsafe { mem::transmute(self) } | 184 unsafe { mem::transmute(self) } |