Skip to content

Commit 2a293ed

Browse files
committed
Convert *u8 native string users to *c_char
1 parent e5dea87 commit 2a293ed

File tree

11 files changed

+231
-224
lines changed

11 files changed

+231
-224
lines changed

src/libcore/os.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export as_c_charp, fill_charp_buf;
3838
native mod rustrt {
3939
fn rust_env_pairs() -> [str];
4040
fn rust_getcwd() -> str;
41-
fn rust_path_is_dir(path: *u8) -> c_int;
42-
fn rust_path_exists(path: *u8) -> c_int;
41+
fn rust_path_is_dir(path: *libc::c_char) -> c_int;
42+
fn rust_path_exists(path: *libc::c_char) -> c_int;
4343
fn rust_list_files(path: str) -> [str];
4444
fn rust_process_wait(handle: c_int) -> c_int;
4545
}
@@ -58,7 +58,7 @@ fn env() -> [(str,str)] {
5858
const tmpbuf_sz : uint = 1000u;
5959

6060
fn as_c_charp<T>(s: str, f: fn(*c_char) -> T) -> T {
61-
str::as_buf(s) {|b| f(b as *c_char) }
61+
str::as_c_str(s) {|b| f(b as *c_char) }
6262
}
6363

6464
fn fill_charp_buf(f: fn(*mutable c_char, size_t) -> bool)
@@ -386,14 +386,14 @@ fn homedir() -> option<path> {
386386

387387
#[doc = "Indicates whether a path represents a directory"]
388388
fn path_is_dir(p: path) -> bool {
389-
str::as_buf(p) {|buf|
389+
str::as_c_str(p) {|buf|
390390
rustrt::rust_path_is_dir(buf) != 0 as c_int
391391
}
392392
}
393393

394394
#[doc = "Indicates whether a path exists"]
395395
fn path_exists(p: path) -> bool {
396-
str::as_buf(p) {|buf|
396+
str::as_c_str(p) {|buf|
397397
rustrt::rust_path_exists(buf) != 0 as c_int
398398
}
399399
}

src/libcore/run.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export waitpid;
1111

1212
#[abi = "cdecl"]
1313
native mod rustrt {
14-
fn rust_run_program(argv: **u8, envp: *c_void, dir: *u8,
14+
fn rust_run_program(argv: **libc::c_char, envp: *c_void,
15+
dir: *libc::c_char,
1516
in_fd: c_int, out_fd: c_int, err_fd: c_int)
1617
-> pid_t;
1718
}
@@ -77,13 +78,13 @@ fn spawn_process(prog: str, args: [str],
7778
}
7879

7980
fn with_argv<T>(prog: str, args: [str],
80-
cb: fn(**u8) -> T) -> T unsafe {
81-
let mut argptrs = str::as_buf(prog) {|b| [b] };
81+
cb: fn(**libc::c_char) -> T) -> T unsafe {
82+
let mut argptrs = str::as_c_str(prog) {|b| [b] };
8283
let mut tmps = [];
8384
for arg in args {
8485
let t = @arg;
8586
tmps += [t];
86-
argptrs += str::as_buf(*t) {|b| [b] };
87+
argptrs += str::as_c_str(*t) {|b| [b] };
8788
}
8889
argptrs += [ptr::null()];
8990
vec::as_buf(argptrs, cb)
@@ -104,7 +105,7 @@ fn with_envp<T>(env: option<[(str,str)]>,
104105
for (k,v) in es {
105106
let t = @(#fmt("%s=%s", k, v));
106107
vec::push(tmps, t);
107-
ptrs += str::as_buf(*t) {|b| [b]};
108+
ptrs += str::as_c_str(*t) {|b| [b]};
108109
}
109110
ptrs += [ptr::null()];
110111
vec::as_buf(ptrs) { |p| cb(::unsafe::reinterpret_cast(p)) }
@@ -140,9 +141,9 @@ fn with_envp<T>(env: option<[(str,str)]>,
140141
}
141142

142143
fn with_dirp<T>(d: option<str>,
143-
cb: fn(*u8) -> T) -> T unsafe {
144+
cb: fn(*libc::c_char) -> T) -> T unsafe {
144145
alt d {
145-
some(dir) { str::as_buf(dir, cb) }
146+
some(dir) { str::as_c_str(dir, cb) }
146147
none { cb(ptr::null()) }
147148
}
148149
}

src/rustc/back/link.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ enum output_type {
2424
}
2525

2626
fn llvm_err(sess: session, msg: str) -> ! unsafe {
27-
let buf = llvm::LLVMRustGetLastError();
28-
if buf == ptr::null() {
27+
let cstr = llvm::LLVMRustGetLastError();
28+
if cstr == ptr::null() {
2929
sess.fatal(msg);
30-
} else { sess.fatal(msg + ": " + str::from_buf(buf)); }
30+
} else { sess.fatal(msg + ": " + str::from_c_str(cstr)); }
3131
}
3232

3333
fn load_intrinsics_bc(sess: session) -> option<ModuleRef> {
@@ -40,7 +40,7 @@ fn load_intrinsics_bc(sess: session) -> option<ModuleRef> {
4040
ret option::none;
4141
}
4242
};
43-
let membuf = str::as_buf(path, {|buf|
43+
let membuf = str::as_c_str(path, {|buf|
4444
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
4545
});
4646
if membuf as uint == 0u {
@@ -63,7 +63,7 @@ fn load_intrinsics_ll(sess: session) -> ModuleRef {
6363
option::some(path) { path }
6464
option::none { sess.fatal("couldn't find intrinsics.ll") }
6565
};
66-
let llintrinsicsmod = str::as_buf(path, { |buf|
66+
let llintrinsicsmod = str::as_c_str(path, { |buf|
6767
llvm::LLVMRustParseAssemblyFile(buf)
6868
});
6969
if llintrinsicsmod as uint == 0u {
@@ -131,15 +131,15 @@ mod write {
131131
output_type_bitcode {
132132
if opts.optimize != 0u {
133133
let filename = mk_intermediate_name(output, "no-opt.bc");
134-
str::as_buf(filename,
134+
str::as_c_str(filename,
135135
{|buf|
136136
llvm::LLVMWriteBitcodeToFile(llmod, buf)
137137
});
138138
}
139139
}
140140
_ {
141141
let filename = mk_intermediate_name(output, "bc");
142-
str::as_buf(filename,
142+
str::as_c_str(filename,
143143
{|buf|
144144
llvm::LLVMWriteBitcodeToFile(llmod, buf)
145145
});
@@ -215,18 +215,18 @@ mod write {
215215

216216
let filename = mk_intermediate_name(output, "opt.bc");
217217
llvm::LLVMRunPassManager(pm.llpm, llmod);
218-
str::as_buf(filename,
218+
str::as_c_str(filename,
219219
{|buf|
220220
llvm::LLVMWriteBitcodeToFile(llmod, buf)
221221
});
222222
pm = mk_pass_manager();
223223
// Save the assembly file if -S is used
224224

225225
if opts.output_type == output_type_assembly {
226-
let _: () = str::as_buf(
226+
let _: () = str::as_c_str(
227227
sess.targ_cfg.target_strs.target_triple,
228228
{|buf_t|
229-
str::as_buf(output, {|buf_o|
229+
str::as_c_str(output, {|buf_o|
230230
llvm::LLVMRustWriteOutputFile(
231231
pm.llpm,
232232
llmod,
@@ -243,10 +243,10 @@ mod write {
243243
if opts.output_type == output_type_object ||
244244
opts.output_type == output_type_exe {
245245
let _: () =
246-
str::as_buf(
246+
str::as_c_str(
247247
sess.targ_cfg.target_strs.target_triple,
248248
{|buf_t|
249-
str::as_buf(output, {|buf_o|
249+
str::as_c_str(output, {|buf_o|
250250
llvm::LLVMRustWriteOutputFile(
251251
pm.llpm,
252252
llmod,
@@ -261,10 +261,10 @@ mod write {
261261
// type corresponding to the '-c' or '-S' flag used
262262

263263
let _: () =
264-
str::as_buf(
264+
str::as_c_str(
265265
sess.targ_cfg.target_strs.target_triple,
266266
{|buf_t|
267-
str::as_buf(output, {|buf_o|
267+
str::as_c_str(output, {|buf_o|
268268
llvm::LLVMRustWriteOutputFile(
269269
pm.llpm,
270270
llmod,
@@ -283,13 +283,13 @@ mod write {
283283

284284
if opts.output_type == output_type_llvm_assembly {
285285
// Given options "-S --emit-llvm": output LLVM assembly
286-
str::as_buf(output, {|buf_o|
286+
str::as_c_str(output, {|buf_o|
287287
llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o)});
288288
} else {
289289
// If only a bitcode file is asked for by using the '--emit-llvm'
290290
// flag, then output it here
291291
llvm::LLVMRunPassManager(pm.llpm, llmod);
292-
str::as_buf(output,
292+
str::as_c_str(output,
293293
{|buf| llvm::LLVMWriteBitcodeToFile(llmod, buf) });
294294
}
295295

0 commit comments

Comments
 (0)