mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
@@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/common/zalloc"
|
||||
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
||||
keywords = []
|
||||
edition = "2021"
|
||||
rust-version = "1.60"
|
||||
rust-version = "1.77.0"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
@@ -19,8 +19,10 @@ workspace = true
|
||||
[dependencies]
|
||||
zeroize = { version = "^1.5", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
rustversion = { version = "1", default-features = false }
|
||||
|
||||
[features]
|
||||
std = ["zeroize/std"]
|
||||
default = ["std"]
|
||||
# Commented for now as it requires nightly and we don't use nightly
|
||||
# allocator = []
|
||||
allocator = []
|
||||
|
||||
10
common/zalloc/build.rs
Normal file
10
common/zalloc/build.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
#[rustversion::nightly]
|
||||
fn main() {
|
||||
println!("cargo::rustc-check-cfg=cfg(zalloc_rustc_nightly)");
|
||||
println!("cargo::rustc-cfg=zalloc_rustc_nightly");
|
||||
}
|
||||
|
||||
#[rustversion::not(nightly)]
|
||||
fn main() {
|
||||
println!("cargo::rustc-check-cfg=cfg(zalloc_rustc_nightly)");
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
#![cfg_attr(feature = "allocator", feature(allocator_api))]
|
||||
#![cfg_attr(all(zalloc_rustc_nightly, feature = "allocator"), feature(allocator_api))]
|
||||
|
||||
//! Implementation of a Zeroizing Allocator, enabling zeroizing memory on deallocation.
|
||||
//! This can either be used with Box (requires nightly and the "allocator" feature) to provide the
|
||||
@@ -17,12 +17,12 @@ use zeroize::Zeroize;
|
||||
/// An allocator wrapper which zeroizes its memory on dealloc.
|
||||
pub struct ZeroizingAlloc<T>(pub T);
|
||||
|
||||
#[cfg(feature = "allocator")]
|
||||
#[cfg(all(zalloc_rustc_nightly, feature = "allocator"))]
|
||||
use core::{
|
||||
ptr::NonNull,
|
||||
alloc::{AllocError, Allocator},
|
||||
};
|
||||
#[cfg(feature = "allocator")]
|
||||
#[cfg(all(zalloc_rustc_nightly, feature = "allocator"))]
|
||||
unsafe impl<T: Allocator> Allocator for ZeroizingAlloc<T> {
|
||||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
|
||||
self.0.allocate(layout)
|
||||
|
||||
Reference in New Issue
Block a user