Skip to content

Commit ea285c6

Browse files
committed
---
yaml --- r: 113276 b: refs/heads/snap-stage3 c: 189dc5f h: refs/heads/master v: v3
1 parent d42f54c commit ea285c6

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

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

@@ -368,8 +368,8 @@ pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
368368
if fp_buf as uint == 0 {
369369
fail!("os::list_dir() failure: got null ptr from wfd");
370370
} else {
371-
let fp_vec = slice::from_buf(fp_buf, libc::wcslen(fp_buf) as uint);
372-
let fp_trimmed = str::truncate_utf16_at_nul(fp_vec);
371+
let fp_vec = vec::raw::from_buf(fp_buf, libc::wcslen(fp_buf) as uint);
372+
let fp_trimmed = str::truncate_utf16_at_nul(fp_vec.as_slice());
373373
let fp_str = str::from_utf16(fp_trimmed)
374374
.expect("rust_list_dir_wfd_fp_buf returned invalid UTF-16");
375375
paths.push(Path::new(fp_str));

branches/snap-stage3/src/libstd/slice.rs

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

725-
/**
726-
* Constructs a vector from an unsafe pointer to a buffer
727-
*
728-
* # Arguments
729-
*
730-
* * ptr - An unsafe pointer to a buffer of `T`
731-
* * elts - The number of elements in the buffer
732-
*/
733-
// Wrapper for fn in raw: needs to be called by net_tcp::on_tcp_read_cb
734-
pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
735-
raw::from_buf_raw(ptr, elts)
736-
}
737-
738725
/// Unsafe operations
739726
pub mod raw {
740727
use iter::Iterator;
@@ -744,23 +731,6 @@ pub mod raw {
744731

745732
pub use core::slice::raw::{buf_as_slice, mut_buf_as_slice};
746733
pub use core::slice::raw::{shift_ptr, pop_ptr};
747-
748-
/**
749-
* Constructs a vector from an unsafe pointer to a buffer
750-
*
751-
* # Arguments
752-
*
753-
* * ptr - An unsafe pointer to a buffer of `T`
754-
* * elts - The number of elements in the buffer
755-
*/
756-
// Was in raw, but needs to be called by net_tcp::on_tcp_read_cb
757-
#[inline]
758-
pub unsafe fn from_buf_raw<T>(ptr: *T, elts: uint) -> ~[T] {
759-
let mut dst = Vec::with_capacity(elts);
760-
dst.set_len(elts);
761-
ptr::copy_memory(dst.as_mut_ptr(), ptr, elts);
762-
dst.move_iter().collect()
763-
}
764734
}
765735

766736
/// An iterator that moves out of a vector.
@@ -820,31 +790,6 @@ mod tests {
820790

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

823-
#[test]
824-
fn test_unsafe_ptrs() {
825-
unsafe {
826-
// Test on-stack copy-from-buf.
827-
let a = box [1, 2, 3];
828-
let mut ptr = a.as_ptr();
829-
let b = from_buf(ptr, 3u);
830-
assert_eq!(b.len(), 3u);
831-
assert_eq!(b[0], 1);
832-
assert_eq!(b[1], 2);
833-
assert_eq!(b[2], 3);
834-
835-
// Test on-heap copy-from-buf.
836-
let c = box [1, 2, 3, 4, 5];
837-
ptr = c.as_ptr();
838-
let d = from_buf(ptr, 5u);
839-
assert_eq!(d.len(), 5u);
840-
assert_eq!(d[0], 1);
841-
assert_eq!(d[1], 2);
842-
assert_eq!(d[2], 3);
843-
assert_eq!(d[3], 4);
844-
assert_eq!(d[4], 5);
845-
}
846-
}
847-
848793
#[test]
849794
fn test_from_fn() {
850795
// Test on-stack from_fn.

branches/snap-stage3/src/libstd/vec.rs

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

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

14591477
#[cfg(test)]
14601478
mod tests {
14611479
use prelude::*;
14621480
use mem::size_of;
1463-
use super::unzip;
1481+
use super::{unzip, raw};
14641482

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

0 commit comments

Comments
 (0)