1
Fork 0

Replacing str::unsafe_from_bytes with str::from_bytes (part 1)

This commit is contained in:
Kevin Cantu 2012-01-25 00:53:17 -08:00
parent 9750e83a17
commit c7b23f9a86
10 changed files with 16 additions and 11 deletions

View file

@ -440,6 +440,7 @@ mod rt {
let head = s[0]; let head = s[0];
if head == '+' as u8 || head == '-' as u8 || head == ' ' as u8 { if head == '+' as u8 || head == '-' as u8 || head == ' ' as u8 {
let headstr = str::unsafe_from_bytes([head]); let headstr = str::unsafe_from_bytes([head]);
// FIXME: not UTF-8 safe
let bytelen = str::byte_len(s); let bytelen = str::byte_len(s);
let numpart = str::substr(s, 1u, bytelen - 1u); let numpart = str::substr(s, 1u, bytelen - 1u);
ret headstr + padstr + numpart; ret headstr + padstr + numpart;

View file

@ -129,7 +129,8 @@ fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; }
/// followed by a path separator /// followed by a path separator
fn get_exe_path() -> option::t<fs::path> unsafe { fn get_exe_path() -> option::t<fs::path> unsafe {
let bufsize = 1023u; 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, let mib = [libc_constants::CTL_KERN,
libc_constants::KERN_PROC, libc_constants::KERN_PROC,
libc_constants::KERN_PROC_PATHNAME, -1i32]; libc_constants::KERN_PROC_PATHNAME, -1i32];

View file

@ -75,7 +75,7 @@ fn getenv(n: str) -> option::t<str> {
unsafe { unsafe {
vec::unsafe::set_len(v, res); 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; } } else { nsize = res; }
} }
fail; fail;

View file

@ -125,7 +125,8 @@ fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; }
/// followed by a path separator /// followed by a path separator
fn get_exe_path() -> option::t<fs::path> { fn get_exe_path() -> option::t<fs::path> {
let bufsize = 1023u; 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| ret str::as_buf("/proc/self/exe", { |proc_self_buf|
str::as_buf(path, { |path_buf| str::as_buf(path, { |path_buf|
if libc::readlink(proc_self_buf, path_buf, bufsize) != -1 { if libc::readlink(proc_self_buf, path_buf, bufsize) != -1 {

View file

@ -133,8 +133,9 @@ fn dylib_filename(base: str) -> str { ret "lib" + base + ".dylib"; }
fn get_exe_path() -> option::t<fs::path> { fn get_exe_path() -> option::t<fs::path> {
// FIXME: This doesn't handle the case where the buffer is too small // FIXME: This doesn't handle the case where the buffer is too small
// FIXME: path "strings" will likely need fixing...
let bufsize = 1023u32; 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| ret str::as_buf(path, { |path_buf|
if mac_libc::_NSGetExecutablePath(path_buf, if mac_libc::_NSGetExecutablePath(path_buf,
ptr::mut_addr_of(bufsize)) == 0i32 { ptr::mut_addr_of(bufsize)) == 0i32 {

View file

@ -216,7 +216,7 @@ fn read_all(rd: io::reader) -> str {
let buf = ""; let buf = "";
while !rd.eof() { while !rd.eof() {
let bytes = rd.read_bytes(4096u); let bytes = rd.read_bytes(4096u);
buf += str::unsafe_from_bytes(bytes); buf += str::from_bytes(bytes);
} }
ret buf; ret buf;
} }
@ -347,7 +347,7 @@ mod tests {
let buf = ""; let buf = "";
while !reader.eof() { while !reader.eof() {
let bytes = reader.read_bytes(4096u); let bytes = reader.read_bytes(4096u);
buf += str::unsafe_from_bytes(bytes); buf += str::from_bytes(bytes);
} }
os::fclose(file); os::fclose(file);
ret buf; ret buf;

View file

@ -131,7 +131,7 @@ fn test_http() {
unsafe { unsafe {
log(error, len); log(error, len);
let buf = vec::unsafe::from_buf(buf, len as uint); 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"); #error("read something");
io::println(str); io::println(str);
} }
@ -146,4 +146,4 @@ fn test_http() {
} }
join_thread(thread); join_thread(thread);
delete_thread(thread); delete_thread(thread);
} }

View file

@ -113,8 +113,9 @@ fn getcwd() -> str { ret rustrt::rust_getcwd(); }
fn get_exe_path() -> option::t<fs::path> { fn get_exe_path() -> option::t<fs::path> {
// FIXME: This doesn't handle the case where the buffer is too small // FIXME: This doesn't handle the case where the buffer is too small
// FIXME: path "strings" will likely need fixing...
let bufsize = 1023u; 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| ret str::as_buf(path, { |path_buf|
if kernel32::GetModuleFileNameA(0u, path_buf, if kernel32::GetModuleFileNameA(0u, path_buf,
bufsize as u32) != 0u32 { bufsize as u32) != 0u32 {

View file

@ -32,7 +32,7 @@ import comm::recv;
import comm::send; import comm::send;
fn map(&&filename: [u8], emit: map_reduce::putter<[u8], int>) { 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 { while true {
alt read_word(f) { alt read_word(f) {

View file

@ -81,7 +81,7 @@ mod map_reduce {
mapper_done { num_mappers -= 1; } mapper_done { num_mappers -= 1; }
find_reducer(k, cc) { find_reducer(k, cc) {
let c; let c;
alt reducers.find(str::unsafe_from_bytes(k)) { alt reducers.find(str::from_bytes(k)) {
some(_c) { c = _c; } some(_c) { c = _c; }
none { c = 0; } none { c = 0; }
} }