Skip to content

Commit d78b00b

Browse files
committed
---
yaml --- r: 95293 b: refs/heads/dist-snap c: 618c6af h: refs/heads/master i: 95291: d0c6ebe v: v3
1 parent a873eef commit d78b00b

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: d86de18b6198547f0a39e217123d8ec9ef4a9988
9+
refs/heads/dist-snap: 618c6afe3232d0cc3750178d4f301352684ddde6
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/rand/os.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ use rt::io::{file, Open, Read};
2121

2222
#[cfg(windows)]
2323
use cast;
24+
#[cfg(windows)]
25+
use libc::{c_long, DWORD, BYTE};
26+
#[cfg(windows)]
27+
type HCRYPTPROV = c_long;
28+
// the extern functions imported from the runtime on Windows are
29+
// implemented so that they either succeed or abort(), so we can just
30+
// assume they work when we call them.
2431

2532
/// A random number generator that retrieves randomness straight from
2633
/// the operating system. On Unix-like systems this reads from
@@ -38,7 +45,7 @@ pub struct OSRng {
3845
/// This does not block.
3946
#[cfg(windows)]
4047
pub struct OSRng {
41-
priv hcryptprov: raw::HCRYPTPROV
48+
priv hcryptprov: HCRYPTPROV
4249
}
4350

4451
impl OSRng {
@@ -53,10 +60,11 @@ impl OSRng {
5360

5461
/// Create a new `OSRng`.
5562
#[cfg(windows)]
56-
#[fixed_stack_segment] #[inline(never)]
5763
pub fn new() -> OSRng {
64+
externfn!(fn rust_win32_rand_acquire(phProv: *mut HCRYPTPROV))
65+
5866
let mut hcp = 0;
59-
unsafe {raw::rust_win32_rand_acquire(&mut hcp)};
67+
unsafe {rust_win32_rand_acquire(&mut hcp)};
6068

6169
OSRng { hcryptprov: hcp }
6270
}
@@ -87,12 +95,11 @@ impl Rng for OSRng {
8795
self.fill_bytes(v);
8896
unsafe { cast::transmute(v) }
8997
}
90-
#[fixed_stack_segment] #[inline(never)]
9198
fn fill_bytes(&mut self, v: &mut [u8]) {
92-
use libc::DWORD;
99+
externfn!(fn rust_win32_rand_gen(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: *mut BYTE))
93100

94101
do v.as_mut_buf |ptr, len| {
95-
unsafe {raw::rust_win32_rand_gen(self.hcryptprov, len as DWORD, ptr)}
102+
unsafe {rust_win32_rand_gen(self.hcryptprov, len as DWORD, ptr)}
96103
}
97104
}
98105
}
@@ -105,27 +112,14 @@ impl Drop for OSRng {
105112
}
106113

107114
#[cfg(windows)]
108-
#[fixed_stack_segment] #[inline(never)]
109115
fn drop(&mut self) {
110-
unsafe {raw::rust_win32_rand_release(self.hcryptprov)}
111-
}
112-
}
116+
externfn!(fn rust_win32_rand_release(hProv: HCRYPTPROV))
113117

114-
#[cfg(windows)]
115-
mod raw {
116-
use libc::{c_long, DWORD, BYTE};
117-
118-
pub type HCRYPTPROV = c_long;
119-
120-
// these functions are implemented so that they either succeed or
121-
// abort(), so we can just assume they work when we call them.
122-
extern {
123-
pub fn rust_win32_rand_acquire(phProv: *mut HCRYPTPROV);
124-
pub fn rust_win32_rand_gen(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: *mut BYTE);
125-
pub fn rust_win32_rand_release(hProv: HCRYPTPROV);
118+
unsafe {rust_win32_rand_release(self.hcryptprov)}
126119
}
127120
}
128121

122+
129123
#[cfg(test)]
130124
mod test {
131125
use super::*;

0 commit comments

Comments
 (0)