From 2c3a203f57710483547061611ed0c8389f631c18 Mon Sep 17 00:00:00 2001 From: edef Date: Thu, 16 Apr 2015 05:24:18 -0400 Subject: [PATCH] rearrange the os::{Stack, StackSource} code a little --- src/os.rs | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/os.rs b/src/os.rs index 88e96ec..b21572a 100644 --- a/src/os.rs +++ b/src/os.rs @@ -6,6 +6,8 @@ use stack; #[cfg(unix)] #[path = "os/unix.rs"] mod sys; +pub struct StackSource; + #[allow(raw_pointer_derive)] #[derive(Debug)] pub struct Stack { @@ -13,33 +15,11 @@ pub struct Stack { len: usize } -pub struct StackSource; - impl stack::StackSource for StackSource { type Output = Stack; type Error = IoError; fn get_stack(size: usize) -> Result { - Stack::new(size) - } -} - -impl stack::Stack for Stack { - fn top(&mut self) -> *mut u8 { - unsafe { - self.ptr.offset(self.len as isize) - } - } - - fn limit(&self) -> *const u8 { - unsafe { - self.ptr.offset(sys::page_size() as isize) - } - } -} - -impl Stack { - fn new(size: usize) -> Result { let page_size = sys::page_size(); // round the page size up, @@ -64,6 +44,20 @@ impl Stack { } } +impl stack::Stack for Stack { + fn top(&mut self) -> *mut u8 { + unsafe { + self.ptr.offset(self.len as isize) + } + } + + fn limit(&self) -> *const u8 { + unsafe { + self.ptr.offset(sys::page_size() as isize) + } + } +} + impl Drop for Stack { fn drop(&mut self) { unsafe {