|
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 |
2 | 2 | // README.md file at the top-level directory of this repository.
|
3 | 3 | //
|
4 | 4 | // Licensed under the Apache License, Version 2.0 (the LICENSE-APACHE file) or
|
@@ -39,7 +39,7 @@ extern crate winapi;
|
39 | 39 |
|
40 | 40 | use self::alloc::allocator::{Alloc, AllocErr, CannotReallocInPlace, Excess, Layout};
|
41 | 41 | use self::object_alloc::{Exhausted, UntypedObjectAlloc};
|
42 |
| -use core::ptr; |
| 42 | +use core::ptr::{self, NonNull}; |
43 | 43 |
|
44 | 44 | #[cfg(any(target_os = "linux", target_os = "macos"))]
|
45 | 45 | use errno::errno;
|
@@ -533,17 +533,17 @@ unsafe impl<'a> UntypedObjectAlloc for &'a MapAlloc {
|
533 | 533 | }
|
534 | 534 | }
|
535 | 535 |
|
536 |
| - unsafe fn alloc(&mut self) -> Result<*mut u8, Exhausted> { |
| 536 | + unsafe fn alloc(&mut self) -> Result<NonNull<u8>, Exhausted> { |
537 | 537 | // TODO: There's probably a method that does this more cleanly.
|
538 | 538 | match self.alloc_excess(self.layout()) {
|
539 |
| - Ok(Excess(ptr, _)) => Ok(ptr), |
| 539 | + Ok(Excess(ptr, _)) => Ok(NonNull::new_unchecked(ptr)), |
540 | 540 | Err(AllocErr::Exhausted { .. }) => Err(Exhausted),
|
541 | 541 | Err(AllocErr::Unsupported { .. }) => unreachable!(),
|
542 | 542 | }
|
543 | 543 | }
|
544 | 544 |
|
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); |
547 | 547 | }
|
548 | 548 | }
|
549 | 549 |
|
@@ -601,11 +601,11 @@ unsafe impl UntypedObjectAlloc for MapAlloc {
|
601 | 601 | <&MapAlloc as UntypedObjectAlloc>::layout(&(&*self))
|
602 | 602 | }
|
603 | 603 |
|
604 |
| - unsafe fn alloc(&mut self) -> Result<*mut u8, Exhausted> { |
| 604 | + unsafe fn alloc(&mut self) -> Result<NonNull<u8>, Exhausted> { |
605 | 605 | <&MapAlloc as UntypedObjectAlloc>::alloc(&mut (&*self))
|
606 | 606 | }
|
607 | 607 |
|
608 |
| - unsafe fn dealloc(&mut self, ptr: *mut u8) { |
| 608 | + unsafe fn dealloc(&mut self, ptr: NonNull<u8>) { |
609 | 609 | <&MapAlloc as UntypedObjectAlloc>::dealloc(&mut (&*self), ptr);
|
610 | 610 | }
|
611 | 611 | }
|
|
0 commit comments