Skip to content

Commit b71a693

Browse files
committed
---
yaml --- r: 113079 b: refs/heads/try c: e5cbc61 h: refs/heads/master i: 113077: 53135c6 113075: 401cef4 113071: 0867ab5 v: v3
1 parent 39eeb55 commit b71a693

File tree

4 files changed

+40
-60
lines changed

4 files changed

+40
-60
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: abdacecdf86b4b5a4f432560445a24e1c5f4751b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 922c420fcd4dfbfc7e3bce4dd20d9b17a20b39f3
5-
refs/heads/try: 89c1923cac37fb149ba72422fe1033b9a9a43bc9
5+
refs/heads/try: e5cbc613069679f15a8e199c7f6a98aa1ea864e5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libnative/io/file_win32.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::ptr;
2222
use std::rt::rtio;
2323
use std::str;
2424
use std::sync::arc::UnsafeArc;
25-
use std::slice;
25+
use std::vec;
2626

2727
use io::IoResult;
2828

@@ -353,8 +353,8 @@ pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
353353
if fp_buf as uint == 0 {
354354
fail!("os::list_dir() failure: got null ptr from wfd");
355355
} else {
356-
let fp_vec = slice::from_buf(fp_buf, libc::wcslen(fp_buf) as uint);
357-
let fp_trimmed = str::truncate_utf16_at_nul(fp_vec);
356+
let fp_vec = vec::raw::from_buf(fp_buf, libc::wcslen(fp_buf) as uint);
357+
let fp_trimmed = str::truncate_utf16_at_nul(fp_vec.as_slice());
358358
let fp_str = str::from_utf16(fp_trimmed)
359359
.expect("rust_list_dir_wfd_fp_buf returned invalid UTF-16");
360360
paths.push(Path::new(fp_str));

branches/try/src/libstd/slice.rs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,19 +1862,6 @@ impl<'a, T: TotalOrd> MutableTotalOrdVector<T> for &'a mut [T] {
18621862
}
18631863
}
18641864

1865-
/**
1866-
* Constructs a vector from an unsafe pointer to a buffer
1867-
*
1868-
* # Arguments
1869-
*
1870-
* * ptr - An unsafe pointer to a buffer of `T`
1871-
* * elts - The number of elements in the buffer
1872-
*/
1873-
// Wrapper for fn in raw: needs to be called by net_tcp::on_tcp_read_cb
1874-
pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
1875-
raw::from_buf_raw(ptr, elts)
1876-
}
1877-
18781865
/// Unsafe operations
18791866
pub mod raw {
18801867
use cast::transmute;
@@ -1915,23 +1902,6 @@ pub mod raw {
19151902
}))
19161903
}
19171904

1918-
/**
1919-
* Constructs a vector from an unsafe pointer to a buffer
1920-
*
1921-
* # Arguments
1922-
*
1923-
* * ptr - An unsafe pointer to a buffer of `T`
1924-
* * elts - The number of elements in the buffer
1925-
*/
1926-
// Was in raw, but needs to be called by net_tcp::on_tcp_read_cb
1927-
#[inline]
1928-
pub unsafe fn from_buf_raw<T>(ptr: *T, elts: uint) -> ~[T] {
1929-
let mut dst = Vec::with_capacity(elts);
1930-
dst.set_len(elts);
1931-
ptr::copy_memory(dst.as_mut_ptr(), ptr, elts);
1932-
dst.move_iter().collect()
1933-
}
1934-
19351905
/**
19361906
* Returns a pointer to first element in slice and adjusts
19371907
* slice so it no longer contains that element. Fails if
@@ -2315,31 +2285,6 @@ mod tests {
23152285

23162286
fn is_odd(n: &uint) -> bool { *n % 2u == 1u }
23172287

2318-
#[test]
2319-
fn test_unsafe_ptrs() {
2320-
unsafe {
2321-
// Test on-stack copy-from-buf.
2322-
let a = box [1, 2, 3];
2323-
let mut ptr = a.as_ptr();
2324-
let b = from_buf(ptr, 3u);
2325-
assert_eq!(b.len(), 3u);
2326-
assert_eq!(b[0], 1);
2327-
assert_eq!(b[1], 2);
2328-
assert_eq!(b[2], 3);
2329-
2330-
// Test on-heap copy-from-buf.
2331-
let c = box [1, 2, 3, 4, 5];
2332-
ptr = c.as_ptr();
2333-
let d = from_buf(ptr, 5u);
2334-
assert_eq!(d.len(), 5u);
2335-
assert_eq!(d[0], 1);
2336-
assert_eq!(d[1], 2);
2337-
assert_eq!(d[2], 3);
2338-
assert_eq!(d[3], 4);
2339-
assert_eq!(d[4], 5);
2340-
}
2341-
}
2342-
23432288
#[test]
23442289
fn test_from_fn() {
23452290
// Test on-stack from_fn.

branches/try/src/libstd/vec.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,12 +1454,30 @@ pub fn unzip<T, U, V: Iterator<(T, U)>>(mut iter: V) -> (Vec<T>, Vec<U>) {
14541454
(ts, us)
14551455
}
14561456

1457+
/// Unsafe operations
1458+
pub mod raw {
1459+
use super::Vec;
1460+
use ptr;
1461+
1462+
/// Constructs a vector from an unsafe pointer to a buffer.
1463+
///
1464+
/// The elements of the buffer are copied into the vector without cloning,
1465+
/// as if `ptr::read()` were called on them.
1466+
#[inline]
1467+
pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> Vec<T> {
1468+
let mut dst = Vec::with_capacity(elts);
1469+
dst.set_len(elts);
1470+
ptr::copy_nonoverlapping_memory(dst.as_mut_ptr(), ptr, elts);
1471+
dst
1472+
}
1473+
}
1474+
14571475

14581476
#[cfg(test)]
14591477
mod tests {
14601478
use prelude::*;
14611479
use mem::size_of;
1462-
use super::unzip;
1480+
use super::{unzip, raw};
14631481

14641482
#[test]
14651483
fn test_small_vec_struct() {
@@ -1719,4 +1737,21 @@ mod tests {
17191737
assert_eq!((2, 5), (left[1], right[1]));
17201738
assert_eq!((3, 6), (left[2], right[2]));
17211739
}
1740+
1741+
#[test]
1742+
fn test_unsafe_ptrs() {
1743+
unsafe {
1744+
// Test on-stack copy-from-buf.
1745+
let a = [1, 2, 3];
1746+
let ptr = a.as_ptr();
1747+
let b = raw::from_buf(ptr, 3u);
1748+
assert_eq!(b, vec![1, 2, 3]);
1749+
1750+
// Test on-heap copy-from-buf.
1751+
let c = box [1, 2, 3, 4, 5];
1752+
let ptr = c.as_ptr();
1753+
let d = raw::from_buf(ptr, 5u);
1754+
assert_eq!(d, vec![1, 2, 3, 4, 5]);
1755+
}
1756+
}
17221757
}

0 commit comments

Comments
 (0)