Skip to content

Commit 956813e

Browse files
committed
---
yaml --- r: 30798 b: refs/heads/incoming c: cd79e1d h: refs/heads/master v: v3
1 parent 8d2a148 commit 956813e

File tree

4 files changed

+52
-83
lines changed

4 files changed

+52
-83
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: c91821d356b87dcbede651a1130ea758bf6a5265
9+
refs/heads/incoming: cd79e1d1b20a2c289dd15bc2766f97c789d975aa
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/ptr.rs

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
11
//! Unsafe pointer utility functions
22
3-
export addr_of;
4-
export to_unsafe_ptr;
5-
export to_const_unsafe_ptr;
6-
export to_mut_unsafe_ptr;
7-
export mut_addr_of;
8-
export offset;
9-
export const_offset;
10-
export mut_offset;
11-
export null;
12-
export mut_null;
13-
export is_null;
14-
export is_not_null;
15-
export memcpy;
16-
export memmove;
17-
export memset;
18-
export to_uint;
19-
export ref_eq;
20-
export buf_len;
21-
export position;
22-
export Ptr;
23-
243
use cmp::{Eq, Ord};
254
use libc::{c_void, size_t};
265

@@ -49,47 +28,47 @@ extern mod rusti {
4928

5029
/// Get an unsafe pointer to a value
5130
#[inline(always)]
52-
pure fn addr_of<T>(val: T) -> *T { unsafe { rusti::addr_of(val) } }
31+
pub pure fn addr_of<T>(val: T) -> *T { unsafe { rusti::addr_of(val) } }
5332

5433
/// Get an unsafe mut pointer to a value
5534
#[inline(always)]
56-
pure fn mut_addr_of<T>(val: T) -> *mut T {
35+
pub pure fn mut_addr_of<T>(val: T) -> *mut T {
5736
unsafe {
5837
cast::reinterpret_cast(&rusti::addr_of(val))
5938
}
6039
}
6140

6241
/// Calculate the offset from a pointer
6342
#[inline(always)]
64-
fn offset<T>(ptr: *T, count: uint) -> *T {
43+
pub fn offset<T>(ptr: *T, count: uint) -> *T {
6544
unsafe {
6645
(ptr as uint + count * sys::size_of::<T>()) as *T
6746
}
6847
}
6948

7049
/// Calculate the offset from a const pointer
7150
#[inline(always)]
72-
fn const_offset<T>(ptr: *const T, count: uint) -> *const T {
51+
pub fn const_offset<T>(ptr: *const T, count: uint) -> *const T {
7352
unsafe {
7453
(ptr as uint + count * sys::size_of::<T>()) as *T
7554
}
7655
}
7756

7857
/// Calculate the offset from a mut pointer
7958
#[inline(always)]
80-
fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
59+
pub fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
8160
(ptr as uint + count * sys::size_of::<T>()) as *mut T
8261
}
8362

8463
/// Return the offset of the first null pointer in `buf`.
8564
#[inline(always)]
86-
unsafe fn buf_len<T>(buf: **T) -> uint {
65+
pub unsafe fn buf_len<T>(buf: **T) -> uint {
8766
position(buf, |i| i == null())
8867
}
8968

9069
/// Return the first offset `i` such that `f(buf[i]) == true`.
9170
#[inline(always)]
92-
unsafe fn position<T>(buf: *T, f: fn(T) -> bool) -> uint {
71+
pub unsafe fn position<T>(buf: *T, f: fn(T) -> bool) -> uint {
9372
let mut i = 0u;
9473
loop {
9574
if f(*offset(buf, i)) { return i; }
@@ -99,17 +78,17 @@ unsafe fn position<T>(buf: *T, f: fn(T) -> bool) -> uint {
9978

10079
/// Create an unsafe null pointer
10180
#[inline(always)]
102-
pure fn null<T>() -> *T { unsafe { cast::reinterpret_cast(&0u) } }
81+
pub pure fn null<T>() -> *T { unsafe { cast::reinterpret_cast(&0u) } }
10382

10483
/// Create an unsafe mutable null pointer
10584
#[inline(always)]
106-
pure fn mut_null<T>() -> *mut T { unsafe { cast::reinterpret_cast(&0u) } }
85+
pub pure fn mut_null<T>() -> *mut T { unsafe { cast::reinterpret_cast(&0u) } }
10786

10887
/// Returns true if the pointer is equal to the null pointer.
109-
pure fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
88+
pub pure fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
11089

11190
/// Returns true if the pointer is not equal to the null pointer.
112-
pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
91+
pub pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
11392

11493
/**
11594
* Copies data from one location to another
@@ -118,7 +97,7 @@ pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
11897
* and destination may not overlap.
11998
*/
12099
#[inline(always)]
121-
unsafe fn memcpy<T>(dst: *mut T, src: *const T, count: uint) {
100+
pub unsafe fn memcpy<T>(dst: *mut T, src: *const T, count: uint) {
122101
let n = count * sys::size_of::<T>();
123102
libc_::memcpy(dst as *mut c_void, src as *c_void, n as size_t);
124103
}
@@ -130,13 +109,13 @@ unsafe fn memcpy<T>(dst: *mut T, src: *const T, count: uint) {
130109
* and destination may overlap.
131110
*/
132111
#[inline(always)]
133-
unsafe fn memmove<T>(dst: *mut T, src: *const T, count: uint) {
112+
pub unsafe fn memmove<T>(dst: *mut T, src: *const T, count: uint) {
134113
let n = count * sys::size_of::<T>();
135114
libc_::memmove(dst as *mut c_void, src as *c_void, n as size_t);
136115
}
137116

138117
#[inline(always)]
139-
unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
118+
pub unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
140119
let n = count * sys::size_of::<T>();
141120
libc_::memset(dst as *mut c_void, c as libc::c_int, n as size_t);
142121
}
@@ -148,7 +127,7 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
148127
reinterpret_cast.
149128
*/
150129
#[inline(always)]
151-
fn to_unsafe_ptr<T>(thing: &T) -> *T {
130+
pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
152131
unsafe { cast::reinterpret_cast(&thing) }
153132
}
154133

@@ -158,7 +137,7 @@ fn to_unsafe_ptr<T>(thing: &T) -> *T {
158137
reinterpret_cast.
159138
*/
160139
#[inline(always)]
161-
fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
140+
pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
162141
unsafe { cast::reinterpret_cast(&thing) }
163142
}
164143

@@ -168,7 +147,7 @@ fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
168147
reinterpret_cast.
169148
*/
170149
#[inline(always)]
171-
fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
150+
pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
172151
unsafe { cast::reinterpret_cast(&thing) }
173152
}
174153

@@ -180,17 +159,17 @@ fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
180159
(I couldn't think of a cutesy name for this one.)
181160
*/
182161
#[inline(always)]
183-
fn to_uint<T>(thing: &T) -> uint unsafe {
162+
pub fn to_uint<T>(thing: &T) -> uint unsafe {
184163
cast::reinterpret_cast(&thing)
185164
}
186165

187166
/// Determine if two borrowed pointers point to the same thing.
188167
#[inline(always)]
189-
fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
168+
pub fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
190169
to_uint(thing) == to_uint(other)
191170
}
192171

193-
trait Ptr {
172+
pub trait Ptr {
194173
pure fn is_null() -> bool;
195174
pure fn is_not_null() -> bool;
196175
}
@@ -253,7 +232,7 @@ impl<T:Ord> &const T : Ord {
253232
}
254233

255234
#[test]
256-
fn test() {
235+
pub fn test() {
257236
unsafe {
258237
type Pair = {mut fst: int, mut snd: int};
259238
let p = {mut fst: 10, mut snd: 20};
@@ -285,7 +264,7 @@ fn test() {
285264
}
286265

287266
#[test]
288-
fn test_position() {
267+
pub fn test_position() {
289268
use str::as_c_str;
290269
use libc::c_char;
291270

@@ -298,7 +277,7 @@ fn test_position() {
298277
}
299278

300279
#[test]
301-
fn test_buf_len() {
280+
pub fn test_buf_len() {
302281
let s0 = ~"hello";
303282
let s1 = ~"there";
304283
let s2 = ~"thing";
@@ -316,7 +295,7 @@ fn test_buf_len() {
316295
}
317296

318297
#[test]
319-
fn test_is_null() {
298+
pub fn test_is_null() {
320299
let p: *int = ptr::null();
321300
assert p.is_null();
322301
assert !p.is_not_null();

branches/incoming/src/libcore/send_map.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use cmp::Eq;
1212
use hash::Hash;
1313
use to_bytes::IterBytes;
1414

15-
trait SendMap<K:Eq Hash, V: Copy> {
15+
pub trait SendMap<K:Eq Hash, V: Copy> {
1616
// FIXME(#3148) ^^^^ once find_ref() works, we can drop V:copy
1717

1818
fn insert(&mut self, +k: K, +v: V) -> bool;
@@ -31,17 +31,15 @@ trait SendMap<K:Eq Hash, V: Copy> {
3131
}
3232

3333
/// Open addressing with linear probing.
34-
mod linear {
35-
#[legacy_exports];
36-
export LinearMap, linear_map, linear_map_with_capacity, public_methods;
37-
34+
pub mod linear {
3835
const initial_capacity: uint = 32u; // 2^5
36+
3937
struct Bucket<K:Eq Hash,V> {
4038
hash: uint,
4139
key: K,
4240
value: V,
4341
}
44-
struct LinearMap<K:Eq Hash,V> {
42+
pub struct LinearMap<K:Eq Hash,V> {
4543
k0: u64,
4644
k1: u64,
4745
resize_at: uint,
@@ -60,11 +58,11 @@ mod linear {
6058
((capacity as float) * 3. / 4.) as uint
6159
}
6260

63-
fn LinearMap<K:Eq Hash,V>() -> LinearMap<K,V> {
61+
pub fn LinearMap<K:Eq Hash,V>() -> LinearMap<K,V> {
6462
linear_map_with_capacity(32)
6563
}
6664

67-
fn linear_map_with_capacity<K:Eq Hash,V>(
65+
pub fn linear_map_with_capacity<K:Eq Hash,V>(
6866
initial_capacity: uint) -> LinearMap<K,V> {
6967
let r = rand::Rng();
7068
linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(),
@@ -366,13 +364,11 @@ mod linear {
366364
}
367365

368366
#[test]
369-
mod test {
370-
#[legacy_exports];
371-
367+
pub mod test {
372368
use linear::LinearMap;
373369

374370
#[test]
375-
fn inserts() {
371+
pub fn inserts() {
376372
let mut m = ~LinearMap();
377373
assert m.insert(1, 2);
378374
assert m.insert(2, 4);
@@ -381,7 +377,7 @@ mod test {
381377
}
382378

383379
#[test]
384-
fn overwrite() {
380+
pub fn overwrite() {
385381
let mut m = ~LinearMap();
386382
assert m.insert(1, 2);
387383
assert m.get(&1) == 2;
@@ -390,7 +386,7 @@ mod test {
390386
}
391387

392388
#[test]
393-
fn conflicts() {
389+
pub fn conflicts() {
394390
let mut m = linear::linear_map_with_capacity(4);
395391
assert m.insert(1, 2);
396392
assert m.insert(5, 3);
@@ -401,7 +397,7 @@ mod test {
401397
}
402398

403399
#[test]
404-
fn conflict_remove() {
400+
pub fn conflict_remove() {
405401
let mut m = linear::linear_map_with_capacity(4);
406402
assert m.insert(1, 2);
407403
assert m.insert(5, 3);
@@ -412,7 +408,7 @@ mod test {
412408
}
413409

414410
#[test]
415-
fn empty() {
411+
pub fn empty() {
416412
let mut m = linear::linear_map_with_capacity(4);
417413
assert m.insert(1, 2);
418414
assert !m.is_empty();
@@ -421,7 +417,7 @@ mod test {
421417
}
422418

423419
#[test]
424-
fn iterate() {
420+
pub fn iterate() {
425421
let mut m = linear::linear_map_with_capacity(4);
426422
for uint::range(0, 32) |i| {
427423
assert m.insert(i, i*2);
@@ -435,7 +431,7 @@ mod test {
435431
}
436432

437433
#[test]
438-
fn find_ref() {
434+
pub fn find_ref() {
439435
let mut m = ~LinearMap();
440436
assert m.find_ref(&1).is_none();
441437
m.insert(1, 2);

0 commit comments

Comments
 (0)