Skip to content

Commit 162228f

Browse files
committed
---
yaml --- r: 61399 b: refs/heads/try c: f198832 h: refs/heads/master i: 61397: d366a43 61395: bea5fff 61391: 480c66f v: v3
1 parent 09e49f1 commit 162228f

File tree

22 files changed

+238
-158
lines changed

22 files changed

+238
-158
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: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2d28d645422c1617be58c8ca7ad9a457264ca850
5-
refs/heads/try: cd2eb4701fc16e7acd6934759be043b1f7e5586d
5+
refs/heads/try: f19883223cbf72ec28b503cae71f823fc2229708
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/.swo

-72 KB
Binary file not shown.

branches/try/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ Supported traits for `deriving` are:
15621562

15631563
* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
15641564
* Serialization: `Encodable`, `Decodable`. These require `std`.
1565-
* `Clone` and `DeepClone`, to perform (deep) copies.
1565+
* `Clone`, to perform deep copies.
15661566
* `IterBytes`, to iterate over the bytes in a data type.
15671567
* `Rand`, to create a random instance of a data type.
15681568
* `ToStr`, to convert to a string. For a type with this instance,

branches/try/doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,8 +2308,8 @@ enum ABC { A, B, C }
23082308
~~~
23092309

23102310
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
2311-
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `DeepClone`,
2312-
`IterBytes`, `Rand` and `ToStr`.
2311+
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `IterBytes`, `Rand` and
2312+
`ToStr`.
23132313

23142314
# Modules and crates
23152315

branches/try/src/libcore/clone.rs

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ by convention implementing the `Clone` trait and calling the
2222
2323
*/
2424

25+
use core::kinds::Const;
26+
2527
pub trait Clone {
2628
/// Return a deep copy of the owned object tree. Types with shared ownership like managed boxes
2729
/// are cloned with a shallow copy.
@@ -46,6 +48,12 @@ impl<T> Clone for @mut T {
4648
fn clone(&self) -> @mut T { *self }
4749
}
4850

51+
impl<'self, T> Clone for &'self T {
52+
/// Return a shallow copy of the borrowed pointer.
53+
#[inline(always)]
54+
fn clone(&self) -> &'self T { *self }
55+
}
56+
4957
macro_rules! clone_impl(
5058
($t:ty) => {
5159
impl Clone for $t {
@@ -78,11 +86,32 @@ clone_impl!(char)
7886

7987
pub trait DeepClone {
8088
/// Return a deep copy of the object tree. Types with shared ownership are also copied via a
81-
/// deep copy, unlike `Clone`. Note that this is currently unimplemented for managed boxes, as
82-
/// it would need to handle cycles.
89+
/// deep copy, unlike `Clone`.
8390
fn deep_clone(&self) -> Self;
8491
}
8592

93+
impl<T: DeepClone> DeepClone for ~T {
94+
/// Return a deep copy of the owned box.
95+
#[inline(always)]
96+
fn deep_clone(&self) -> ~T { ~(**self).deep_clone() }
97+
}
98+
99+
// FIXME: #6525: should also be implemented for `T: Owned + DeepClone`
100+
impl<T: Const + DeepClone> DeepClone for @T {
101+
/// Return a deep copy of the managed box. The `Const` trait is required to prevent performing
102+
/// a deep clone of a potentially cyclical type.
103+
#[inline(always)]
104+
fn deep_clone(&self) -> @T { @(**self).deep_clone() }
105+
}
106+
107+
// FIXME: #6525: should also be implemented for `T: Owned + DeepClone`
108+
impl<T: Const + DeepClone> DeepClone for @mut T {
109+
/// Return a deep copy of the managed box. The `Const` trait is required to prevent performing
110+
/// a deep clone of a potentially cyclical type.
111+
#[inline(always)]
112+
fn deep_clone(&self) -> @mut T { @mut (**self).deep_clone() }
113+
}
114+
86115
macro_rules! deep_clone_impl(
87116
($t:ty) => {
88117
impl DeepClone for $t {
@@ -93,12 +122,6 @@ macro_rules! deep_clone_impl(
93122
}
94123
)
95124

96-
impl<T: DeepClone> DeepClone for ~T {
97-
/// Return a deep copy of the owned box.
98-
#[inline(always)]
99-
fn deep_clone(&self) -> ~T { ~(**self).deep_clone() }
100-
}
101-
102125
deep_clone_impl!(int)
103126
deep_clone_impl!(i8)
104127
deep_clone_impl!(i16)
@@ -121,23 +144,39 @@ deep_clone_impl!(char)
121144

122145
#[test]
123146
fn test_owned_clone() {
124-
let a: ~int = ~5i;
147+
let a = ~5i;
125148
let b: ~int = a.clone();
126149
assert!(a == b);
127150
}
128151

129152
#[test]
130153
fn test_managed_clone() {
131-
let a: @int = @5i;
154+
let a = @5i;
132155
let b: @int = a.clone();
133156
assert!(a == b);
134157
}
135158

159+
#[test]
160+
fn test_managed_mut_deep_clone() {
161+
let x = @mut 5i;
162+
let y: @mut int = x.deep_clone();
163+
*x = 20;
164+
assert_eq!(*y, 5);
165+
}
166+
136167
#[test]
137168
fn test_managed_mut_clone() {
138-
let a: @mut int = @mut 5i;
169+
let a = @mut 5i;
139170
let b: @mut int = a.clone();
140171
assert!(a == b);
141172
*b = 10;
142173
assert!(a == b);
143174
}
175+
176+
#[test]
177+
fn test_borrowed_clone() {
178+
let x = 5i;
179+
let y: &int = &x;
180+
let z: &int = (&y).clone();
181+
assert_eq!(*z, 5);
182+
}

branches/try/src/libcore/os.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,33 @@ pub fn setenv(n: &str, v: &str) {
289289
}
290290
}
291291

292+
/// Remove a variable from the environment entirely
293+
pub fn unsetenv(n: &str) {
294+
#[cfg(unix)]
295+
fn _unsetenv(n: &str) {
296+
unsafe {
297+
do with_env_lock {
298+
do str::as_c_str(n) |nbuf| {
299+
libc::funcs::posix01::unistd::unsetenv(nbuf);
300+
}
301+
}
302+
}
303+
}
304+
#[cfg(windows)]
305+
fn _unsetenv(n: &str) {
306+
unsafe {
307+
do with_env_lock {
308+
use os::win32::as_utf16_p;
309+
do as_utf16_p(n) |nbuf| {
310+
libc::SetEnvironmentVariableW(nbuf, ptr::null());
311+
}
312+
}
313+
}
314+
}
315+
316+
_unsetenv(n);
317+
}
318+
292319
pub fn fdopen(fd: c_int) -> *FILE {
293320
unsafe {
294321
return do as_c_charp("r") |modebuf| {
@@ -1412,7 +1439,7 @@ mod tests {
14121439
use option::Some;
14131440
use option;
14141441
use os::{as_c_charp, env, getcwd, getenv, make_absolute, real_args};
1415-
use os::{remove_file, setenv};
1442+
use os::{remove_file, setenv, unsetenv};
14161443
use os;
14171444
use path::Path;
14181445
use rand::RngUtil;
@@ -1448,6 +1475,14 @@ mod tests {
14481475
assert!(getenv(n) == option::Some(~"VALUE"));
14491476
}
14501477
1478+
#[test]
1479+
fn test_unsetenv() {
1480+
let n = make_rand_name();
1481+
setenv(n, ~"VALUE");
1482+
unsetenv(n);
1483+
assert!(getenv(n) == option::None);
1484+
}
1485+
14511486
#[test]
14521487
#[ignore(cfg(windows))]
14531488
#[ignore]

branches/try/src/libcore/vec.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,23 +2546,29 @@ pub mod raw {
25462546
* would also make any pointers to it invalid.
25472547
*/
25482548
#[inline(always)]
2549-
pub unsafe fn to_ptr<T>(v: &[T]) -> *T {
2550-
let repr: **SliceRepr = transmute(&v);
2551-
transmute(&((**repr).data))
2549+
pub fn to_ptr<T>(v: &[T]) -> *T {
2550+
unsafe {
2551+
let repr: **SliceRepr = transmute(&v);
2552+
transmute(&((**repr).data))
2553+
}
25522554
}
25532555

25542556
/** see `to_ptr()` */
25552557
#[inline(always)]
2556-
pub unsafe fn to_const_ptr<T>(v: &const [T]) -> *const T {
2557-
let repr: **SliceRepr = transmute(&v);
2558-
transmute(&((**repr).data))
2558+
pub fn to_const_ptr<T>(v: &const [T]) -> *const T {
2559+
unsafe {
2560+
let repr: **SliceRepr = transmute(&v);
2561+
transmute(&((**repr).data))
2562+
}
25592563
}
25602564

25612565
/** see `to_ptr()` */
25622566
#[inline(always)]
2563-
pub unsafe fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
2564-
let repr: **SliceRepr = transmute(&v);
2565-
transmute(&((**repr).data))
2567+
pub fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
2568+
unsafe {
2569+
let repr: **SliceRepr = transmute(&v);
2570+
transmute(&((**repr).data))
2571+
}
25662572
}
25672573

25682574
/**

branches/try/src/librustpkg/tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ fn test_sysroot() -> Path {
9393
self_path.pop()
9494
}
9595

96+
// Ignored on i686 -- see #6517
9697
#[test]
98+
#[ignore(cfg(target_arch = "x86"))]
9799
fn test_make_dir_rwx() {
98100
let temp = &os::tmpdir();
99101
let dir = temp.push(~"quux");
@@ -107,6 +109,7 @@ fn test_make_dir_rwx() {
107109
}
108110

109111
#[test]
112+
#[ignore(cfg(target_arch = "x86"))]
110113
fn test_install_valid() {
111114
let sysroot = test_sysroot();
112115
debug!("sysroot = %s", sysroot.to_str());
@@ -132,6 +135,7 @@ fn test_install_valid() {
132135
}
133136

134137
#[test]
138+
#[ignore(cfg(target_arch = "x86"))]
135139
fn test_install_invalid() {
136140
use conditions::nonexistent_package::cond;
137141
use cond1 = conditions::missing_pkg_files::cond;
@@ -154,6 +158,7 @@ fn test_install_invalid() {
154158
}
155159

156160
#[test]
161+
#[ignore(cfg(target_arch = "x86"))]
157162
fn test_install_url() {
158163
let workspace = mkdtemp(&os::tmpdir(), "test").expect("couldn't create temp dir");
159164
let sysroot = test_sysroot();

0 commit comments

Comments
 (0)