Skip to content

Commit a34b8da

Browse files
committed
---
yaml --- r: 61349 b: refs/heads/try c: 6ef226d h: refs/heads/master i: 61347: a28d764 v: v3
1 parent 239f429 commit a34b8da

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
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: bcec83aaee0a44639a4b231834140dcb1d9adc7b
5+
refs/heads/try: 6ef226d5d95ac2248178e85accc52d0161d76540
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

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/task/local_data_priv.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
9494
let map_ptr = rt::rust_get_task_local_data(task);
9595
if map_ptr.is_null() {
9696
let map: TaskLocalMap = @mut ~[];
97-
// NB: This bumps the ref count before converting to an unsafe pointer,
98-
// keeping the map alive until TLS is destroyed
9997
rt::rust_set_task_local_data(task, cast::transmute(map));
10098
rt::rust_task_local_data_atexit(task, cleanup_task_local_map_extern_cb);
99+
// Also need to reference it an extra time to keep it for now.
100+
let nonmut = cast::transmute::<TaskLocalMap,
101+
@~[Option<TaskLocalElement>]>(map);
102+
cast::bump_box_refcount(nonmut);
101103
map
102104
} else {
103105
let map = cast::transmute(map_ptr);

0 commit comments

Comments
 (0)