Skip to content

Commit

Permalink
Merge branch 'master' into ao-mimalloc
Browse files Browse the repository at this point in the history
* master:
  [parity-util-mem] remove Memzero (#183)
  • Loading branch information
ordian committed Jul 4, 2019
2 parents e47d325 + 2a8a33a commit dce9dd0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
3 changes: 1 addition & 2 deletions parity-util-mem/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "parity-util-mem"
version = "0.1.0"
version = "0.2.0"
authors = ["Parity Technologies <admin@parity.io>"]
repository = "https://github.com/paritytech/parity-common"
description = "Collection of memory related utilities"
license = "GPL-3.0"

[dependencies]
clear_on_drop = "0.2"
cfg-if = "0.1.6"
malloc_size_of_derive = "0.1.0"
dlmalloc = { version = "0.1", features = ["global"], optional = true }
Expand Down
39 changes: 0 additions & 39 deletions parity-util-mem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ extern crate alloc;

extern crate malloc_size_of_derive as malloc_size_derive;

use std::ops::{Deref, DerefMut};

use std::ptr;

cfg_if! {
if #[cfg(all(
Expand Down Expand Up @@ -99,42 +96,6 @@ pub use malloc_size::{
};
pub use allocators::MallocSizeOfExt;

/// Wrapper to zero out memory when dropped.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Memzero<T: AsMut<[u8]>> {
mem: T,
}

impl<T: AsMut<[u8]>> From<T> for Memzero<T> {
fn from(mem: T) -> Memzero<T> {
Memzero { mem }
}
}

impl<T: AsMut<[u8]>> Drop for Memzero<T> {
fn drop(&mut self) {
unsafe {
for byte_ref in self.mem.as_mut() {
ptr::write_volatile(byte_ref, 0)
}
}
}
}

impl<T: AsMut<[u8]>> Deref for Memzero<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.mem
}
}

impl<T: AsMut<[u8]>> DerefMut for Memzero<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.mem
}
}

#[cfg(feature = "std")]
#[cfg(test)]
mod test {
Expand Down

0 comments on commit dce9dd0

Please sign in to comment.