Skip to content

Commit b252f6c

Browse files
committed
object-alloc: Switch from *mut to NonNull
- Switch from *mut u8 and *mut T to NonNull<u8> and NonNull<T> in trait methods - Upgrade slab-alloc, mmap-alloc, and object-alloc-test accordingly - While upgrading slab-alloc to use the latest mmap-alloc, remove support for huge pages (since mmap-alloc no longer supports them) - Closes #140
1 parent 2b4b5d5 commit b252f6c

22 files changed

+547
-453
lines changed

mmap-alloc/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1313

1414
## [Unreleased]
1515

16+
### Changed
17+
- Upgraded to new `UntypedObjectAlloc` trait that uses `NonNull<u8>` instead
18+
of `*mut u8`
19+
1620
## 0.2.0
1721

1822
### Added

mmap-alloc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ errno = "0.2"
2626
kernel32-sys = "0.2"
2727
# use no_std libc
2828
libc = { version = "0.2", default-features = false }
29-
object-alloc = "0.1.0"
29+
object-alloc = { path = "../object-alloc" }
3030
sysconf = "0.3.1"
3131
winapi = "0.2"

mmap-alloc/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 the authors. See the 'Copyright and license' section of the
1+
// Copyright 2017-2018 the authors. See the 'Copyright and license' section of the
22
// README.md file at the top-level directory of this repository.
33
//
44
// Licensed under the Apache License, Version 2.0 (the LICENSE-APACHE file) or
@@ -39,7 +39,7 @@ extern crate winapi;
3939

4040
use self::alloc::allocator::{Alloc, AllocErr, CannotReallocInPlace, Excess, Layout};
4141
use self::object_alloc::{Exhausted, UntypedObjectAlloc};
42-
use core::ptr;
42+
use core::ptr::{self, NonNull};
4343

4444
#[cfg(any(target_os = "linux", target_os = "macos"))]
4545
use errno::errno;
@@ -533,17 +533,17 @@ unsafe impl<'a> UntypedObjectAlloc for &'a MapAlloc {
533533
}
534534
}
535535

536-
unsafe fn alloc(&mut self) -> Result<*mut u8, Exhausted> {
536+
unsafe fn alloc(&mut self) -> Result<NonNull<u8>, Exhausted> {
537537
// TODO: There's probably a method that does this more cleanly.
538538
match self.alloc_excess(self.layout()) {
539-
Ok(Excess(ptr, _)) => Ok(ptr),
539+
Ok(Excess(ptr, _)) => Ok(NonNull::new_unchecked(ptr)),
540540
Err(AllocErr::Exhausted { .. }) => Err(Exhausted),
541541
Err(AllocErr::Unsupported { .. }) => unreachable!(),
542542
}
543543
}
544544

545-
unsafe fn dealloc(&mut self, ptr: *mut u8) {
546-
unmap(ptr, self.obj_size);
545+
unsafe fn dealloc(&mut self, ptr: NonNull<u8>) {
546+
unmap(ptr.as_ptr(), self.obj_size);
547547
}
548548
}
549549

@@ -601,11 +601,11 @@ unsafe impl UntypedObjectAlloc for MapAlloc {
601601
<&MapAlloc as UntypedObjectAlloc>::layout(&(&*self))
602602
}
603603

604-
unsafe fn alloc(&mut self) -> Result<*mut u8, Exhausted> {
604+
unsafe fn alloc(&mut self) -> Result<NonNull<u8>, Exhausted> {
605605
<&MapAlloc as UntypedObjectAlloc>::alloc(&mut (&*self))
606606
}
607607

608-
unsafe fn dealloc(&mut self, ptr: *mut u8) {
608+
unsafe fn dealloc(&mut self, ptr: NonNull<u8>) {
609609
<&MapAlloc as UntypedObjectAlloc>::dealloc(&mut (&*self), ptr);
610610
}
611611
}

object-alloc-test/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Copyright 2017 the authors. See the 'Copyright and license' section of the
1+
<!-- Copyright 2017-2018 the authors. See the 'Copyright and license' section of the
22
README.md file at the top-level directory of this repository.
33
44
Licensed under the Apache License, Version 2.0 (the LICENSE-APACHE file) or
@@ -15,3 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1515

1616
### Added
1717
- Added this changelog
18+
19+
### Changed
20+
- Upgraded to new `ObjectAlloc` trait that uses `NonNull<u8>` instead
21+
of `*mut u8`

object-alloc-test/Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ exclude = ["appveyor.sh", "travis.sh"]
2323

2424
[dependencies]
2525
interpolate_idents = "0.2.2"
26+
kernel32-sys = "0.2"
2627
lazy_static = "1.0.0"
2728
libc = "0.2"
28-
object-alloc = "0.1.0"
29+
object-alloc = { path = "../object-alloc" }
2930
quickcheck = "0.4"
3031
rand = "0.3"
3132
twox-hash = "1.1"
32-
winapi = "0.2"
33+
34+
[dependencies.winapi]
35+
version = "0.3"
36+
features = ["basetsd", "psapi"]

0 commit comments

Comments
 (0)