.with_c_str() is a replacement for the old .as_c_str(), to avoid
unnecessary boilerplate.
Replace all usages of .to_c_str().with_ref() with .with_c_str().
33 files changed:
/// Add a line to history
pub unsafe fn add_history(line: &str) -> bool {
/// Add a line to history
pub unsafe fn add_history(line: &str) -> bool {
- do line.to_c_str().with_ref |buf| {
+ do line.with_c_str |buf| {
rustrt::linenoiseHistoryAdd(buf) == 1 as c_int
}
}
rustrt::linenoiseHistoryAdd(buf) == 1 as c_int
}
}
/// Save line history to a file
pub unsafe fn save_history(file: &str) -> bool {
/// Save line history to a file
pub unsafe fn save_history(file: &str) -> bool {
- do file.to_c_str().with_ref |buf| {
+ do file.with_c_str |buf| {
rustrt::linenoiseHistorySave(buf) == 1 as c_int
}
}
/// Load line history from a file
pub unsafe fn load_history(file: &str) -> bool {
rustrt::linenoiseHistorySave(buf) == 1 as c_int
}
}
/// Load line history from a file
pub unsafe fn load_history(file: &str) -> bool {
- do file.to_c_str().with_ref |buf| {
+ do file.with_c_str |buf| {
rustrt::linenoiseHistoryLoad(buf) == 1 as c_int
}
}
/// Print out a prompt and then wait for input and return it
pub unsafe fn read(prompt: &str) -> Option<~str> {
rustrt::linenoiseHistoryLoad(buf) == 1 as c_int
}
}
/// Print out a prompt and then wait for input and return it
pub unsafe fn read(prompt: &str) -> Option<~str> {
- do prompt.to_c_str().with_ref |buf| {
+ do prompt.with_c_str |buf| {
let line = rustrt::linenoise(buf);
if line.is_null() { None }
let line = rustrt::linenoise(buf);
if line.is_null() { None }
unsafe {
do cb(str::raw::from_c_str(line)) |suggestion| {
unsafe {
do cb(str::raw::from_c_str(line)) |suggestion| {
- do suggestion.to_c_str().with_ref |buf| {
+ do suggestion.with_c_str |buf| {
rustrt::linenoiseAddCompletion(completions, buf);
}
}
rustrt::linenoiseAddCompletion(completions, buf);
}
}
OptLevel: c_int,
EnableSegmentedStacks: bool) {
unsafe {
OptLevel: c_int,
EnableSegmentedStacks: bool) {
unsafe {
- do Triple.to_c_str().with_ref |Triple| {
- do Cpu.to_c_str().with_ref |Cpu| {
- do Feature.to_c_str().with_ref |Feature| {
- do Output.to_c_str().with_ref |Output| {
+ do Triple.with_c_str |Triple| {
+ do Cpu.with_c_str |Cpu| {
+ do Feature.with_c_str |Feature| {
+ do Output.with_c_str |Output| {
let result = llvm::LLVMRustWriteOutputFile(
PM,
M,
let result = llvm::LLVMRustWriteOutputFile(
PM,
M,
debug!("linking: %s", path);
debug!("linking: %s", path);
- do path.to_c_str().with_ref |buf_t| {
+ do path.with_c_str |buf_t| {
if !llvm::LLVMRustLoadCrate(manager, buf_t) {
llvm_err(sess, ~"Could not link");
}
if !llvm::LLVMRustLoadCrate(manager, buf_t) {
llvm_err(sess, ~"Could not link");
}
// Next, we need to get a handle on the _rust_main function by
// looking up it's corresponding ValueRef and then requesting that
// the execution engine compiles the function.
// Next, we need to get a handle on the _rust_main function by
// looking up it's corresponding ValueRef and then requesting that
// the execution engine compiles the function.
- let fun = do "_rust_main".to_c_str().with_ref |entry| {
+ let fun = do "_rust_main".with_c_str |entry| {
llvm::LLVMGetNamedFunction(m, entry)
};
if fun.is_null() {
llvm::LLVMGetNamedFunction(m, entry)
};
if fun.is_null() {
output_type_bitcode => {
if opts.optimize != session::No {
let filename = output.with_filetype("no-opt.bc");
output_type_bitcode => {
if opts.optimize != session::No {
let filename = output.with_filetype("no-opt.bc");
- do filename.to_c_str().with_ref |buf| {
+ do filename.with_c_str |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf);
}
}
}
_ => {
let filename = output.with_filetype("bc");
llvm::LLVMWriteBitcodeToFile(llmod, buf);
}
}
}
_ => {
let filename = output.with_filetype("bc");
- do filename.to_c_str().with_ref |buf| {
+ do filename.with_c_str |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf);
}
}
llvm::LLVMWriteBitcodeToFile(llmod, buf);
}
}
// Always output the bitcode file with --save-temps
let filename = output.with_filetype("opt.bc");
// Always output the bitcode file with --save-temps
let filename = output.with_filetype("opt.bc");
- do filename.to_c_str().with_ref |buf| {
+ do filename.with_c_str |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf)
};
// Save the assembly file if -S is used
llvm::LLVMWriteBitcodeToFile(llmod, buf)
};
// Save the assembly file if -S is used
if output_type == output_type_llvm_assembly {
// Given options "-S --emit-llvm": output LLVM assembly
if output_type == output_type_llvm_assembly {
// Given options "-S --emit-llvm": output LLVM assembly
- do output.to_c_str().with_ref |buf_o| {
+ do output.with_c_str |buf_o| {
llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o);
}
} else {
// If only a bitcode file is asked for by using the
// '--emit-llvm' flag, then output it here
llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o);
}
} else {
// If only a bitcode file is asked for by using the
// '--emit-llvm' flag, then output it here
- do output.to_c_str().with_ref |buf| {
+ do output.with_c_str |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf);
}
}
llvm::LLVMWriteBitcodeToFile(llmod, buf);
}
}
}
pub fn create_pass(name:&str) -> Option<PassRef> {
}
pub fn create_pass(name:&str) -> Option<PassRef> {
- do name.to_c_str().with_ref |s| {
+ do name.with_c_str |s| {
unsafe {
let p = llvm::LLVMCreatePass(s);
if p.is_null() {
unsafe {
let p = llvm::LLVMCreatePass(s);
if p.is_null() {
}
pub fn mk_target_data(string_rep: &str) -> TargetData {
}
pub fn mk_target_data(string_rep: &str) -> TargetData {
- let lltd = do string_rep.to_c_str().with_ref |buf| {
+ let lltd = do string_rep.with_c_str |buf| {
unsafe { llvm::LLVMCreateTargetData(buf) }
};
unsafe { llvm::LLVMCreateTargetData(buf) }
};
fn get_metadata_section(os: os,
filename: &Path) -> Option<@~[u8]> {
unsafe {
fn get_metadata_section(os: os,
filename: &Path) -> Option<@~[u8]> {
unsafe {
- let mb = do filename.to_c_str().with_ref |buf| {
+ let mb = do filename.with_c_str |buf| {
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
};
if mb as int == 0 { return option::None::<@~[u8]>; }
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
};
if mb as int == 0 { return option::None::<@~[u8]>; }
ast::asm_intel => lib::llvm::AD_Intel
};
ast::asm_intel => lib::llvm::AD_Intel
};
- let r = do ia.asm.to_c_str().with_ref |a| {
- do constraints.to_c_str().with_ref |c| {
+ let r = do ia.asm.with_c_str |a| {
+ do constraints.with_c_str |c| {
InlineAsmCall(bcx, a, c, inputs, output, ia.volatile, ia.alignstack, dialect)
}
};
InlineAsmCall(bcx, a, c, inputs, output, ia.volatile, ia.alignstack, dialect)
}
};
}
pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv, ty: Type) -> ValueRef {
}
pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv, ty: Type) -> ValueRef {
- let llfn: ValueRef = do name.to_c_str().with_ref |buf| {
+ let llfn: ValueRef = do name.with_c_str |buf| {
unsafe {
llvm::LLVMGetOrInsertFunction(llmod, buf, ty.to_ref())
}
unsafe {
llvm::LLVMGetOrInsertFunction(llmod, buf, ty.to_ref())
}
- let c = do name.to_c_str().with_ref |buf| {
+ let c = do name.with_c_str |buf| {
llvm::LLVMAddGlobal(llmod, ty.to_ref(), buf)
};
externs.insert(name, c);
llvm::LLVMAddGlobal(llmod, ty.to_ref(), buf)
};
externs.insert(name, c);
// Structural comparison: a rather involved form of glue.
pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) {
if cx.sess.opts.save_temps {
// Structural comparison: a rather involved form of glue.
pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) {
if cx.sess.opts.save_temps {
- do s.to_c_str().with_ref |buf| {
+ do s.with_c_str |buf| {
unsafe {
llvm::LLVMSetValueName(v, buf)
}
unsafe {
llvm::LLVMSetValueName(v, buf)
}
opt_node_info: Option<NodeInfo>)
-> @mut Block {
unsafe {
opt_node_info: Option<NodeInfo>)
-> @mut Block {
unsafe {
- let llbb = do name.to_c_str().with_ref |buf| {
+ let llbb = do name.with_c_str |buf| {
llvm::LLVMAppendBasicBlockInContext(cx.ccx.llcx, cx.llfn, buf)
};
let bcx = @mut Block::new(llbb,
llvm::LLVMAppendBasicBlockInContext(cx.ccx.llcx, cx.llfn, buf)
};
let bcx = @mut Block::new(llbb,
pub fn mk_staticallocas_basic_block(llfn: ValueRef) -> BasicBlockRef {
unsafe {
let cx = task_llcx();
pub fn mk_staticallocas_basic_block(llfn: ValueRef) -> BasicBlockRef {
unsafe {
let cx = task_llcx();
- do "static_allocas".to_c_str().with_ref | buf| {
+ do "static_allocas".with_c_str | buf| {
llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)
}
}
llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)
}
}
pub fn mk_return_basic_block(llfn: ValueRef) -> BasicBlockRef {
unsafe {
let cx = task_llcx();
pub fn mk_return_basic_block(llfn: ValueRef) -> BasicBlockRef {
unsafe {
let cx = task_llcx();
- do "return".to_c_str().with_ref |buf| {
+ do "return".with_c_str |buf| {
llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)
}
}
llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)
}
}
};
decl_cdecl_fn(ccx.llmod, main_name, llfty)
};
};
decl_cdecl_fn(ccx.llmod, main_name, llfty)
};
- let llbb = do "top".to_c_str().with_ref |buf| {
+ let llbb = do "top".with_c_str |buf| {
unsafe {
llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf)
}
unsafe {
llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf)
}
llvm::LLVMPositionBuilderAtEnd(bld, llbb);
let crate_map = ccx.crate_map;
llvm::LLVMPositionBuilderAtEnd(bld, llbb);
let crate_map = ccx.crate_map;
- let opaque_crate_map = do "crate_map".to_c_str().with_ref |buf| {
+ let opaque_crate_map = do "crate_map".with_c_str |buf| {
llvm::LLVMBuildPointerCast(bld, crate_map, Type::i8p().to_ref(), buf)
};
llvm::LLVMBuildPointerCast(bld, crate_map, Type::i8p().to_ref(), buf)
};
- let opaque_rust_main = do "rust_main".to_c_str().with_ref |buf| {
+ let opaque_rust_main = do "rust_main".with_c_str |buf| {
llvm::LLVMBuildPointerCast(bld, rust_main, Type::i8p().to_ref(), buf)
};
llvm::LLVMBuildPointerCast(bld, rust_main, Type::i8p().to_ref(), buf)
};
unsafe {
let llty = llvm::LLVMTypeOf(v);
unsafe {
let llty = llvm::LLVMTypeOf(v);
- let g = do sym.to_c_str().with_ref |buf| {
+ let g = do sym.with_c_str |buf| {
llvm::LLVMAddGlobal(ccx.llmod, llty, buf)
};
llvm::LLVMAddGlobal(ccx.llmod, llty, buf)
};
match (attr::first_attr_value_str_by_name(i.attrs, "link_section")) {
Some(sect) => unsafe {
match (attr::first_attr_value_str_by_name(i.attrs, "link_section")) {
Some(sect) => unsafe {
- do sect.to_c_str().with_ref |buf| {
+ do sect.with_c_str |buf| {
llvm::LLVMSetSection(v, buf);
}
},
llvm::LLVMSetSection(v, buf);
}
},
}
ast::foreign_item_static(*) => {
let ident = token::ident_to_str(&ni.ident);
}
ast::foreign_item_static(*) => {
let ident = token::ident_to_str(&ni.ident);
- let g = do ident.to_c_str().with_ref |buf| {
+ let g = do ident.with_c_str |buf| {
unsafe {
let ty = type_of(ccx, ty);
llvm::LLVMAddGlobal(ccx.llmod, ty.to_ref(), buf)
unsafe {
let ty = type_of(ccx, ty);
llvm::LLVMAddGlobal(ccx.llmod, ty.to_ref(), buf)
let s = mangle_exported_name(ccx, p, ty::mk_int()).to_managed();
let disr_val = vi[i].disr_val;
note_unique_llvm_symbol(ccx, s);
let s = mangle_exported_name(ccx, p, ty::mk_int()).to_managed();
let disr_val = vi[i].disr_val;
note_unique_llvm_symbol(ccx, s);
- let discrim_gvar = do s.to_c_str().with_ref |buf| {
+ let discrim_gvar = do s.with_c_str |buf| {
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf)
}
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf)
}
}
let gc_metadata_name = ~"_gc_module_metadata_" + llmod_id;
}
let gc_metadata_name = ~"_gc_module_metadata_" + llmod_id;
- let gc_metadata = do gc_metadata_name.to_c_str().with_ref |buf| {
+ let gc_metadata = do gc_metadata_name.with_c_str |buf| {
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
}
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
}
pub fn create_module_map(ccx: &mut CrateContext) -> ValueRef {
let elttype = Type::struct_([ccx.int_type, ccx.int_type], false);
let maptype = Type::array(&elttype, (ccx.module_data.len() + 1) as u64);
pub fn create_module_map(ccx: &mut CrateContext) -> ValueRef {
let elttype = Type::struct_([ccx.int_type, ccx.int_type], false);
let maptype = Type::array(&elttype, (ccx.module_data.len() + 1) as u64);
- let map = do "_rust_mod_map".to_c_str().with_ref |buf| {
+ let map = do "_rust_mod_map".with_c_str |buf| {
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf)
}
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf)
}
let sym_name = ~"_rust_crate_map_" + mapname;
let arrtype = Type::array(&int_type, n_subcrates as u64);
let maptype = Type::struct_([Type::i32(), Type::i8p(), int_type, arrtype], false);
let sym_name = ~"_rust_crate_map_" + mapname;
let arrtype = Type::array(&int_type, n_subcrates as u64);
let maptype = Type::struct_([Type::i32(), Type::i8p(), int_type, arrtype], false);
- let map = do sym_name.to_c_str().with_ref |buf| {
+ let map = do sym_name.with_c_str |buf| {
unsafe {
llvm::LLVMAddGlobal(llmod, maptype.to_ref(), buf)
}
unsafe {
llvm::LLVMAddGlobal(llmod, maptype.to_ref(), buf)
}
cdata.name,
cstore::get_crate_vers(cstore, i),
cstore::get_crate_hash(cstore, i));
cdata.name,
cstore::get_crate_vers(cstore, i),
cstore::get_crate_hash(cstore, i));
- let cr = do nm.to_c_str().with_ref |buf| {
+ let cr = do nm.with_c_str |buf| {
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf)
}
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf)
}
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
let llmeta = C_bytes(encoder::encode_metadata(encode_parms, crate));
let llconst = C_struct([llmeta]);
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
let llmeta = C_bytes(encoder::encode_metadata(encode_parms, crate));
let llconst = C_struct([llmeta]);
- let mut llglobal = do "rust_metadata".to_c_str().with_ref |buf| {
+ let mut llglobal = do "rust_metadata".with_c_str |buf| {
unsafe {
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst).to_ref(), buf)
}
};
unsafe {
llvm::LLVMSetInitializer(llglobal, llconst);
unsafe {
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst).to_ref(), buf)
}
};
unsafe {
llvm::LLVMSetInitializer(llglobal, llconst);
- do cx.sess.targ_cfg.target_strs.meta_sect_name.to_c_str().with_ref |buf| {
+ do cx.sess.targ_cfg.target_strs.meta_sect_name.with_c_str |buf| {
llvm::LLVMSetSection(llglobal, buf)
};
lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage);
let t_ptr_i8 = Type::i8p();
llglobal = llvm::LLVMConstBitCast(llglobal, t_ptr_i8.to_ref());
llvm::LLVMSetSection(llglobal, buf)
};
lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage);
let t_ptr_i8 = Type::i8p();
llglobal = llvm::LLVMConstBitCast(llglobal, t_ptr_i8.to_ref());
- let llvm_used = do "llvm.used".to_c_str().with_ref |buf| {
+ let llvm_used = do "llvm.used".with_c_str |buf| {
llvm::LLVMAddGlobal(cx.llmod, Type::array(&t_ptr_i8, 1).to_ref(), buf)
};
lib::llvm::SetLinkage(llvm_used, lib::llvm::AppendingLinkage);
llvm::LLVMAddGlobal(cx.llmod, Type::array(&t_ptr_i8, 1).to_ref(), buf)
};
lib::llvm::SetLinkage(llvm_used, lib::llvm::AppendingLinkage);
internal: bool)
-> ValueRef {
unsafe {
internal: bool)
-> ValueRef {
unsafe {
- let llglobal = do name.to_c_str().with_ref |buf| {
+ let llglobal = do name.with_c_str |buf| {
llvm::LLVMAddGlobal(ccx.llmod, val_ty(llval).to_ref(), buf)
};
llvm::LLVMSetInitializer(llglobal, llval);
llvm::LLVMAddGlobal(ccx.llmod, val_ty(llval).to_ref(), buf)
};
llvm::LLVMSetInitializer(llglobal, llval);
if name.is_empty() {
llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(), noname())
} else {
if name.is_empty() {
llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(), noname())
} else {
- do name.to_c_str().with_ref |c| {
+ do name.with_c_str |c| {
llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(), c)
}
}
llvm::LLVMBuildAlloca(self.llbuilder, ty.to_ref(), c)
}
}
let sanitized = text.replace("$", "");
let comment_text = fmt!("# %s", sanitized.replace("\n", "\n\t# "));
self.count_insn("inlineasm");
let sanitized = text.replace("$", "");
let comment_text = fmt!("# %s", sanitized.replace("\n", "\n\t# "));
self.count_insn("inlineasm");
- let asm = do comment_text.to_c_str().with_ref |c| {
+ let asm = do comment_text.with_c_str |c| {
unsafe {
llvm::LLVMConstInlineAsm(Type::func([], &Type::void()).to_ref(),
c, noname(), False, False)
unsafe {
llvm::LLVMConstInlineAsm(Type::func([], &Type::void()).to_ref(),
c, noname(), False, False)
let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(self.llbuilder);
let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB);
let M: ModuleRef = llvm::LLVMGetGlobalParent(FN);
let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(self.llbuilder);
let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB);
let M: ModuleRef = llvm::LLVMGetGlobalParent(FN);
- let T: ValueRef = do "llvm.trap".to_c_str().with_ref |buf| {
+ let T: ValueRef = do "llvm.trap".with_c_str |buf| {
llvm::LLVMGetNamedFunction(M, buf)
};
assert!((T as int != 0));
llvm::LLVMGetNamedFunction(M, buf)
};
assert!((T as int != 0));
pub fn C_floating(s: &str, t: Type) -> ValueRef {
unsafe {
pub fn C_floating(s: &str, t: Type) -> ValueRef {
unsafe {
- do s.to_c_str().with_ref |buf| {
+ do s.with_c_str |buf| {
llvm::LLVMConstRealOfString(t.to_ref(), buf)
}
}
llvm::LLVMConstRealOfString(t.to_ref(), buf)
}
}
- let sc = do s.to_c_str().with_ref |buf| {
+ let sc = do s.with_c_str |buf| {
llvm::LLVMConstStringInContext(cx.llcx, buf, s.len() as c_uint, False)
};
let gsym = token::gensym("str");
llvm::LLVMConstStringInContext(cx.llcx, buf, s.len() as c_uint, False)
};
let gsym = token::gensym("str");
- let g = do fmt!("str%u", gsym).to_c_str().with_ref |buf| {
+ let g = do fmt!("str%u", gsym).with_c_str |buf| {
llvm::LLVMAddGlobal(cx.llmod, val_ty(sc).to_ref(), buf)
};
llvm::LLVMSetInitializer(g, sc);
llvm::LLVMAddGlobal(cx.llmod, val_ty(sc).to_ref(), buf)
};
llvm::LLVMSetInitializer(g, sc);
fn const_addr_of(cx: &mut CrateContext, cv: ValueRef) -> ValueRef {
unsafe {
fn const_addr_of(cx: &mut CrateContext, cv: ValueRef) -> ValueRef {
unsafe {
- let gv = do "const".to_c_str().with_ref |name| {
+ let gv = do "const".with_c_str |name| {
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv).to_ref(), name)
};
llvm::LLVMSetInitializer(gv, cv);
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv).to_ref(), name)
};
llvm::LLVMSetInitializer(gv, cv);
ast::expr_vec(ref es, ast::m_imm) => {
let (cv, sz, llunitty) = const_vec(cx, e, *es);
let llty = val_ty(cv);
ast::expr_vec(ref es, ast::m_imm) => {
let (cv, sz, llunitty) = const_vec(cx, e, *es);
let llty = val_ty(cv);
- let gv = do "const".to_c_str().with_ref |name| {
+ let gv = do "const".with_c_str |name| {
llvm::LLVMAddGlobal(cx.llmod, llty.to_ref(), name)
};
llvm::LLVMSetInitializer(gv, cv);
llvm::LLVMAddGlobal(cx.llmod, llty.to_ref(), name)
};
llvm::LLVMSetInitializer(gv, cv);
unsafe {
let llcx = llvm::LLVMContextCreate();
set_task_llcx(llcx);
unsafe {
let llcx = llvm::LLVMContextCreate();
set_task_llcx(llcx);
- let llmod = do name.to_c_str().with_ref |buf| {
+ let llmod = do name.with_c_str |buf| {
llvm::LLVMModuleCreateWithNameInContext(buf, llcx)
};
let data_layout: &str = sess.targ_cfg.target_strs.data_layout;
let targ_triple: &str = sess.targ_cfg.target_strs.target_triple;
llvm::LLVMModuleCreateWithNameInContext(buf, llcx)
};
let data_layout: &str = sess.targ_cfg.target_strs.data_layout;
let targ_triple: &str = sess.targ_cfg.target_strs.target_triple;
- do data_layout.to_c_str().with_ref |buf| {
+ do data_layout.with_c_str |buf| {
llvm::LLVMSetDataLayout(llmod, buf)
};
llvm::LLVMSetDataLayout(llmod, buf)
};
- do targ_triple.to_c_str().with_ref |buf| {
+ do targ_triple.with_c_str |buf| {
llvm::LLVMSetTarget(llmod, buf)
};
let targ_cfg = sess.targ_cfg;
llvm::LLVMSetTarget(llmod, buf)
};
let targ_cfg = sess.targ_cfg;
ccx, modpath, "loglevel");
let global;
unsafe {
ccx, modpath, "loglevel");
let global;
unsafe {
- global = do s.to_c_str().with_ref |buf| {
+ global = do s.with_c_str |buf| {
llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
};
llvm::LLVMSetGlobalConstant(global, False);
llvm::LLVMAddGlobal(ccx.llmod, Type::i32().to_ref(), buf)
};
llvm::LLVMSetGlobalConstant(global, False);
argument_index as c_uint
};
argument_index as c_uint
};
- let arg_metadata = do name.to_c_str().with_ref |name| {
+ let arg_metadata = do name.with_c_str |name| {
unsafe {
llvm::LLVMDIBuilderCreateLocalVariable(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateLocalVariable(
DIB(cx),
- do cx.sess.str_of(ident).to_c_str().with_ref |name| {
- do cx.sess.str_of(ident).to_c_str().with_ref |linkage| {
+ do cx.sess.str_of(ident).with_c_str |name| {
+ do cx.sess.str_of(ident).with_c_str |linkage| {
unsafe {
llvm::LLVMDIBuilderCreateFunction(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateFunction(
DIB(cx),
let work_dir = cx.sess.working_dir.to_str();
let producer = fmt!("rustc version %s", env!("CFG_VERSION"));
let work_dir = cx.sess.working_dir.to_str();
let producer = fmt!("rustc version %s", env!("CFG_VERSION"));
- do crate_name.to_c_str().with_ref |crate_name| {
- do work_dir.to_c_str().with_ref |work_dir| {
- do producer.to_c_str().with_ref |producer| {
- do "".to_c_str().with_ref |flags| {
- do "".to_c_str().with_ref |split_name| {
+ do crate_name.with_c_str |crate_name| {
+ do work_dir.with_c_str |work_dir| {
+ do producer.with_c_str |producer| {
+ do "".with_c_str |flags| {
+ do "".with_c_str |split_name| {
unsafe {
llvm::LLVMDIBuilderCreateCompileUnit(dcx.builder,
DW_LANG_RUST as c_uint, crate_name, work_dir, producer,
unsafe {
llvm::LLVMDIBuilderCreateCompileUnit(dcx.builder,
DW_LANG_RUST as c_uint, crate_name, work_dir, producer,
let type_metadata = type_metadata(cx, variable_type, span);
let scope = scope_metadata(bcx.fcx, node_id, span);
let type_metadata = type_metadata(cx, variable_type, span);
let scope = scope_metadata(bcx.fcx, node_id, span);
- let var_metadata = do name.to_c_str().with_ref |name| {
+ let var_metadata = do name.with_c_str |name| {
unsafe {
llvm::LLVMDIBuilderCreateLocalVariable(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateLocalVariable(
DIB(cx),
- do file_name.to_c_str().with_ref |file_name| {
- do work_dir.to_c_str().with_ref |work_dir| {
+ do file_name.with_c_str |file_name| {
+ do work_dir.with_c_str |work_dir| {
unsafe {
llvm::LLVMDIBuilderCreateFile(DIB(cx), file_name, work_dir)
}
unsafe {
llvm::LLVMDIBuilderCreateFile(DIB(cx), file_name, work_dir)
}
let llvm_type = type_of::type_of(cx, t);
let (size, align) = size_and_align_of(cx, llvm_type);
let llvm_type = type_of::type_of(cx, t);
let (size, align) = size_and_align_of(cx, llvm_type);
- let ty_metadata = do name.to_c_str().with_ref |name| {
+ let ty_metadata = do name.with_c_str |name| {
unsafe {
llvm::LLVMDIBuilderCreateBasicType(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateBasicType(
DIB(cx),
let pointer_llvm_type = type_of::type_of(cx, pointer_type);
let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type);
let name = ty_to_str(cx.tcx, pointer_type);
let pointer_llvm_type = type_of::type_of(cx, pointer_type);
let (pointer_size, pointer_align) = size_and_align_of(cx, pointer_llvm_type);
let name = ty_to_str(cx.tcx, pointer_type);
- let ptr_metadata = do name.to_c_str().with_ref |name| {
+ let ptr_metadata = do name.with_c_str |name| {
unsafe {
llvm::LLVMDIBuilderCreatePointerType(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreatePointerType(
DIB(cx),
let name: &str = cx.sess.str_of(v.name);
let discriminant_value = v.disr_val as c_ulonglong;
let name: &str = cx.sess.str_of(v.name);
let discriminant_value = v.disr_val as c_ulonglong;
- do name.to_c_str().with_ref |name| {
+ do name.with_c_str |name| {
unsafe {
llvm::LLVMDIBuilderCreateEnumerator(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateEnumerator(
DIB(cx),
let loc = span_start(cx, span);
let file_metadata = file_metadata(cx, loc.file.name);
let loc = span_start(cx, span);
let file_metadata = file_metadata(cx, loc.file.name);
- let discriminant_type_metadata = do enum_name.to_c_str().with_ref |enum_name| {
+ let discriminant_type_metadata = do enum_name.with_c_str |enum_name| {
unsafe {
llvm::LLVMDIBuilderCreateEnumerationType(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateEnumerationType(
DIB(cx),
Some(discriminant_type_metadata),
span);
Some(discriminant_type_metadata),
span);
- do "".to_c_str().with_ref |name| {
+ do "".with_c_str |name| {
unsafe {
llvm::LLVMDIBuilderCreateMemberType(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateMemberType(
DIB(cx),
let enum_llvm_type = type_of::type_of(cx, enum_type);
let (enum_type_size, enum_type_align) = size_and_align_of(cx, enum_llvm_type);
let enum_llvm_type = type_of::type_of(cx, enum_type);
let (enum_type_size, enum_type_align) = size_and_align_of(cx, enum_llvm_type);
- return do enum_name.to_c_str().with_ref |enum_name| {
+ return do enum_name.with_c_str |enum_name| {
unsafe {
llvm::LLVMDIBuilderCreateUnionType(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateUnionType(
DIB(cx),
let member_offset = machine::llelement_offset(cx, composite_llvm_type, i);
let member_name: &str = member_names[i];
let member_offset = machine::llelement_offset(cx, composite_llvm_type, i);
let member_name: &str = member_names[i];
- do member_name.to_c_str().with_ref |member_name| {
+ do member_name.with_c_str |member_name| {
unsafe {
llvm::LLVMDIBuilderCreateMemberType(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateMemberType(
DIB(cx),
- return do composite_type_name.to_c_str().with_ref |name| {
+ return do composite_type_name.with_c_str |name| {
unsafe {
llvm::LLVMDIBuilderCreateStructType(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateStructType(
DIB(cx),
debug!("unimplemented_type_metadata: %?", ty::get(t));
let name = ty_to_str(cx.tcx, t);
debug!("unimplemented_type_metadata: %?", ty::get(t));
let name = ty_to_str(cx.tcx, t);
- let metadata = do fmt!("NYI<%s>", name).to_c_str().with_ref |name| {
+ let metadata = do fmt!("NYI<%s>", name).with_c_str |name| {
unsafe {
llvm::LLVMDIBuilderCreateBasicType(
DIB(cx),
unsafe {
llvm::LLVMDIBuilderCreateBasicType(
DIB(cx),
let symbol = csearch::get_symbol(
bcx.ccx().sess.cstore,
did);
let symbol = csearch::get_symbol(
bcx.ccx().sess.cstore,
did);
- let llval = do symbol.to_c_str().with_ref |buf| {
+ let llval = do symbol.with_c_str |buf| {
llvm::LLVMAddGlobal(bcx.ccx().llmod,
llty.to_ref(),
buf)
llvm::LLVMAddGlobal(bcx.ccx().llmod,
llty.to_ref(),
buf)
let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc").to_managed();
note_unique_llvm_symbol(ccx, name);
debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), name);
let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc").to_managed();
note_unique_llvm_symbol(ccx, name);
debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), name);
- let gvar = do name.to_c_str().with_ref |buf| {
+ let gvar = do name.with_c_str |buf| {
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type.to_ref(), buf)
}
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type.to_ref(), buf)
}
let tbl = C_struct(components);
let vtable = ccx.sess.str_of(gensym_name("vtable"));
let tbl = C_struct(components);
let vtable = ccx.sess.str_of(gensym_name("vtable"));
- let vt_gvar = do vtable.to_c_str().with_ref |buf| {
+ let vt_gvar = do vtable.with_c_str |buf| {
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf)
};
llvm::LLVMSetInitializer(vt_gvar, tbl);
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf)
};
llvm::LLVMSetInitializer(vt_gvar, tbl);
pub fn named_struct(name: &str) -> Type {
let ctx = base::task_llcx();
pub fn named_struct(name: &str) -> Type {
let ctx = base::task_llcx();
- ty!(name.to_c_str().with_ref(|s| llvm::LLVMStructCreateNamed(ctx, s)))
+ ty!(name.with_c_str(|s| llvm::LLVMStructCreateNamed(ctx, s)))
}
pub fn empty_struct() -> Type {
}
pub fn empty_struct() -> Type {
- do src.to_c_str().with_ref |src_buf| {
- do dest.to_c_str().with_ref |dest_buf| {
+ do src.with_c_str |src_buf| {
+ do dest.with_c_str |dest_buf| {
libc::link(src_buf, dest_buf) == 0 as libc::c_int &&
libc::chmod(dest_buf, 755) == 0 as libc::c_int
}
libc::link(src_buf, dest_buf) == 0 as libc::c_int &&
libc::chmod(dest_buf, 755) == 0 as libc::c_int
}
/// Unsafe variant of `to_c_str()` that doesn't check for nulls.
unsafe fn to_c_str_unchecked(&self) -> CString;
/// Unsafe variant of `to_c_str()` that doesn't check for nulls.
unsafe fn to_c_str_unchecked(&self) -> CString;
+
+ /// Work with a temporary CString constructed from the receiver.
+ /// The provided `*libc::c_char` will be freed immediately upon return.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// let s = "PATH".with_c_str(|path| libc::getenv(path))
+ /// ~~~
+ ///
+ /// # Failure
+ ///
+ /// Raises the `null_byte` condition if the receiver has an interior null.
+ #[inline]
+ fn with_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
+ self.to_c_str().with_ref(f)
+ }
+
+ /// Unsafe variant of `with_c_str()` that doesn't check for nulls.
+ #[inline]
+ unsafe fn with_c_str_unchecked<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
+ self.to_c_str_unchecked().with_ref(f)
+ }
}
impl<'self> ToCStr for &'self str {
}
impl<'self> ToCStr for &'self str {
}
pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
}
pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
- let f = do path.to_c_str().with_ref |pathbuf| {
- do "rb".to_c_str().with_ref |modebuf| {
+ let f = do path.with_c_str |pathbuf| {
+ do "rb".with_c_str |modebuf| {
unsafe { libc::fopen(pathbuf, modebuf as *libc::c_char) }
}
};
unsafe { libc::fopen(pathbuf, modebuf as *libc::c_char) }
}
};
- do path.to_c_str().with_ref |pathbuf| {
+ do path.with_c_str |pathbuf| {
libc::open(pathbuf, fflags, (S_IRUSR | S_IWUSR) as c_int)
}
};
libc::open(pathbuf, fflags, (S_IRUSR | S_IWUSR) as c_int)
}
};
// FIXME: fileflags // #2004
pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
unsafe {
// FIXME: fileflags // #2004
pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
unsafe {
- let f = do path.to_c_str().with_ref |pathbuf| {
- do "w".to_c_str().with_ref |modebuf| {
+ let f = do path.with_c_str |pathbuf| {
+ do "w".with_c_str |modebuf| {
libc::fopen(pathbuf, modebuf)
}
};
libc::fopen(pathbuf, modebuf)
}
};
pub fn getenv(n: &str) -> Option<~str> {
unsafe {
do with_env_lock {
pub fn getenv(n: &str) -> Option<~str> {
unsafe {
do with_env_lock {
- let s = do n.to_c_str().with_ref |buf| {
+ let s = do n.with_c_str |buf| {
libc::getenv(buf)
};
if s.is_null() {
libc::getenv(buf)
};
if s.is_null() {
pub fn setenv(n: &str, v: &str) {
unsafe {
do with_env_lock {
pub fn setenv(n: &str, v: &str) {
unsafe {
do with_env_lock {
- do n.to_c_str().with_ref |nbuf| {
- do v.to_c_str().with_ref |vbuf| {
+ do n.with_c_str |nbuf| {
+ do v.with_c_str |vbuf| {
libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1);
}
}
libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1);
}
}
fn _unsetenv(n: &str) {
unsafe {
do with_env_lock {
fn _unsetenv(n: &str) {
unsafe {
do with_env_lock {
- do n.to_c_str().with_ref |nbuf| {
+ do n.with_c_str |nbuf| {
libc::funcs::posix01::unistd::unsetenv(nbuf);
}
}
libc::funcs::posix01::unistd::unsetenv(nbuf);
}
}
}
pub fn fdopen(fd: c_int) -> *FILE {
}
pub fn fdopen(fd: c_int) -> *FILE {
- do "r".to_c_str().with_ref |modebuf| {
+ do "r".with_c_str |modebuf| {
unsafe {
libc::fdopen(fd, modebuf)
}
unsafe {
libc::fdopen(fd, modebuf)
}
let mut path = [0 as c_char, .. TMPBUF_SZ];
do path.as_mut_buf |buf, len| {
let mut path = [0 as c_char, .. TMPBUF_SZ];
do path.as_mut_buf |buf, len| {
- let len = do "/proc/self/exe".to_c_str().with_ref |proc_self_buf| {
+ let len = do "/proc/self/exe".with_c_str |proc_self_buf| {
readlink(proc_self_buf, buf, len as size_t) as uint
};
readlink(proc_self_buf, buf, len as size_t) as uint
};
/// Indicates whether a path represents a directory
pub fn path_is_dir(p: &Path) -> bool {
unsafe {
/// Indicates whether a path represents a directory
pub fn path_is_dir(p: &Path) -> bool {
unsafe {
- do p.to_c_str().with_ref |buf| {
+ do p.with_c_str |buf| {
rustrt::rust_path_is_dir(buf) != 0 as c_int
}
}
rustrt::rust_path_is_dir(buf) != 0 as c_int
}
}
/// Indicates whether a path exists
pub fn path_exists(p: &Path) -> bool {
unsafe {
/// Indicates whether a path exists
pub fn path_exists(p: &Path) -> bool {
unsafe {
- do p.to_c_str().with_ref |buf| {
+ do p.with_c_str |buf| {
rustrt::rust_path_exists(buf) != 0 as c_int
}
}
rustrt::rust_path_exists(buf) != 0 as c_int
}
}
#[cfg(unix)]
fn mkdir(p: &Path, mode: c_int) -> bool {
#[cfg(unix)]
fn mkdir(p: &Path, mode: c_int) -> bool {
- do p.to_c_str().with_ref |buf| {
+ do p.with_c_str |buf| {
unsafe {
libc::mkdir(buf, mode as libc::mode_t) == (0 as c_int)
}
unsafe {
libc::mkdir(buf, mode as libc::mode_t) == (0 as c_int)
}
let mut strings = ~[];
debug!("os::list_dir -- BEFORE OPENDIR");
let mut strings = ~[];
debug!("os::list_dir -- BEFORE OPENDIR");
- let dir_ptr = do p.to_c_str().with_ref |buf| {
+ let dir_ptr = do p.with_c_str |buf| {
#[cfg(unix)]
fn rmdir(p: &Path) -> bool {
#[cfg(unix)]
fn rmdir(p: &Path) -> bool {
- do p.to_c_str().with_ref |buf| {
+ do p.with_c_str |buf| {
unsafe {
libc::rmdir(buf) == (0 as c_int)
}
unsafe {
libc::rmdir(buf) == (0 as c_int)
}
#[cfg(unix)]
fn chdir(p: &Path) -> bool {
#[cfg(unix)]
fn chdir(p: &Path) -> bool {
- do p.to_c_str().with_ref |buf| {
+ do p.with_c_str |buf| {
unsafe {
libc::chdir(buf) == (0 as c_int)
}
unsafe {
libc::chdir(buf) == (0 as c_int)
}
#[cfg(unix)]
fn do_copy_file(from: &Path, to: &Path) -> bool {
unsafe {
#[cfg(unix)]
fn do_copy_file(from: &Path, to: &Path) -> bool {
unsafe {
- let istream = do from.to_c_str().with_ref |fromp| {
- do "rb".to_c_str().with_ref |modebuf| {
+ let istream = do from.with_c_str |fromp| {
+ do "rb".with_c_str |modebuf| {
libc::fopen(fromp, modebuf)
}
};
libc::fopen(fromp, modebuf)
}
};
let from_mode = from.get_mode().expect("copy_file: couldn't get permissions \
for source file");
let from_mode = from.get_mode().expect("copy_file: couldn't get permissions \
for source file");
- let ostream = do to.to_c_str().with_ref |top| {
- do "w+b".to_c_str().with_ref |modebuf| {
+ let ostream = do to.with_c_str |top| {
+ do "w+b".with_c_str |modebuf| {
libc::fopen(top, modebuf)
}
};
libc::fopen(top, modebuf)
}
};
fclose(ostream);
// Give the new file the old file's permissions
fclose(ostream);
// Give the new file the old file's permissions
- if do to.to_c_str().with_ref |to_buf| {
+ if do to.with_c_str |to_buf| {
libc::chmod(to_buf, from_mode as libc::mode_t)
} != 0 {
return false; // should be a condition...
libc::chmod(to_buf, from_mode as libc::mode_t)
} != 0 {
return false; // should be a condition...
#[cfg(unix)]
fn unlink(p: &Path) -> bool {
unsafe {
#[cfg(unix)]
fn unlink(p: &Path) -> bool {
unsafe {
- do p.to_c_str().with_ref |buf| {
+ do p.with_c_str |buf| {
libc::unlink(buf) == (0 as c_int)
}
}
libc::unlink(buf) == (0 as c_int)
}
}
}
let mut g = default_glob_t();
}
let mut g = default_glob_t();
- do pattern.to_c_str().with_ref |c_pattern| {
+ do pattern.with_c_str |c_pattern| {
unsafe { libc::glob(c_pattern, 0, ptr::null(), &mut g) }
};
do(|| {
unsafe { libc::glob(c_pattern, 0, ptr::null(), &mut g) }
};
do(|| {
let out = tempdir.push("out.txt");
/* Write the temp input file */
let out = tempdir.push("out.txt");
/* Write the temp input file */
- let ostream = do input.to_c_str().with_ref |fromp| {
- do "w+b".to_c_str().with_ref |modebuf| {
+ let ostream = do input.with_c_str |fromp| {
+ do "w+b".with_c_str |modebuf| {
libc::fopen(fromp, modebuf)
}
};
assert!((ostream as uint != 0u));
let s = ~"hello";
libc::fopen(fromp, modebuf)
}
};
assert!((ostream as uint != 0u));
let s = ~"hello";
- do "hello".to_c_str().with_ref |buf| {
+ do "hello".with_c_str |buf| {
let write_len = libc::fwrite(buf as *c_void,
1u as size_t,
(s.len() + 1u) as size_t,
let write_len = libc::fwrite(buf as *c_void,
1u as size_t,
(s.len() + 1u) as size_t,
remove_file(&path);
let fd = unsafe {
remove_file(&path);
let fd = unsafe {
- let fd = do path.to_c_str().with_ref |path| {
+ let fd = do path.with_c_str |path| {
open(path, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)
};
lseek_(fd, size);
open(path, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)
};
lseek_(fd, size);
- do "x".to_c_str().with_ref |x| {
+ do "x".with_c_str |x| {
assert!(write(fd, x as *c_void, 1) == 1);
}
fd
assert!(write(fd, x as *c_void, 1) == 1);
}
fd
#[cfg(target_os = "win32")]
impl WindowsPath {
pub fn stat(&self) -> Option<libc::stat> {
#[cfg(target_os = "win32")]
impl WindowsPath {
pub fn stat(&self) -> Option<libc::stat> {
- do self.to_c_str().with_ref |buf| {
+ do self.with_c_str |buf| {
let mut st = stat::arch::default_stat();
match unsafe { libc::stat(buf, &mut st) } {
0 => Some(st),
let mut st = stat::arch::default_stat();
match unsafe { libc::stat(buf, &mut st) } {
0 => Some(st),
#[cfg(not(target_os = "win32"))]
impl PosixPath {
pub fn stat(&self) -> Option<libc::stat> {
#[cfg(not(target_os = "win32"))]
impl PosixPath {
pub fn stat(&self) -> Option<libc::stat> {
- do self.to_c_str().with_ref |buf| {
+ do self.with_c_str |buf| {
let mut st = stat::arch::default_stat();
match unsafe { libc::stat(buf as *libc::c_char, &mut st) } {
0 => Some(st),
let mut st = stat::arch::default_stat();
match unsafe { libc::stat(buf as *libc::c_char, &mut st) } {
0 => Some(st),
#[cfg(unix)]
impl PosixPath {
pub fn lstat(&self) -> Option<libc::stat> {
#[cfg(unix)]
impl PosixPath {
pub fn lstat(&self) -> Option<libc::stat> {
- do self.to_c_str().with_ref |buf| {
+ do self.with_c_str |buf| {
let mut st = stat::arch::default_stat();
match unsafe { libc::lstat(buf, &mut st) } {
0 => Some(st),
let mut st = stat::arch::default_stat();
match unsafe { libc::lstat(buf, &mut st) } {
0 => Some(st),
fn test_position() {
use libc::c_char;
fn test_position() {
use libc::c_char;
- do "hello".to_c_str().with_ref |p| {
+ do "hello".with_c_str |p| {
unsafe {
assert!(2u == position(p, |c| *c == 'l' as c_char));
assert!(4u == position(p, |c| *c == 'o' as c_char));
unsafe {
assert!(2u == position(p, |c| *c == 'l' as c_char));
assert!(4u == position(p, |c| *c == 'o' as c_char));
#[test]
fn test_buf_len() {
#[test]
fn test_buf_len() {
- do "hello".to_c_str().with_ref |p0| {
- do "there".to_c_str().with_ref |p1| {
- do "thing".to_c_str().with_ref |p2| {
+ do "hello".with_c_str |p0| {
+ do "there".with_c_str |p1| {
+ do "thing".with_c_str |p2| {
let v = ~[p0, p1, p2, null()];
do v.as_imm_buf |vp, len| {
assert_eq!(unsafe { buf_len(vp) }, 3u);
let v = ~[p0, p1, p2, null()];
do v.as_imm_buf |vp, len| {
assert_eq!(unsafe { buf_len(vp) }, 3u);
match try_take_task_borrow_list() {
None => { // not recording borrows
let msg = "borrowed";
match try_take_task_borrow_list() {
None => { // not recording borrows
let msg = "borrowed";
- do msg.to_c_str().with_ref |msg_p| {
+ do msg.with_c_str |msg_p| {
sys::begin_unwind_(msg_p, file, line);
}
}
sys::begin_unwind_(msg_p, file, line);
}
}
- do msg.to_c_str().with_ref |msg_p| {
+ do msg.with_c_str |msg_p| {
sys::begin_unwind_(msg_p, file, line)
}
}
sys::begin_unwind_(msg_p, file, line)
}
}
let br = borrow_list.pop();
if br.box != a || br.file != file || br.line != line {
let err = fmt!("wrong borrow found, br=%?", br);
let br = borrow_list.pop();
if br.box != a || br.file != file || br.line != line {
let err = fmt!("wrong borrow found, br=%?", br);
- do err.to_c_str().with_ref |msg_p| {
+ do err.with_c_str |msg_p| {
sys::begin_unwind_(msg_p, file, line)
}
}
sys::begin_unwind_(msg_p, file, line)
}
}
let log_spec = os::getenv("RUST_LOG");
match log_spec {
Some(spec) => {
let log_spec = os::getenv("RUST_LOG");
match log_spec {
Some(spec) => {
- do spec.to_c_str().with_ref |buf| {
+ do spec.with_c_str |buf| {
unsafe { rust_update_log_settings(crate_map, buf) }
}
}
unsafe { rust_update_log_settings(crate_map, buf) }
}
}
fn join_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> {
let r = unsafe {
fn join_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> {
let r = unsafe {
- do multi.to_str().to_c_str().with_ref |m_addr| {
+ do multi.to_str().with_c_str |m_addr| {
uvll::udp_set_membership(self.native_handle(), m_addr,
ptr::null(), uvll::UV_JOIN_GROUP)
}
uvll::udp_set_membership(self.native_handle(), m_addr,
ptr::null(), uvll::UV_JOIN_GROUP)
}
fn leave_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> {
let r = unsafe {
fn leave_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> {
let r = unsafe {
- do multi.to_str().to_c_str().with_ref |m_addr| {
+ do multi.to_str().with_c_str |m_addr| {
uvll::udp_set_membership(self.native_handle(), m_addr,
ptr::null(), uvll::UV_LEAVE_GROUP)
}
uvll::udp_set_membership(self.native_handle(), m_addr,
ptr::null(), uvll::UV_LEAVE_GROUP)
}
}
pub unsafe fn malloc_ip4_addr(ip: &str, port: int) -> *sockaddr_in {
}
pub unsafe fn malloc_ip4_addr(ip: &str, port: int) -> *sockaddr_in {
- do ip.to_c_str().with_ref |ip_buf| {
+ do ip.with_c_str |ip_buf| {
rust_uv_ip4_addrp(ip_buf as *u8, port as libc::c_int)
}
}
pub unsafe fn malloc_ip6_addr(ip: &str, port: int) -> *sockaddr_in6 {
rust_uv_ip4_addrp(ip_buf as *u8, port as libc::c_int)
}
}
pub unsafe fn malloc_ip6_addr(ip: &str, port: int) -> *sockaddr_in6 {
- do ip.to_c_str().with_ref |ip_buf| {
+ do ip.with_c_str |ip_buf| {
rust_uv_ip6_addrp(ip_buf as *u8, port as libc::c_int)
}
}
rust_uv_ip6_addrp(ip_buf as *u8, port as libc::c_int)
}
}
do with_envp(env) |envp| {
do with_dirp(dir) |dirp| {
do with_envp(env) |envp| {
do with_dirp(dir) |dirp| {
- do cmd.to_c_str().with_ref |cmdp| {
+ do cmd.with_c_str |cmdp| {
let created = CreateProcessA(ptr::null(), cast::transmute(cmdp),
ptr::mut_null(), ptr::mut_null(), TRUE,
0, envp, dirp, &mut si, &mut pi);
let created = CreateProcessA(ptr::null(), cast::transmute(cmdp),
ptr::mut_null(), ptr::mut_null(), TRUE,
0, envp, dirp, &mut si, &mut pi);
fn with_dirp<T>(d: Option<&Path>, cb: &fn(*libc::c_char) -> T) -> T {
match d {
fn with_dirp<T>(d: Option<&Path>, cb: &fn(*libc::c_char) -> T) -> T {
match d {
- Some(dir) => dir.to_c_str().with_ref(|buf| cb(buf)),
+ Some(dir) => dir.with_c_str(|buf| cb(buf)),
None => cb(ptr::null())
}
}
None => cb(ptr::null())
}
}
impl FailWithCause for ~str {
fn fail_with(cause: ~str, file: &'static str, line: uint) -> ! {
impl FailWithCause for ~str {
fn fail_with(cause: ~str, file: &'static str, line: uint) -> ! {
- do cause.to_c_str().with_ref |msg_buf| {
- do file.to_c_str().with_ref |file_buf| {
+ do cause.with_c_str |msg_buf| {
+ do file.with_c_str |file_buf| {
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
}
}
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
}
}
impl FailWithCause for &'static str {
fn fail_with(cause: &'static str, file: &'static str, line: uint) -> ! {
impl FailWithCause for &'static str {
fn fail_with(cause: &'static str, file: &'static str, line: uint) -> ! {
- do cause.to_c_str().with_ref |msg_buf| {
- do file.to_c_str().with_ref |file_buf| {
+ do cause.with_c_str |msg_buf| {
+ do file.with_c_str |file_buf| {
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
}
}
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
}
}
// T but that feature is still unimplemented
let maybe_symbol_value = do dl::check_for_errors_in {
// T but that feature is still unimplemented
let maybe_symbol_value = do dl::check_for_errors_in {
- do symbol.to_c_str().with_ref |raw_string| {
+ do symbol.with_c_str |raw_string| {
dl::symbol(self.handle, raw_string)
}
};
dl::symbol(self.handle, raw_string)
}
};
use result::*;
pub unsafe fn open_external(filename: &path::Path) -> *libc::c_void {
use result::*;
pub unsafe fn open_external(filename: &path::Path) -> *libc::c_void {
- do filename.to_c_str().with_ref |raw_name| {
+ do filename.with_c_str |raw_name| {
dlopen(raw_name, Lazy as libc::c_int)
}
}
dlopen(raw_name, Lazy as libc::c_int)
}
}
index: size_t, len: size_t) {
let msg = fmt!("index out of bounds: the len is %d but the index is %d",
len as int, index as int);
index: size_t, len: size_t) {
let msg = fmt!("index out of bounds: the len is %d but the index is %d",
len as int, index as int);
- do msg.to_c_str().with_ref |buf| {
+ do msg.with_c_str |buf| {
fail_(buf, file, line);
}
}
fail_(buf, file, line);
}
}
}
fn atol(s: ~str) -> int {
}
fn atol(s: ~str) -> int {
- s.to_c_str().with_ref(|x| unsafe { libc::atol(x as *u8) })
+ s.with_c_str(|x| unsafe { libc::atol(x as *u8) })
}
fn atoll(s: ~str) -> i64 {
}
fn atoll(s: ~str) -> i64 {
- s.to_c_str().with_ref(|x| unsafe { libc::atoll(x as *u8) })
+ s.with_c_str(|x| unsafe { libc::atoll(x as *u8) })
fn strlen(str: ~str) -> uint {
unsafe {
// C string is terminated with a zero
fn strlen(str: ~str) -> uint {
unsafe {
// C string is terminated with a zero
- do str.to_c_str().with_ref |buf| {
+ do str.with_c_str |buf| {
libc::my_strlen(buf as *u8)
}
}
libc::my_strlen(buf as *u8)
}
}