Skip to content

Commit 63dda01

Browse files
committed
---
yaml --- r: 155116 b: refs/heads/try2 c: 84b3737 h: refs/heads/master v: v3
1 parent f08dfa9 commit 63dda01

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
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: 396f9106173b941e880a0f311bc2d1429a68c983
8+
refs/heads/try2: 84b37374bf31b463c36f70123e870f52db19c740
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/liballoc/heap.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,19 @@ pub fn stats_print() {
8686
imp::stats_print();
8787
}
8888

89-
// The compiler never calls `exchange_free` on Box<ZeroSizeType>, so zero-size
90-
// allocations can point to this `static`. It would be incorrect to use a null
91-
// pointer, due to enums assuming types like unique pointers are never null.
92-
pub static mut EMPTY: uint = 12345;
89+
/// An arbitrary non-null address to represent zero-size allocations.
90+
///
91+
/// This preserves the non-null invariant for types like `Box<T>`. The address may overlap with
92+
/// non-zero-size memory allocations.
93+
pub static EMPTY: *mut () = 0x1 as *mut ();
9394

9495
/// The allocator for unique pointers.
9596
#[cfg(not(test))]
9697
#[lang="exchange_malloc"]
9798
#[inline]
9899
unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
99100
if size == 0 {
100-
&EMPTY as *const uint as *mut u8
101+
EMPTY as *mut u8
101102
} else {
102103
allocate(size, align)
103104
}

branches/try2/src/libcollections/vec.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use core::prelude::*;
1414

15-
use alloc::heap::{allocate, reallocate, deallocate};
15+
use alloc::heap::{EMPTY, allocate, reallocate, deallocate};
1616
use core::cmp::max;
1717
use core::default::Default;
1818
use core::fmt;
@@ -26,10 +26,6 @@ use {Mutable, MutableSeq};
2626
use slice::{MutableOrdSlice, MutableSliceAllocating, CloneableVector};
2727
use slice::{Items, MutItems};
2828

29-
30-
#[doc(hidden)]
31-
pub static PTR_MARKER: u8 = 0;
32-
3329
/// An owned, growable vector.
3430
///
3531
/// # Examples
@@ -122,7 +118,7 @@ impl<T> Vec<T> {
122118
// non-null value which is fine since we never call deallocate on the ptr
123119
// if cap is 0. The reason for this is because the pointer of a slice
124120
// being NULL would break the null pointer optimization for enums.
125-
Vec { len: 0, cap: 0, ptr: &PTR_MARKER as *const _ as *mut T }
121+
Vec { len: 0, cap: 0, ptr: EMPTY as *mut T }
126122
}
127123

128124
/// Constructs a new, empty `Vec` with the specified capacity.
@@ -155,7 +151,7 @@ impl<T> Vec<T> {
155151
#[inline]
156152
pub fn with_capacity(capacity: uint) -> Vec<T> {
157153
if mem::size_of::<T>() == 0 {
158-
Vec { len: 0, cap: uint::MAX, ptr: &PTR_MARKER as *const _ as *mut T }
154+
Vec { len: 0, cap: uint::MAX, ptr: EMPTY as *mut T }
159155
} else if capacity == 0 {
160156
Vec::new()
161157
} else {

branches/try2/src/libsyntax/owned_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::fmt;
1212
use std::default::Default;
1313
use std::hash;
1414
use std::{mem, raw, ptr, slice, vec};
15+
use std::rt::heap::EMPTY;
1516
use serialize::{Encodable, Decodable, Encoder, Decoder};
1617

1718
/// A non-growable owned slice. This would preferably become `~[T]`
@@ -81,10 +82,9 @@ impl<T> OwnedSlice<T> {
8182
}
8283

8384
pub fn as_slice<'a>(&'a self) -> &'a [T] {
84-
static PTR_MARKER: u8 = 0;
8585
let ptr = if self.data.is_null() {
8686
// length zero, i.e. this will never be read as a T.
87-
&PTR_MARKER as *const u8 as *const T
87+
EMPTY as *const T
8888
} else {
8989
self.data as *const T
9090
};

0 commit comments

Comments
 (0)