Skip to content

Commit fb77847

Browse files
committed
---
yaml --- r: 40319 b: refs/heads/dist-snap c: a54d046 h: refs/heads/master i: 40317: a80c2a2 40315: 31c80d6 40311: 5bc1aae 40303: 3df4b89 40287: f89a97d 40255: 61dd9ff 40191: 367ab00 v: v3
1 parent 3ba1048 commit fb77847

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
99
refs/heads/incoming: e90142e536c150df0d9b4b2f11352152177509b5
10-
refs/heads/dist-snap: 92e3a8c17e9b7cb61b18791aea0544794a315bbb
10+
refs/heads/dist-snap: a54d04617413322e434f6eb6c0a786d61c2f8329
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcore/ptr.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub trait Ptr<T> {
176176
pure fn offset(count: uint) -> self;
177177
}
178178

179-
/// Extension methods for pointers
179+
/// Extension methods for immutable pointers
180180
impl<T> *T: Ptr<T> {
181181
/// Returns true if the pointer is equal to the null pointer.
182182
#[inline(always)]
@@ -191,6 +191,21 @@ impl<T> *T: Ptr<T> {
191191
pure fn offset(count: uint) -> *T { offset(self, count) }
192192
}
193193

194+
/// Extension methods for mutable pointers
195+
impl<T> *mut T: Ptr<T> {
196+
/// Returns true if the pointer is equal to the null pointer.
197+
#[inline(always)]
198+
pure fn is_null() -> bool { is_null(self) }
199+
200+
/// Returns true if the pointer is not equal to the null pointer.
201+
#[inline(always)]
202+
pure fn is_not_null() -> bool { is_not_null(self) }
203+
204+
/// Calculates the offset from a mutable pointer.
205+
#[inline(always)]
206+
pure fn offset(count: uint) -> *mut T { mut_offset(self, count) }
207+
}
208+
194209
// Equality for pointers
195210
impl<T> *const T : Eq {
196211
pure fn eq(other: &*const T) -> bool unsafe {
@@ -311,4 +326,12 @@ pub fn test_is_null() {
311326
let q = ptr::offset(p, 1u);
312327
assert !q.is_null();
313328
assert q.is_not_null();
329+
330+
let mp: *mut int = ptr::mut_null();
331+
assert mp.is_null();
332+
assert !mp.is_not_null();
333+
334+
let mq = mp.offset(1u);
335+
assert !mq.is_null();
336+
assert mq.is_not_null();
314337
}

0 commit comments

Comments
 (0)