Skip to content

Commit fae4f56

Browse files
authored
Merge pull request #12 from tarcieri/no_std
no_std support (closes #11)
2 parents 029223c + 035a415 commit fae4f56

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

src/clear.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
//! assert!(!as_bytes(&place).contains(&0x41));
4040
//! ```
4141
42-
use std::mem;
43-
use std::ptr;
42+
use core::mem;
43+
use core::ptr;
4444

4545
use hide::hide_mem_impl;
4646

src/clear_on_drop.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use std::borrow::{Borrow, BorrowMut};
2-
use std::cmp::Ordering;
3-
use std::fmt;
4-
use std::hash::{Hash, Hasher};
5-
use std::mem;
6-
use std::ops::{Deref, DerefMut};
7-
use std::ptr;
1+
use core::borrow::{Borrow, BorrowMut};
2+
use core::cmp::Ordering;
3+
use core::fmt;
4+
use core::hash::{Hash, Hasher};
5+
use core::mem;
6+
use core::ops::{Deref, DerefMut};
7+
use core::ptr;
88

99
use clear::Clear;
1010

@@ -138,7 +138,7 @@ impl<P> Drop for ClearOnDrop<P>
138138
}
139139
}
140140

141-
// std::convert traits
141+
// core::convert traits
142142

143143
impl<P, T: ?Sized> AsRef<T> for ClearOnDrop<P>
144144
where P: DerefMut + AsRef<T>,
@@ -160,7 +160,7 @@ impl<P, T: ?Sized> AsMut<T> for ClearOnDrop<P>
160160
}
161161
}
162162

163-
// std::borrow traits
163+
// core::borrow traits
164164

165165
// The `T: Clear` bound avoids a conflict with the blanket impls
166166
// `impl<T> Borrow<T> for T` and `impl<T> BorrowMut<T> for T`, since
@@ -188,7 +188,7 @@ impl<P, T: ?Sized> BorrowMut<T> for ClearOnDrop<P>
188188
}
189189
}
190190

191-
// std::hash traits
191+
// core::hash traits
192192

193193
impl<P> Hash for ClearOnDrop<P>
194194
where P: DerefMut + Hash,
@@ -200,7 +200,7 @@ impl<P> Hash for ClearOnDrop<P>
200200
}
201201
}
202202

203-
// std::cmp traits
203+
// core::cmp traits
204204

205205
impl<P, Q> PartialEq<ClearOnDrop<Q>> for ClearOnDrop<P>
206206
where P: DerefMut + PartialEq<Q>,

src/hide.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__attribute__ ((visibility ("hidden")))
44
#endif
55
#endif
6-
void *clear_on_drop_hide(void *ptr) {
6+
unsigned char *clear_on_drop_hide(unsigned char *ptr) {
77
#if defined(__GNUC__)
88
/* Not needed with MSVC, since Rust uses LLVM and LTO can't inline this. */
99
__asm__ volatile ("" : "=r" (ptr) : "0" (ptr) : "memory");

src/hide.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ mod nightly {
6565
// When a C compiler is available, a dummy C function can be used.
6666
#[cfg(not(feature = "no_cc"))]
6767
mod cc {
68-
use std::os::raw::c_void;
69-
7068
extern "C" {
71-
fn clear_on_drop_hide(ptr: *mut c_void) -> *mut c_void;
69+
fn clear_on_drop_hide(ptr: *mut u8) -> *mut u8;
7270
}
7371

7472
#[inline]
7573
pub fn hide_mem_impl<T: ?Sized>(ptr: *mut T) {
7674
unsafe {
77-
clear_on_drop_hide(ptr as *mut c_void);
75+
clear_on_drop_hide(ptr as *mut u8);
7876
}
7977
}
8078
}
@@ -83,7 +81,7 @@ mod cc {
8381
// and hope this is enough to confuse the optimizer.
8482
#[cfg(all(feature = "no_cc", not(feature = "nightly")))]
8583
mod fallback {
86-
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
84+
use core::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
8785

8886
#[inline]
8987
pub fn hide_mem_impl<T: ?Sized>(ptr: *mut T) {

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg_attr(not(test), no_std)]
12
#![cfg_attr(feature = "nightly", feature(asm))]
23
#![cfg_attr(feature = "nightly", feature(i128_type))]
34
#![cfg_attr(feature = "nightly", feature(specialization))]
@@ -55,6 +56,9 @@
5556
//! the `no_cc` feature, works on stable Rust, and does not need a C
5657
//! compiler.
5758
59+
#[cfg(test)]
60+
extern crate core;
61+
5862
pub mod clear;
5963
mod clear_on_drop;
6064
mod clear_stack_on_return;

0 commit comments

Comments
 (0)