diff --git a/src/detail/mod.rs b/src/detail/mod.rs index 3579b1e..3c0e2dd 100644 --- a/src/detail/mod.rs +++ b/src/detail/mod.rs @@ -41,7 +41,7 @@ fn align_down(sp: *mut usize) -> *mut usize { sp as *mut usize } -// ptr::mut_offset is positive isizes only +// ptr::mut_offset is positive isize only #[inline] #[allow(unused)] fn mut_offset(ptr: *mut T, count: isize) -> *mut T { diff --git a/src/detail/x86_64_unix.rs b/src/detail/x86_64_unix.rs index ec28c6f..b4e06a3 100644 --- a/src/detail/x86_64_unix.rs +++ b/src/detail/x86_64_unix.rs @@ -34,7 +34,7 @@ mod asm_impl { mov %r12, %rdi // setup the function arg mov %r13, %rsi // setup the function arg and $$-16, %rsp // align the stack pointer - mov %r14, (%rsp) // this is the new return adrress + mov %r14, (%rsp) // this is the new return address " : // no output : // no input diff --git a/src/detail/x86_64_windows.rs b/src/detail/x86_64_windows.rs index 5cfaa4e..8aca17e 100644 --- a/src/detail/x86_64_windows.rs +++ b/src/detail/x86_64_windows.rs @@ -40,7 +40,7 @@ mod asm_impl { mov %r12, %rcx // setup the function arg mov %r13, %rdx // setup the function arg and $$-16, %rsp // align the stack pointer - mov %r14, (%rsp) // this is the new return adrress + mov %r14, (%rsp) // this is the new return address " : // no output : // no input diff --git a/src/gen_impl.rs b/src/gen_impl.rs index 5eaac3b..e2eb707 100644 --- a/src/gen_impl.rs +++ b/src/gen_impl.rs @@ -290,11 +290,8 @@ impl<'a, A, T> GeneratorImpl<'a, A, T> { fn new(mut stack: Stack) -> StackBox { // the stack box would finally dealloc the stack! unsafe { - let mut stack_box = stack - .alloc_uninit_box::>() - .assume_init(); - - stack_box.init(GeneratorImpl { + let mut stack_box = stack.alloc_uninit_box::>(); + (*stack_box.as_mut_ptr()).init(GeneratorImpl { para: None, stack, ret: None, @@ -302,7 +299,7 @@ impl<'a, A, T> GeneratorImpl<'a, A, T> { context: Context::new(), phantom: PhantomData, }); - stack_box + stack_box.assume_init() } } diff --git a/src/reg_context.rs b/src/reg_context.rs index 1071168..fcb876f 100644 --- a/src/reg_context.rs +++ b/src/reg_context.rs @@ -34,7 +34,7 @@ impl RegContext { #[inline] pub fn init_with(&mut self, init: InitFn, arg: usize, start: *mut usize, stack: &Stack) { // Save and then immediately load the current context, - // which we will then modify to call the given function when restoredtack + // we will modify it to call the given function when restored back initialize_call_frame(&mut self.regs, init, arg, start, stack); } diff --git a/src/stack/mod.rs b/src/stack/mod.rs index 30ab28f..c1f11c0 100644 --- a/src/stack/mod.rs +++ b/src/stack/mod.rs @@ -42,7 +42,7 @@ pub struct StackBox { impl StackBox { /// create uninit stack box - fn new_unint(stack: &mut Stack, need_drop: usize) -> MaybeUninit { + fn new_uninit(stack: &mut Stack, need_drop: usize) -> MaybeUninit { let offset = unsafe { &mut *stack.get_offset() }; // alloc the data let layout = std::alloc::Layout::new::(); @@ -150,8 +150,9 @@ impl StackBox { /// create a functor on the stack pub(crate) fn new_fn_once(stack: &mut Stack, data: F) -> Func { unsafe { - let mut d = Self::new_unint(stack, 0).assume_init(); - d.init(data); + let mut d = Self::new_uninit(stack, 0); + (*d.as_mut_ptr()).init(data); + let d = d.assume_init(); let header = d.get_header(); let f = Func { data: d.ptr.as_ptr() as *mut (), @@ -306,7 +307,7 @@ impl SysStack { unsafe impl Send for SysStack {} /// generator stack -/// this struct will not dealloc the memroy +/// this struct will not dealloc the memory /// instead StackBox<> would track it's usage and dealloc it pub struct Stack { buf: SysStack, @@ -385,7 +386,7 @@ impl Stack { /// alloc buffer on this stack pub fn alloc_uninit_box(&mut self) -> MaybeUninit> { // the first obj should set need drop to non zero - StackBox::::new_unint(self, 1) + StackBox::::new_uninit(self, 1) } // get offset @@ -393,7 +394,7 @@ impl Stack { unsafe { (self.buf.top as *mut usize).offset(-1) } } - // dealloc the statck + // dealloc the stack fn drop_stack(&self) { if self.buf.len() == 0 { return; @@ -419,6 +420,6 @@ impl Stack { impl fmt::Debug for Stack { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let offset = self.get_offset(); - write!(f, "Statck<{:?}, Offset={}>", self.buf, unsafe { *offset }) + write!(f, "Stack<{:?}, Offset={}>", self.buf, unsafe { *offset }) } } diff --git a/src/stack/unix.rs b/src/stack/unix.rs index 0cb9576..794aa4b 100644 --- a/src/stack/unix.rs +++ b/src/stack/unix.rs @@ -93,9 +93,9 @@ pub fn max_stack_size() -> usize { let mut ret = PAGE_SIZE.load(Ordering::Relaxed); if ret == 0 { - let limit = mem::MaybeUninit::uninit(); - let mut limit = unsafe { limit.assume_init() }; - let limitret = unsafe { libc::getrlimit(libc::RLIMIT_STACK, &mut limit) }; + let mut limit = mem::MaybeUninit::uninit(); + let limitret = unsafe { libc::getrlimit(libc::RLIMIT_STACK, limit.as_mut_ptr()) }; + let limit = unsafe { limit.assume_init() }; if limitret == 0 { ret = if limit.rlim_max == libc::RLIM_INFINITY diff --git a/src/yield_.rs b/src/yield_.rs index 0fa5e6d..743b07a 100644 --- a/src/yield_.rs +++ b/src/yield_.rs @@ -27,7 +27,7 @@ pub fn done() -> T { // set the done bit for this special return ContextStack::current().top()._ref = 0xf; // this return value would not be dropped when _ref is 0xf - // so it's safe here to reutrn a dummy T + // so it's safe here to return a dummy T let ret = std::mem::MaybeUninit::uninit(); unsafe { ret.assume_init() } }