Skip to content

Commit 410d7c6

Browse files
committed
---
yaml --- r: 151523 b: refs/heads/try2 c: f8e92cb h: refs/heads/master i: 151521: 209a58b 151519: 0f441a0 v: v3
1 parent 3c2aadc commit 410d7c6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 138437956c9ab78aede9bb698aa80f9367b3b75a
8+
refs/heads/try2: f8e92cbbe3337974caca28b801efa26734b3c6f9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/vec.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl<T> Vec<T> {
9191
/// let vec: Vec<int> = Vec::with_capacity(10);
9292
/// ```
9393
pub fn with_capacity(capacity: uint) -> Vec<T> {
94+
if size_of::<T>() == 0 { return Vec { len: 0, cap: ::uint::MAX, ptr: 0 as *mut T } }
9495
if capacity == 0 {
9596
Vec::new()
9697
} else {
@@ -486,6 +487,7 @@ impl<T> Vec<T> {
486487
/// assert_eq!(vec.capacity(), 11);
487488
/// ```
488489
pub fn reserve_exact(&mut self, capacity: uint) {
490+
if size_of::<T>() == 0 { return }
489491
if capacity > self.cap {
490492
let size = capacity.checked_mul(&size_of::<T>()).expect("capacity overflow");
491493
unsafe {
@@ -505,6 +507,7 @@ impl<T> Vec<T> {
505507
/// vec.shrink_to_fit();
506508
/// ```
507509
pub fn shrink_to_fit(&mut self) {
510+
if size_of::<T>() == 0 { return }
508511
if self.len == 0 {
509512
if self.cap != 0 {
510513
unsafe {
@@ -559,6 +562,12 @@ impl<T> Vec<T> {
559562
/// ```
560563
#[inline]
561564
pub fn push(&mut self, value: T) {
565+
if size_of::<T>() == 0 {
566+
// zero-size types consume no memory, so we can't rely on the address space running out
567+
self.len = self.len.checked_add(&1).expect("length overflow");
568+
unsafe { forget(value); }
569+
return
570+
}
562571
if self.len == self.cap {
563572
let old_size = self.cap * size_of::<T>();
564573
let size = max(old_size, 2 * size_of::<T>()) * 2;
@@ -1405,7 +1414,9 @@ impl<T> Drop for Vec<T> {
14051414
for x in self.as_mut_slice().iter() {
14061415
ptr::read(x);
14071416
}
1408-
deallocate(self.ptr as *mut u8, self.cap * size_of::<T>(), min_align_of::<T>())
1417+
if size_of::<T>() != 0 {
1418+
deallocate(self.ptr as *mut u8, self.cap * size_of::<T>(), min_align_of::<T>())
1419+
}
14091420
}
14101421
}
14111422
}
@@ -1460,7 +1471,9 @@ impl<T> Drop for MoveItems<T> {
14601471
if self.cap != 0 {
14611472
for _x in *self {}
14621473
unsafe {
1463-
deallocate(self.allocation, self.cap * size_of::<T>(), min_align_of::<T>())
1474+
if size_of::<T>() != 0 {
1475+
deallocate(self.allocation, self.cap * size_of::<T>(), min_align_of::<T>())
1476+
}
14641477
}
14651478
}
14661479
}

0 commit comments

Comments
 (0)