diff --git a/mmap-alloc/CHANGELOG.md b/mmap-alloc/CHANGELOG.md index a04b671..8559599 100644 --- a/mmap-alloc/CHANGELOG.md +++ b/mmap-alloc/CHANGELOG.md @@ -13,6 +13,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Changed +- Upgraded to new `UntypedObjectAlloc` trait that uses `NonNull` instead + of `*mut u8` + ## 0.2.0 ### Added diff --git a/mmap-alloc/Cargo.toml b/mmap-alloc/Cargo.toml index fc2f01a..23425d8 100644 --- a/mmap-alloc/Cargo.toml +++ b/mmap-alloc/Cargo.toml @@ -26,6 +26,6 @@ errno = "0.2" kernel32-sys = "0.2" # use no_std libc libc = { version = "0.2", default-features = false } -object-alloc = "0.1.0" +object-alloc = { path = "../object-alloc" } sysconf = "0.3.1" winapi = "0.2" diff --git a/mmap-alloc/src/lib.rs b/mmap-alloc/src/lib.rs index 2bb86dc..f8e9268 100644 --- a/mmap-alloc/src/lib.rs +++ b/mmap-alloc/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2017 the authors. See the 'Copyright and license' section of the +// Copyright 2017-2018 the authors. See the 'Copyright and license' section of the // README.md file at the top-level directory of this repository. // // Licensed under the Apache License, Version 2.0 (the LICENSE-APACHE file) or @@ -39,7 +39,7 @@ extern crate winapi; use self::alloc::allocator::{Alloc, AllocErr, CannotReallocInPlace, Excess, Layout}; use self::object_alloc::{Exhausted, UntypedObjectAlloc}; -use core::ptr; +use core::ptr::{self, NonNull}; #[cfg(any(target_os = "linux", target_os = "macos"))] use errno::errno; @@ -533,17 +533,17 @@ unsafe impl<'a> UntypedObjectAlloc for &'a MapAlloc { } } - unsafe fn alloc(&mut self) -> Result<*mut u8, Exhausted> { + unsafe fn alloc(&mut self) -> Result, Exhausted> { // TODO: There's probably a method that does this more cleanly. match self.alloc_excess(self.layout()) { - Ok(Excess(ptr, _)) => Ok(ptr), + Ok(Excess(ptr, _)) => Ok(NonNull::new_unchecked(ptr)), Err(AllocErr::Exhausted { .. }) => Err(Exhausted), Err(AllocErr::Unsupported { .. }) => unreachable!(), } } - unsafe fn dealloc(&mut self, ptr: *mut u8) { - unmap(ptr, self.obj_size); + unsafe fn dealloc(&mut self, ptr: NonNull) { + unmap(ptr.as_ptr(), self.obj_size); } } @@ -601,11 +601,11 @@ unsafe impl UntypedObjectAlloc for MapAlloc { <&MapAlloc as UntypedObjectAlloc>::layout(&(&*self)) } - unsafe fn alloc(&mut self) -> Result<*mut u8, Exhausted> { + unsafe fn alloc(&mut self) -> Result, Exhausted> { <&MapAlloc as UntypedObjectAlloc>::alloc(&mut (&*self)) } - unsafe fn dealloc(&mut self, ptr: *mut u8) { + unsafe fn dealloc(&mut self, ptr: NonNull) { <&MapAlloc as UntypedObjectAlloc>::dealloc(&mut (&*self), ptr); } } diff --git a/object-alloc-test/CHANGELOG.md b/object-alloc-test/CHANGELOG.md index 22d4873..abff5d3 100644 --- a/object-alloc-test/CHANGELOG.md +++ b/object-alloc-test/CHANGELOG.md @@ -1,4 +1,4 @@ -