Skip to content

Commit 2d58511

Browse files
committed
---
yaml --- r: 186995 b: refs/heads/try c: 8dbdcdb h: refs/heads/master i: 186993: 2abcb61 186991: dc750c3 v: v3
1 parent b9611fa commit 2d58511

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b4c965ee803a4521d8b4575f634e036f93e408f3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 3a96d6a9818fe2affc98a187fb1065120458cee9
5-
refs/heads/try: c2891cc48798908a96d1b3f847d2cf241fcc58bb
5+
refs/heads/try: 8dbdcdbfb3d09c6d521b275e71370117850c89e2
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/libcollections/ring_buf.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use core::marker;
2828
use core::mem;
2929
use core::num::{Int, UnsignedInt};
3030
use core::ops::{Index, IndexMut};
31-
use core::ptr;
31+
use core::ptr::{self, Unique};
3232
use core::raw::Slice as RawSlice;
3333

3434
use core::hash::{Writer, Hash, Hasher};
@@ -51,7 +51,7 @@ pub struct RingBuf<T> {
5151
tail: usize,
5252
head: usize,
5353
cap: usize,
54-
ptr: *mut T
54+
ptr: Unique<T>,
5555
}
5656

5757
#[stable(feature = "rust1", since = "1.0.0")]
@@ -74,7 +74,7 @@ impl<T> Drop for RingBuf<T> {
7474
self.clear();
7575
unsafe {
7676
if mem::size_of::<T>() != 0 {
77-
heap::deallocate(self.ptr as *mut u8,
77+
heap::deallocate(*self.ptr as *mut u8,
7878
self.cap * mem::size_of::<T>(),
7979
mem::min_align_of::<T>())
8080
}
@@ -92,13 +92,13 @@ impl<T> RingBuf<T> {
9292
/// Turn ptr into a slice
9393
#[inline]
9494
unsafe fn buffer_as_slice(&self) -> &[T] {
95-
mem::transmute(RawSlice { data: self.ptr, len: self.cap })
95+
mem::transmute(RawSlice { data: *self.ptr as *const T, len: self.cap })
9696
}
9797

9898
/// Turn ptr into a mut slice
9999
#[inline]
100100
unsafe fn buffer_as_mut_slice(&mut self) -> &mut [T] {
101-
mem::transmute(RawSlice { data: self.ptr, len: self.cap })
101+
mem::transmute(RawSlice { data: *self.ptr as *const T, len: self.cap })
102102
}
103103

104104
/// Moves an element out of the buffer
@@ -165,21 +165,21 @@ impl<T> RingBuf<T> {
165165
let size = cap.checked_mul(mem::size_of::<T>())
166166
.expect("capacity overflow");
167167

168-
let ptr = if mem::size_of::<T>() != 0 {
169-
unsafe {
168+
let ptr = unsafe {
169+
if mem::size_of::<T>() != 0 {
170170
let ptr = heap::allocate(size, mem::min_align_of::<T>()) as *mut T;;
171171
if ptr.is_null() { ::alloc::oom() }
172-
ptr
172+
Unique::new(ptr)
173+
} else {
174+
Unique::new(heap::EMPTY as *mut T)
173175
}
174-
} else {
175-
heap::EMPTY as *mut T
176176
};
177177

178178
RingBuf {
179179
tail: 0,
180180
head: 0,
181181
cap: cap,
182-
ptr: ptr
182+
ptr: ptr,
183183
}
184184
}
185185

@@ -335,11 +335,12 @@ impl<T> RingBuf<T> {
335335
let new = count.checked_mul(mem::size_of::<T>())
336336
.expect("capacity overflow");
337337
unsafe {
338-
self.ptr = heap::reallocate(self.ptr as *mut u8,
339-
old,
340-
new,
341-
mem::min_align_of::<T>()) as *mut T;
342-
if self.ptr.is_null() { ::alloc::oom() }
338+
let ptr = heap::reallocate(*self.ptr as *mut u8,
339+
old,
340+
new,
341+
mem::min_align_of::<T>()) as *mut T;
342+
if ptr.is_null() { ::alloc::oom() }
343+
self.ptr = Unique::new(ptr);
343344
}
344345
}
345346

@@ -453,11 +454,12 @@ impl<T> RingBuf<T> {
453454
let old = self.cap * mem::size_of::<T>();
454455
let new_size = target_cap * mem::size_of::<T>();
455456
unsafe {
456-
self.ptr = heap::reallocate(self.ptr as *mut u8,
457-
old,
458-
new_size,
459-
mem::min_align_of::<T>()) as *mut T;
460-
if self.ptr.is_null() { ::alloc::oom() }
457+
let ptr = heap::reallocate(*self.ptr as *mut u8,
458+
old,
459+
new_size,
460+
mem::min_align_of::<T>()) as *mut T;
461+
if ptr.is_null() { ::alloc::oom() }
462+
self.ptr = Unique::new(ptr);
461463
}
462464
}
463465
self.cap = target_cap;
@@ -539,8 +541,8 @@ impl<T> RingBuf<T> {
539541
tail: self.tail,
540542
head: self.head,
541543
cap: self.cap,
542-
ptr: self.ptr,
543-
marker: marker::ContravariantLifetime,
544+
ptr: *self.ptr,
545+
marker: marker::PhantomData,
544546
}
545547
}
546548

@@ -1336,7 +1338,7 @@ impl<T> RingBuf<T> {
13361338
// `at` lies in the first half.
13371339
let amount_in_first = first_len - at;
13381340

1339-
ptr::copy_nonoverlapping_memory(other.ptr,
1341+
ptr::copy_nonoverlapping_memory(*other.ptr,
13401342
first_half.as_ptr().offset(at as isize),
13411343
amount_in_first);
13421344

@@ -1349,7 +1351,7 @@ impl<T> RingBuf<T> {
13491351
// in the first half.
13501352
let offset = at - first_len;
13511353
let amount_in_second = second_len - offset;
1352-
ptr::copy_nonoverlapping_memory(other.ptr,
1354+
ptr::copy_nonoverlapping_memory(*other.ptr,
13531355
second_half.as_ptr().offset(offset as isize),
13541356
amount_in_second);
13551357
}
@@ -1518,7 +1520,7 @@ pub struct IterMut<'a, T:'a> {
15181520
tail: usize,
15191521
head: usize,
15201522
cap: usize,
1521-
marker: marker::ContravariantLifetime<'a>,
1523+
marker: marker::PhantomData<&'a mut T>,
15221524
}
15231525

15241526
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1986,9 +1988,9 @@ mod tests {
19861988

19871989
#[derive(Clone, PartialEq, Debug)]
19881990
enum Taggypar<T> {
1989-
Onepar(i32),
1990-
Twopar(i32, i32),
1991-
Threepar(i32, i32, i32),
1991+
Onepar(T),
1992+
Twopar(T, T),
1993+
Threepar(T, T, T),
19921994
}
19931995

19941996
#[derive(Clone, PartialEq, Debug)]

0 commit comments

Comments
 (0)