Skip to content

Commit c7b23f9

Browse files
committed
Replacing str::unsafe_from_bytes with str::from_bytes (part 1)
1 parent 9750e83 commit c7b23f9

File tree

10 files changed

+16
-11
lines changed

10 files changed

+16
-11
lines changed

src/libcore/extfmt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ mod rt {
440440
let head = s[0];
441441
if head == '+' as u8 || head == '-' as u8 || head == ' ' as u8 {
442442
let headstr = str::unsafe_from_bytes([head]);
443+
// FIXME: not UTF-8 safe
443444
let bytelen = str::byte_len(s);
444445
let numpart = str::substr(s, 1u, bytelen - 1u);
445446
ret headstr + padstr + numpart;

src/libstd/freebsd_os.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; }
129129
/// followed by a path separator
130130
fn get_exe_path() -> option::t<fs::path> unsafe {
131131
let bufsize = 1023u;
132-
let path = str::unsafe_from_bytes(vec::init_elt(bufsize, 0u8));
132+
// FIXME: path "strings" will likely need fixing...
133+
let path = str::from_bytes(vec::init_elt(bufsize, 0u8));
133134
let mib = [libc_constants::CTL_KERN,
134135
libc_constants::KERN_PROC,
135136
libc_constants::KERN_PROC_PATHNAME, -1i32];

src/libstd/generic_os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn getenv(n: str) -> option::t<str> {
7575
unsafe {
7676
vec::unsafe::set_len(v, res);
7777
}
78-
ret option::some(str::unsafe_from_bytes(v));
78+
ret option::some(str::from_bytes(v)); // UTF-8 or fail
7979
} else { nsize = res; }
8080
}
8181
fail;

src/libstd/linux_os.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; }
125125
/// followed by a path separator
126126
fn get_exe_path() -> option::t<fs::path> {
127127
let bufsize = 1023u;
128-
let path = str::unsafe_from_bytes(vec::init_elt(bufsize, 0u8));
128+
// FIXME: path "strings" will likely need fixing...
129+
let path = str::from_bytes(vec::init_elt(bufsize, 0u8));
129130
ret str::as_buf("/proc/self/exe", { |proc_self_buf|
130131
str::as_buf(path, { |path_buf|
131132
if libc::readlink(proc_self_buf, path_buf, bufsize) != -1 {

src/libstd/macos_os.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ fn dylib_filename(base: str) -> str { ret "lib" + base + ".dylib"; }
133133

134134
fn get_exe_path() -> option::t<fs::path> {
135135
// FIXME: This doesn't handle the case where the buffer is too small
136+
// FIXME: path "strings" will likely need fixing...
136137
let bufsize = 1023u32;
137-
let path = str::unsafe_from_bytes(vec::init_elt(bufsize as uint, 0u8));
138+
let path = str::from_bytes(vec::init_elt(bufsize as uint, 0u8));
138139
ret str::as_buf(path, { |path_buf|
139140
if mac_libc::_NSGetExecutablePath(path_buf,
140141
ptr::mut_addr_of(bufsize)) == 0i32 {

src/libstd/run_program.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn read_all(rd: io::reader) -> str {
216216
let buf = "";
217217
while !rd.eof() {
218218
let bytes = rd.read_bytes(4096u);
219-
buf += str::unsafe_from_bytes(bytes);
219+
buf += str::from_bytes(bytes);
220220
}
221221
ret buf;
222222
}
@@ -347,7 +347,7 @@ mod tests {
347347
let buf = "";
348348
while !reader.eof() {
349349
let bytes = reader.read_bytes(4096u);
350-
buf += str::unsafe_from_bytes(bytes);
350+
buf += str::from_bytes(bytes);
351351
}
352352
os::fclose(file);
353353
ret buf;

src/libstd/uvtmp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn test_http() {
131131
unsafe {
132132
log(error, len);
133133
let buf = vec::unsafe::from_buf(buf, len as uint);
134-
let str = str::unsafe_from_bytes(buf);
134+
let str = str::from_bytes(buf);
135135
#error("read something");
136136
io::println(str);
137137
}
@@ -146,4 +146,4 @@ fn test_http() {
146146
}
147147
join_thread(thread);
148148
delete_thread(thread);
149-
}
149+
}

src/libstd/win32_os.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ fn getcwd() -> str { ret rustrt::rust_getcwd(); }
113113

114114
fn get_exe_path() -> option::t<fs::path> {
115115
// FIXME: This doesn't handle the case where the buffer is too small
116+
// FIXME: path "strings" will likely need fixing...
116117
let bufsize = 1023u;
117-
let path = str::unsafe_from_bytes(vec::init_elt(bufsize, 0u8));
118+
let path = str::from_bytes(vec::init_elt(bufsize, 0u8));
118119
ret str::as_buf(path, { |path_buf|
119120
if kernel32::GetModuleFileNameA(0u, path_buf,
120121
bufsize as u32) != 0u32 {

src/test/bench/task-perf-word-count-generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import comm::recv;
3232
import comm::send;
3333

3434
fn map(&&filename: [u8], emit: map_reduce::putter<[u8], int>) {
35-
let f = io::file_reader(str::unsafe_from_bytes(filename));
35+
let f = io::file_reader(str::from_bytes(filename));
3636

3737
while true {
3838
alt read_word(f) {

src/test/run-pass/hashmap-memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ mod map_reduce {
8181
mapper_done { num_mappers -= 1; }
8282
find_reducer(k, cc) {
8383
let c;
84-
alt reducers.find(str::unsafe_from_bytes(k)) {
84+
alt reducers.find(str::from_bytes(k)) {
8585
some(_c) { c = _c; }
8686
none { c = 0; }
8787
}

0 commit comments

Comments
 (0)