use core::mem;
use core::num::{Int, UnsignedInt};
use core::ops::{Index, IndexMut};
-use core::ptr;
+use core::ptr::{self, Unique};
use core::raw::Slice as RawSlice;
use core::hash::{Writer, Hash, Hasher};
tail: usize,
head: usize,
cap: usize,
- ptr: *mut T
+ ptr: Unique<T>,
}
#[stable(feature = "rust1", since = "1.0.0")]
self.clear();
unsafe {
if mem::size_of::<T>() != 0 {
- heap::deallocate(self.ptr as *mut u8,
+ heap::deallocate(*self.ptr as *mut u8,
self.cap * mem::size_of::<T>(),
mem::min_align_of::<T>())
}
/// Turn ptr into a slice
#[inline]
unsafe fn buffer_as_slice(&self) -> &[T] {
- mem::transmute(RawSlice { data: self.ptr, len: self.cap })
+ mem::transmute(RawSlice { data: *self.ptr as *const T, len: self.cap })
}
/// Turn ptr into a mut slice
#[inline]
unsafe fn buffer_as_mut_slice(&mut self) -> &mut [T] {
- mem::transmute(RawSlice { data: self.ptr, len: self.cap })
+ mem::transmute(RawSlice { data: *self.ptr as *const T, len: self.cap })
}
/// Moves an element out of the buffer
let size = cap.checked_mul(mem::size_of::<T>())
.expect("capacity overflow");
- let ptr = if mem::size_of::<T>() != 0 {
- unsafe {
+ let ptr = unsafe {
+ if mem::size_of::<T>() != 0 {
let ptr = heap::allocate(size, mem::min_align_of::<T>()) as *mut T;;
if ptr.is_null() { ::alloc::oom() }
- ptr
+ Unique::new(ptr)
+ } else {
+ Unique::new(heap::EMPTY as *mut T)
}
- } else {
- heap::EMPTY as *mut T
};
RingBuf {
tail: 0,
head: 0,
cap: cap,
- ptr: ptr
+ ptr: ptr,
}
}
let new = count.checked_mul(mem::size_of::<T>())
.expect("capacity overflow");
unsafe {
- self.ptr = heap::reallocate(self.ptr as *mut u8,
- old,
- new,
- mem::min_align_of::<T>()) as *mut T;
- if self.ptr.is_null() { ::alloc::oom() }
+ let ptr = heap::reallocate(*self.ptr as *mut u8,
+ old,
+ new,
+ mem::min_align_of::<T>()) as *mut T;
+ if ptr.is_null() { ::alloc::oom() }
+ self.ptr = Unique::new(ptr);
}
}
let old = self.cap * mem::size_of::<T>();
let new_size = target_cap * mem::size_of::<T>();
unsafe {
- self.ptr = heap::reallocate(self.ptr as *mut u8,
- old,
- new_size,
- mem::min_align_of::<T>()) as *mut T;
- if self.ptr.is_null() { ::alloc::oom() }
+ let ptr = heap::reallocate(*self.ptr as *mut u8,
+ old,
+ new_size,
+ mem::min_align_of::<T>()) as *mut T;
+ if ptr.is_null() { ::alloc::oom() }
+ self.ptr = Unique::new(ptr);
}
}
self.cap = target_cap;
tail: self.tail,
head: self.head,
cap: self.cap,
- ptr: self.ptr,
- marker: marker::ContravariantLifetime,
+ ptr: *self.ptr,
+ marker: marker::PhantomData,
}
}
// `at` lies in the first half.
let amount_in_first = first_len - at;
- ptr::copy_nonoverlapping_memory(other.ptr,
+ ptr::copy_nonoverlapping_memory(*other.ptr,
first_half.as_ptr().offset(at as isize),
amount_in_first);
// in the first half.
let offset = at - first_len;
let amount_in_second = second_len - offset;
- ptr::copy_nonoverlapping_memory(other.ptr,
+ ptr::copy_nonoverlapping_memory(*other.ptr,
second_half.as_ptr().offset(offset as isize),
amount_in_second);
}
tail: usize,
head: usize,
cap: usize,
- marker: marker::ContravariantLifetime<'a>,
+ marker: marker::PhantomData<&'a mut T>,
}
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Clone, PartialEq, Debug)]
enum Taggypar<T> {
- Onepar(i32),
- Twopar(i32, i32),
- Threepar(i32, i32, i32),
+ Onepar(T),
+ Twopar(T, T),
+ Threepar(T, T, T),
}
#[derive(Clone, PartialEq, Debug)]