Skip to content

Commit 3102b17

Browse files
committed
std: replace str::as_c_str with std::c_str
1 parent 0512475 commit 3102b17

35 files changed

+509
-268
lines changed

src/libextra/rl.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// FIXME #3921. This is unsafe because linenoise uses global mutable
1212
// state without mutexes.
1313

14-
14+
use std::c_str::ToCStr;
1515
use std::libc::{c_char, c_int};
1616
use std::local_data;
1717
use std::str;
@@ -32,7 +32,7 @@ pub mod rustrt {
3232

3333
/// Add a line to history
3434
pub unsafe fn add_history(line: &str) -> bool {
35-
do line.as_c_str |buf| {
35+
do line.to_c_str().with_ref |buf| {
3636
rustrt::linenoiseHistoryAdd(buf) == 1 as c_int
3737
}
3838
}
@@ -44,21 +44,21 @@ pub unsafe fn set_history_max_len(len: int) -> bool {
4444

4545
/// Save line history to a file
4646
pub unsafe fn save_history(file: &str) -> bool {
47-
do file.as_c_str |buf| {
47+
do file.to_c_str().with_ref |buf| {
4848
rustrt::linenoiseHistorySave(buf) == 1 as c_int
4949
}
5050
}
5151

5252
/// Load line history from a file
5353
pub unsafe fn load_history(file: &str) -> bool {
54-
do file.as_c_str |buf| {
54+
do file.to_c_str().with_ref |buf| {
5555
rustrt::linenoiseHistoryLoad(buf) == 1 as c_int
5656
}
5757
}
5858

5959
/// Print out a prompt and then wait for input and return it
6060
pub unsafe fn read(prompt: &str) -> Option<~str> {
61-
do prompt.as_c_str |buf| {
61+
do prompt.to_c_str().with_ref |buf| {
6262
let line = rustrt::linenoise(buf);
6363

6464
if line.is_null() { None }
@@ -80,7 +80,7 @@ pub unsafe fn complete(cb: CompletionCb) {
8080

8181
unsafe {
8282
do cb(str::raw::from_c_str(line)) |suggestion| {
83-
do suggestion.as_c_str |buf| {
83+
do suggestion.to_c_str().with_ref |buf| {
8484
rustrt::linenoiseAddCompletion(completions, buf);
8585
}
8686
}

src/librustc/back/link.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use middle::trans::common::gensym_name;
2222
use middle::ty;
2323
use util::ppaux;
2424

25+
use std::c_str::ToCStr;
2526
use std::char;
2627
use std::hash::Streaming;
2728
use std::hash;
@@ -76,9 +77,9 @@ pub fn WriteOutputFile(sess: Session,
7677
OptLevel: c_int,
7778
EnableSegmentedStacks: bool) {
7879
unsafe {
79-
do Triple.as_c_str |Triple| {
80-
do Feature.as_c_str |Feature| {
81-
do Output.as_c_str |Output| {
80+
do Triple.to_c_str().with_ref |Triple| {
81+
do Feature.to_c_str().with_ref |Feature| {
82+
do Output.to_c_str().with_ref |Output| {
8283
let result = llvm::LLVMRustWriteOutputFile(
8384
PM,
8485
M,
@@ -105,6 +106,7 @@ pub mod jit {
105106
use lib::llvm::{ModuleRef, ContextRef, ExecutionEngineRef};
106107
use metadata::cstore;
107108

109+
use std::c_str::ToCStr;
108110
use std::cast;
109111
use std::local_data;
110112
use std::unstable::intrinsics;
@@ -146,7 +148,7 @@ pub mod jit {
146148

147149
debug!("linking: %s", path);
148150

149-
do path.as_c_str |buf_t| {
151+
do path.to_c_str().with_ref |buf_t| {
150152
if !llvm::LLVMRustLoadCrate(manager, buf_t) {
151153
llvm_err(sess, ~"Could not link");
152154
}
@@ -165,7 +167,7 @@ pub mod jit {
165167
// Next, we need to get a handle on the _rust_main function by
166168
// looking up it's corresponding ValueRef and then requesting that
167169
// the execution engine compiles the function.
168-
let fun = do "_rust_main".as_c_str |entry| {
170+
let fun = do "_rust_main".to_c_str().with_ref |entry| {
169171
llvm::LLVMGetNamedFunction(m, entry)
170172
};
171173
if fun.is_null() {
@@ -230,6 +232,7 @@ pub mod write {
230232

231233
use back::passes;
232234

235+
use std::c_str::ToCStr;
233236
use std::libc::{c_int, c_uint};
234237
use std::path::Path;
235238
use std::run;
@@ -263,14 +266,14 @@ pub mod write {
263266
output_type_bitcode => {
264267
if opts.optimize != session::No {
265268
let filename = output.with_filetype("no-opt.bc");
266-
do filename.to_str().as_c_str |buf| {
269+
do filename.to_c_str().with_ref |buf| {
267270
llvm::LLVMWriteBitcodeToFile(llmod, buf);
268271
}
269272
}
270273
}
271274
_ => {
272275
let filename = output.with_filetype("bc");
273-
do filename.to_str().as_c_str |buf| {
276+
do filename.to_c_str().with_ref |buf| {
274277
llvm::LLVMWriteBitcodeToFile(llmod, buf);
275278
}
276279
}
@@ -333,7 +336,7 @@ pub mod write {
333336
// Always output the bitcode file with --save-temps
334337

335338
let filename = output.with_filetype("opt.bc");
336-
do filename.to_str().as_c_str |buf| {
339+
do filename.to_c_str().with_ref |buf| {
337340
llvm::LLVMWriteBitcodeToFile(llmod, buf)
338341
};
339342
// Save the assembly file if -S is used
@@ -391,13 +394,13 @@ pub mod write {
391394

392395
if output_type == output_type_llvm_assembly {
393396
// Given options "-S --emit-llvm": output LLVM assembly
394-
do output.to_str().as_c_str |buf_o| {
397+
do output.to_c_str().with_ref |buf_o| {
395398
llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o);
396399
}
397400
} else {
398401
// If only a bitcode file is asked for by using the
399402
// '--emit-llvm' flag, then output it here
400-
do output.to_str().as_c_str |buf| {
403+
do output.to_c_str().with_ref |buf| {
401404
llvm::LLVMWriteBitcodeToFile(llmod, buf);
402405
}
403406
}

src/librustc/back/passes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::c_str::ToCStr;
1112
use std::io;
1213

1314
use driver::session::{OptLevel, No, Less, Aggressive};
@@ -173,7 +174,7 @@ pub fn populate_pass_manager(sess: Session, pm: &mut PassManager, pass_list:&[~s
173174
}
174175

175176
pub fn create_pass(name:&str) -> Option<PassRef> {
176-
do name.as_c_str |s| {
177+
do name.to_c_str().with_ref |s| {
177178
unsafe {
178179
let p = llvm::LLVMCreatePass(s);
179180
if p.is_null() {

src/librustc/lib/llvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
11+
use std::c_str::ToCStr;
1212
use std::hashmap::HashMap;
1313
use std::libc::{c_uint, c_ushort};
1414
use std::option;
@@ -2234,7 +2234,7 @@ pub struct TargetData {
22342234
}
22352235

22362236
pub fn mk_target_data(string_rep: &str) -> TargetData {
2237-
let lltd = do string_rep.as_c_str |buf| {
2237+
let lltd = do string_rep.to_c_str().with_ref |buf| {
22382238
unsafe { llvm::LLVMCreateTargetData(buf) }
22392239
};
22402240

src/librustc/metadata/loader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use syntax::print::pprust;
2424
use syntax::{ast, attr};
2525
use syntax::attr::AttrMetaMethods;
2626

27+
use std::c_str::ToCStr;
2728
use std::cast;
2829
use std::io;
2930
use std::num;
@@ -186,7 +187,7 @@ pub fn metadata_matches(extern_metas: &[@ast::MetaItem],
186187
fn get_metadata_section(os: os,
187188
filename: &Path) -> Option<@~[u8]> {
188189
unsafe {
189-
let mb = do filename.to_str().as_c_str |buf| {
190+
let mb = do filename.to_c_str().with_ref |buf| {
190191
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
191192
};
192193
if mb as int == 0 { return option::None::<@~[u8]>; }

src/librustc/middle/trans/asm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# Translation of inline assembly.
1313
*/
1414

15+
use std::c_str::ToCStr;
1516

1617
use lib;
1718
use middle::trans::build::*;
@@ -122,8 +123,8 @@ pub fn trans_inline_asm(bcx: @mut Block, ia: &ast::inline_asm) -> @mut Block {
122123
ast::asm_intel => lib::llvm::AD_Intel
123124
};
124125

125-
let r = do ia.asm.as_c_str |a| {
126-
do constraints.as_c_str |c| {
126+
let r = do ia.asm.to_c_str().with_ref |a| {
127+
do constraints.to_c_str().with_ref |c| {
127128
InlineAsmCall(bcx, a, c, inputs, output, ia.volatile, ia.alignstack, dialect)
128129
}
129130
};

0 commit comments

Comments
 (0)