diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs index 52a738ab97fa..75fca2398ebc 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -5,6 +5,7 @@ * interface. */ import std::vec; +import std::istr; import std::option; import std::generic_os; import base::*; @@ -26,9 +27,11 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, // option::t rather than just an maybe-empty string. let var = expr_to_str(cx, args[0], "#env requires a string"); - alt generic_os::getenv(var) { + alt generic_os::getenv(istr::from_estr(var)) { option::none. { ret make_new_str(cx, sp, ""); } - option::some(s) { ret make_new_str(cx, sp, s); } + option::some(s) { + ret make_new_str(cx, sp, istr::to_estr(s)); + } } } diff --git a/src/lib/generic_os.rs b/src/lib/generic_os.rs index 80bc7747b47f..38662e6f95ed 100644 --- a/src/lib/generic_os.rs +++ b/src/lib/generic_os.rs @@ -3,23 +3,30 @@ import str::sbuf; #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] -fn getenv(n: str) -> option::t { +fn getenv(n: &istr) -> option::t { + let n = istr::to_estr(n); let s = os::libc::getenv(str::buf(n)); ret if s as int == 0 { - option::none:: - } else { option::some::(str::str_from_cstr(s)) }; + option::none:: + } else { + let s = unsafe::reinterpret_cast(s); + option::some::(istr::str_from_cstr(s)) + }; } #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] -fn setenv(n: str, v: str) { +fn setenv(n: &istr, v: &istr) { + let n = istr::to_estr(n); + let v = istr::to_estr(v); let nbuf = str::buf(n); let vbuf = str::buf(v); os::libc::setenv(nbuf, vbuf, 1); } #[cfg(target_os = "win32")] -fn getenv(n: str) -> option::t { +fn getenv(n: &istr) -> option::t { + let n = istr::to_estr(n); let nbuf = str::buf(n); let nsize = 256u; while true { @@ -29,14 +36,17 @@ fn getenv(n: str) -> option::t { if res == 0u { ret option::none; } else if res < nsize { - ret option::some(str::str_from_cstr(vbuf)); + let vbuf = unsafe::reinterpret_cast(vbuf); + ret option::some(istr::str_from_cstr(vbuf)); } else { nsize = res; } } fail; } #[cfg(target_os = "win32")] -fn setenv(n: str, v: str) { +fn setenv(n: &istr, v: &istr) { + let n = istr::to_estr(n); + let v = istr::to_estr(v); let nbuf = str::buf(n); let vbuf = str::buf(v); os::kernel32::SetEnvironmentVariableA(nbuf, vbuf); diff --git a/src/lib/term.rs b/src/lib/term.rs index 4e553a4d3dfa..cd5b1122a596 100644 --- a/src/lib/term.rs +++ b/src/lib/term.rs @@ -49,10 +49,10 @@ fn reset(writer: io::buf_writer) { fn color_supported() -> bool { let supported_terms = [~"xterm-color", ~"xterm", ~"screen-bce"]; - ret alt generic_os::getenv("TERM") { + ret alt generic_os::getenv(~"TERM") { option::some(env) { for term: istr in supported_terms { - if istr::eq(term, istr::from_estr(env)) { ret true; } + if istr::eq(term, env) { ret true; } } false } diff --git a/src/test/compiletest/procsrv.rs b/src/test/compiletest/procsrv.rs index 0e4c2c87d837..abe40b7a3270 100644 --- a/src/test/compiletest/procsrv.rs +++ b/src/test/compiletest/procsrv.rs @@ -153,11 +153,11 @@ fn worker(p: port) { } fn with_lib_path<@T>(path: &str, f: fn() -> T) -> T { - let maybe_oldpath = getenv(util::lib_path_env_var()); + let maybe_oldpath = getenv(istr::from_estr(util::lib_path_env_var())); append_lib_path(path); let res = f(); if option::is_some(maybe_oldpath) { - export_lib_path(option::get(maybe_oldpath)); + export_lib_path(istr::to_estr(option::get(maybe_oldpath))); } else { // FIXME: This should really be unset but we don't have that yet export_lib_path(""); @@ -167,7 +167,9 @@ fn with_lib_path<@T>(path: &str, f: fn() -> T) -> T { fn append_lib_path(path: &str) { export_lib_path(util::make_new_path(path)); } -fn export_lib_path(path: &str) { setenv(util::lib_path_env_var(), path); } +fn export_lib_path(path: &str) { + setenv(istr::from_estr(util::lib_path_env_var()), istr::from_estr(path)); +} fn clone_vecstr(v: &[str]) -> [[u8]] { let r = []; diff --git a/src/test/compiletest/util.rs b/src/test/compiletest/util.rs index 9bbcd6c7e99d..2aa313e29a19 100644 --- a/src/test/compiletest/util.rs +++ b/src/test/compiletest/util.rs @@ -1,6 +1,7 @@ import std::option; import std::generic_os::getenv; import std::io; +import std::istr; import common::config; @@ -8,8 +9,8 @@ fn make_new_path(path: &str) -> str { // Windows just uses PATH as the library search path, so we have to // maintain the current value while adding our own - alt getenv(lib_path_env_var()) { - option::some(curr) { #fmt["%s:%s", path, curr] } + alt getenv(istr::from_estr(lib_path_env_var())) { + option::some(curr) { #fmt["%s:%s", path, istr::to_estr(curr)] } option::none. { path } } } diff --git a/src/test/stdtest/os.rs b/src/test/stdtest/os.rs index 49ebb217dbf8..fc5085953299 100644 --- a/src/test/stdtest/os.rs +++ b/src/test/stdtest/os.rs @@ -6,26 +6,26 @@ import std::option; fn test_setenv() { // NB: Each test of setenv needs to use different variable names or the // tests will not be threadsafe - setenv("NAME1", "VALUE"); - assert (getenv("NAME1") == option::some("VALUE")); + setenv(~"NAME1", ~"VALUE"); + assert (getenv(~"NAME1") == option::some(~"VALUE")); } #[test] fn test_setenv_overwrite() { - setenv("NAME2", "1"); - setenv("NAME2", "2"); - assert (getenv("NAME2") == option::some("2")); + setenv(~"NAME2", ~"1"); + setenv(~"NAME2", ~"2"); + assert (getenv(~"NAME2") == option::some(~"2")); } // Windows GetEnvironmentVariable requires some extra work to make sure // the buffer the variable is copied into is the right size #[test] fn test_getenv_big() { - let s = ""; + let s = ~""; let i = 0; - while i < 100 { s += "aaaaaaaaaa"; i += 1; } - setenv("NAME3", s); - assert (getenv("NAME3") == option::some(s)); + while i < 100 { s += ~"aaaaaaaaaa"; i += 1; } + setenv(~"NAME3", s); + assert (getenv(~"NAME3") == option::some(s)); } // Local Variables: