Skip to content

Commit 092cbca

Browse files
committed
---
yaml --- r: 113343 b: refs/heads/snap-stage3 c: f8e92cb h: refs/heads/master i: 113341: 4a30132 113339: efdd204 113335: a998e76 113327: 1ea92ff 113311: a6e4b27 113279: d207e9a v: v3
1 parent 2f813fe commit 092cbca

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: abdacecdf86b4b5a4f432560445a24e1c5f4751b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 138437956c9ab78aede9bb698aa80f9367b3b75a
4+
refs/heads/snap-stage3: f8e92cbbe3337974caca28b801efa26734b3c6f9
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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)