Skip to content

Commit

Permalink
core:: Eliminate str::sbuf. Replace with *u8
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Mar 15, 2012
1 parent 3864d6d commit 9e48070
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 145 deletions.
6 changes: 3 additions & 3 deletions src/libcore/os.rs
Expand Up @@ -38,8 +38,8 @@ export as_c_charp, fill_charp_buf;
native mod rustrt {
fn rust_env_pairs() -> [str];
fn rust_getcwd() -> str;
fn rust_path_is_dir(path: str::sbuf) -> c_int;
fn rust_path_exists(path: str::sbuf) -> c_int;
fn rust_path_is_dir(path: *u8) -> c_int;
fn rust_path_exists(path: *u8) -> c_int;
fn rust_list_files(path: str) -> [str];
fn rust_process_wait(handle: c_int) -> c_int;
}
Expand All @@ -66,7 +66,7 @@ fn fill_charp_buf(f: fn(*mutable c_char, size_t) -> bool)
let buf = vec::to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char));
vec::as_mut_buf(buf) { |b|
if f(b, tmpbuf_sz as size_t) {
some(str::from_cstr(b as str::sbuf))
some(str::from_cstr(b as *u8))
} else {
none
}
Expand Down
7 changes: 3 additions & 4 deletions src/libcore/run.rs
@@ -1,6 +1,5 @@
#[doc ="Process spawning"];
import option::{some, none};
import str::sbuf;
import libc::{pid_t, c_void, c_int};

export program;
Expand All @@ -12,7 +11,7 @@ export waitpid;

#[abi = "cdecl"]
native mod rustrt {
fn rust_run_program(argv: *sbuf, envp: *c_void, dir: sbuf,
fn rust_run_program(argv: **u8, envp: *c_void, dir: *u8,
in_fd: c_int, out_fd: c_int, err_fd: c_int)
-> pid_t;
}
Expand Down Expand Up @@ -78,7 +77,7 @@ fn spawn_process(prog: str, args: [str],
}

fn with_argv<T>(prog: str, args: [str],
cb: fn(*sbuf) -> T) -> T unsafe {
cb: fn(**u8) -> T) -> T unsafe {
let mut argptrs = str::as_buf(prog) {|b| [b] };
let mut tmps = [];
for arg in args {
Expand Down Expand Up @@ -141,7 +140,7 @@ fn with_envp<T>(env: option<[(str,str)]>,
}

fn with_dirp<T>(d: option<str>,
cb: fn(sbuf) -> T) -> T unsafe {
cb: fn(*u8) -> T) -> T unsafe {
alt d {
some(dir) { str::as_buf(dir, cb) }
none { cb(ptr::null()) }
Expand Down
10 changes: 3 additions & 7 deletions src/libcore/str.rs
Expand Up @@ -90,7 +90,6 @@ export
char_at,
as_bytes,
as_buf,
sbuf,
reserve,

unsafe;
Expand Down Expand Up @@ -184,7 +183,7 @@ fn from_chars(chs: [char]) -> str {
}

#[doc = "Create a Rust string from a null-terminated C string"]
fn from_cstr(cstr: sbuf) -> str unsafe {
fn from_cstr(cstr: *u8) -> str unsafe {
let mut curr = cstr, i = 0u;
while *curr != 0u8 {
i += 1u;
Expand All @@ -194,7 +193,7 @@ fn from_cstr(cstr: sbuf) -> str unsafe {
}

#[doc = "Create a Rust string from a C string of the given length"]
fn from_cstr_len(cstr: sbuf, len: uint) -> str unsafe {
fn from_cstr_len(cstr: *u8, len: uint) -> str unsafe {
let mut buf: [u8] = [];
vec::reserve(buf, len + 1u);
vec::as_buf(buf) {|b| ptr::memcpy(b, cstr, len); }
Expand Down Expand Up @@ -1248,13 +1247,10 @@ interop.
let s = str::as_buf(\"PATH\", { |path_buf| libc::getenv(path_buf) });
```
"]
fn as_buf<T>(s: str, f: fn(sbuf) -> T) -> T unsafe {
fn as_buf<T>(s: str, f: fn(*u8) -> T) -> T unsafe {
as_bytes(s) { |v| vec::as_buf(v, f) }
}

#[doc = "An unsafe buffer of bytes"]
type sbuf = *u8;

#[doc = "Allocate more memory for a string, up to `nn` + 1 bytes"]
fn reserve(&ss: str, nn: uint) {
rustrt::str_reserve_shared(ss, nn);
Expand Down

0 comments on commit 9e48070

Please sign in to comment.