Replacing str::unsafe_from_bytes with str::from_bytes (part 1)
This commit is contained in:
parent
9750e83a17
commit
c7b23f9a86
@ -440,6 +440,7 @@ mod rt {
|
||||
let head = s[0];
|
||||
if head == '+' as u8 || head == '-' as u8 || head == ' ' as u8 {
|
||||
let headstr = str::unsafe_from_bytes([head]);
|
||||
// FIXME: not UTF-8 safe
|
||||
let bytelen = str::byte_len(s);
|
||||
let numpart = str::substr(s, 1u, bytelen - 1u);
|
||||
ret headstr + padstr + numpart;
|
||||
|
@ -129,7 +129,8 @@ fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; }
|
||||
/// followed by a path separator
|
||||
fn get_exe_path() -> option::t<fs::path> unsafe {
|
||||
let bufsize = 1023u;
|
||||
let path = str::unsafe_from_bytes(vec::init_elt(bufsize, 0u8));
|
||||
// FIXME: path "strings" will likely need fixing...
|
||||
let path = str::from_bytes(vec::init_elt(bufsize, 0u8));
|
||||
let mib = [libc_constants::CTL_KERN,
|
||||
libc_constants::KERN_PROC,
|
||||
libc_constants::KERN_PROC_PATHNAME, -1i32];
|
||||
|
@ -75,7 +75,7 @@ fn getenv(n: str) -> option::t<str> {
|
||||
unsafe {
|
||||
vec::unsafe::set_len(v, res);
|
||||
}
|
||||
ret option::some(str::unsafe_from_bytes(v));
|
||||
ret option::some(str::from_bytes(v)); // UTF-8 or fail
|
||||
} else { nsize = res; }
|
||||
}
|
||||
fail;
|
||||
|
@ -125,7 +125,8 @@ fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; }
|
||||
/// followed by a path separator
|
||||
fn get_exe_path() -> option::t<fs::path> {
|
||||
let bufsize = 1023u;
|
||||
let path = str::unsafe_from_bytes(vec::init_elt(bufsize, 0u8));
|
||||
// FIXME: path "strings" will likely need fixing...
|
||||
let path = str::from_bytes(vec::init_elt(bufsize, 0u8));
|
||||
ret str::as_buf("/proc/self/exe", { |proc_self_buf|
|
||||
str::as_buf(path, { |path_buf|
|
||||
if libc::readlink(proc_self_buf, path_buf, bufsize) != -1 {
|
||||
|
@ -133,8 +133,9 @@ fn dylib_filename(base: str) -> str { ret "lib" + base + ".dylib"; }
|
||||
|
||||
fn get_exe_path() -> option::t<fs::path> {
|
||||
// FIXME: This doesn't handle the case where the buffer is too small
|
||||
// FIXME: path "strings" will likely need fixing...
|
||||
let bufsize = 1023u32;
|
||||
let path = str::unsafe_from_bytes(vec::init_elt(bufsize as uint, 0u8));
|
||||
let path = str::from_bytes(vec::init_elt(bufsize as uint, 0u8));
|
||||
ret str::as_buf(path, { |path_buf|
|
||||
if mac_libc::_NSGetExecutablePath(path_buf,
|
||||
ptr::mut_addr_of(bufsize)) == 0i32 {
|
||||
|
@ -216,7 +216,7 @@ fn read_all(rd: io::reader) -> str {
|
||||
let buf = "";
|
||||
while !rd.eof() {
|
||||
let bytes = rd.read_bytes(4096u);
|
||||
buf += str::unsafe_from_bytes(bytes);
|
||||
buf += str::from_bytes(bytes);
|
||||
}
|
||||
ret buf;
|
||||
}
|
||||
@ -347,7 +347,7 @@ mod tests {
|
||||
let buf = "";
|
||||
while !reader.eof() {
|
||||
let bytes = reader.read_bytes(4096u);
|
||||
buf += str::unsafe_from_bytes(bytes);
|
||||
buf += str::from_bytes(bytes);
|
||||
}
|
||||
os::fclose(file);
|
||||
ret buf;
|
||||
|
@ -131,7 +131,7 @@ fn test_http() {
|
||||
unsafe {
|
||||
log(error, len);
|
||||
let buf = vec::unsafe::from_buf(buf, len as uint);
|
||||
let str = str::unsafe_from_bytes(buf);
|
||||
let str = str::from_bytes(buf);
|
||||
#error("read something");
|
||||
io::println(str);
|
||||
}
|
||||
@ -146,4 +146,4 @@ fn test_http() {
|
||||
}
|
||||
join_thread(thread);
|
||||
delete_thread(thread);
|
||||
}
|
||||
}
|
||||
|
@ -113,8 +113,9 @@ fn getcwd() -> str { ret rustrt::rust_getcwd(); }
|
||||
|
||||
fn get_exe_path() -> option::t<fs::path> {
|
||||
// FIXME: This doesn't handle the case where the buffer is too small
|
||||
// FIXME: path "strings" will likely need fixing...
|
||||
let bufsize = 1023u;
|
||||
let path = str::unsafe_from_bytes(vec::init_elt(bufsize, 0u8));
|
||||
let path = str::from_bytes(vec::init_elt(bufsize, 0u8));
|
||||
ret str::as_buf(path, { |path_buf|
|
||||
if kernel32::GetModuleFileNameA(0u, path_buf,
|
||||
bufsize as u32) != 0u32 {
|
||||
|
@ -32,7 +32,7 @@ import comm::recv;
|
||||
import comm::send;
|
||||
|
||||
fn map(&&filename: [u8], emit: map_reduce::putter<[u8], int>) {
|
||||
let f = io::file_reader(str::unsafe_from_bytes(filename));
|
||||
let f = io::file_reader(str::from_bytes(filename));
|
||||
|
||||
while true {
|
||||
alt read_word(f) {
|
||||
|
@ -81,7 +81,7 @@ mod map_reduce {
|
||||
mapper_done { num_mappers -= 1; }
|
||||
find_reducer(k, cc) {
|
||||
let c;
|
||||
alt reducers.find(str::unsafe_from_bytes(k)) {
|
||||
alt reducers.find(str::from_bytes(k)) {
|
||||
some(_c) { c = _c; }
|
||||
none { c = 0; }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user