Convert *u8 native string users to *c_char

This commit is contained in:
Brian Anderson 2012-03-14 15:10:34 -07:00
parent e5dea87f43
commit 2a293ed8b8
11 changed files with 231 additions and 224 deletions

@ -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: *u8) -> c_int;
fn rust_path_exists(path: *u8) -> c_int;
fn rust_path_is_dir(path: *libc::c_char) -> c_int;
fn rust_path_exists(path: *libc::c_char) -> c_int;
fn rust_list_files(path: str) -> [str];
fn rust_process_wait(handle: c_int) -> c_int;
}
@ -58,7 +58,7 @@ fn env() -> [(str,str)] {
const tmpbuf_sz : uint = 1000u;
fn as_c_charp<T>(s: str, f: fn(*c_char) -> T) -> T {
str::as_buf(s) {|b| f(b as *c_char) }
str::as_c_str(s) {|b| f(b as *c_char) }
}
fn fill_charp_buf(f: fn(*mutable c_char, size_t) -> bool)
@ -386,14 +386,14 @@ fn homedir() -> option<path> {
#[doc = "Indicates whether a path represents a directory"]
fn path_is_dir(p: path) -> bool {
str::as_buf(p) {|buf|
str::as_c_str(p) {|buf|
rustrt::rust_path_is_dir(buf) != 0 as c_int
}
}
#[doc = "Indicates whether a path exists"]
fn path_exists(p: path) -> bool {
str::as_buf(p) {|buf|
str::as_c_str(p) {|buf|
rustrt::rust_path_exists(buf) != 0 as c_int
}
}

@ -11,7 +11,8 @@ export waitpid;
#[abi = "cdecl"]
native mod rustrt {
fn rust_run_program(argv: **u8, envp: *c_void, dir: *u8,
fn rust_run_program(argv: **libc::c_char, envp: *c_void,
dir: *libc::c_char,
in_fd: c_int, out_fd: c_int, err_fd: c_int)
-> pid_t;
}
@ -77,13 +78,13 @@ fn spawn_process(prog: str, args: [str],
}
fn with_argv<T>(prog: str, args: [str],
cb: fn(**u8) -> T) -> T unsafe {
let mut argptrs = str::as_buf(prog) {|b| [b] };
cb: fn(**libc::c_char) -> T) -> T unsafe {
let mut argptrs = str::as_c_str(prog) {|b| [b] };
let mut tmps = [];
for arg in args {
let t = @arg;
tmps += [t];
argptrs += str::as_buf(*t) {|b| [b] };
argptrs += str::as_c_str(*t) {|b| [b] };
}
argptrs += [ptr::null()];
vec::as_buf(argptrs, cb)
@ -104,7 +105,7 @@ fn with_envp<T>(env: option<[(str,str)]>,
for (k,v) in es {
let t = @(#fmt("%s=%s", k, v));
vec::push(tmps, t);
ptrs += str::as_buf(*t) {|b| [b]};
ptrs += str::as_c_str(*t) {|b| [b]};
}
ptrs += [ptr::null()];
vec::as_buf(ptrs) { |p| cb(::unsafe::reinterpret_cast(p)) }
@ -140,9 +141,9 @@ fn with_envp<T>(env: option<[(str,str)]>,
}
fn with_dirp<T>(d: option<str>,
cb: fn(*u8) -> T) -> T unsafe {
cb: fn(*libc::c_char) -> T) -> T unsafe {
alt d {
some(dir) { str::as_buf(dir, cb) }
some(dir) { str::as_c_str(dir, cb) }
none { cb(ptr::null()) }
}
}

@ -24,10 +24,10 @@ enum output_type {
}
fn llvm_err(sess: session, msg: str) -> ! unsafe {
let buf = llvm::LLVMRustGetLastError();
if buf == ptr::null() {
let cstr = llvm::LLVMRustGetLastError();
if cstr == ptr::null() {
sess.fatal(msg);
} else { sess.fatal(msg + ": " + str::from_buf(buf)); }
} else { sess.fatal(msg + ": " + str::from_c_str(cstr)); }
}
fn load_intrinsics_bc(sess: session) -> option<ModuleRef> {
@ -40,7 +40,7 @@ fn load_intrinsics_bc(sess: session) -> option<ModuleRef> {
ret option::none;
}
};
let membuf = str::as_buf(path, {|buf|
let membuf = str::as_c_str(path, {|buf|
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
});
if membuf as uint == 0u {
@ -63,7 +63,7 @@ fn load_intrinsics_ll(sess: session) -> ModuleRef {
option::some(path) { path }
option::none { sess.fatal("couldn't find intrinsics.ll") }
};
let llintrinsicsmod = str::as_buf(path, { |buf|
let llintrinsicsmod = str::as_c_str(path, { |buf|
llvm::LLVMRustParseAssemblyFile(buf)
});
if llintrinsicsmod as uint == 0u {
@ -131,7 +131,7 @@ mod write {
output_type_bitcode {
if opts.optimize != 0u {
let filename = mk_intermediate_name(output, "no-opt.bc");
str::as_buf(filename,
str::as_c_str(filename,
{|buf|
llvm::LLVMWriteBitcodeToFile(llmod, buf)
});
@ -139,7 +139,7 @@ mod write {
}
_ {
let filename = mk_intermediate_name(output, "bc");
str::as_buf(filename,
str::as_c_str(filename,
{|buf|
llvm::LLVMWriteBitcodeToFile(llmod, buf)
});
@ -215,7 +215,7 @@ mod write {
let filename = mk_intermediate_name(output, "opt.bc");
llvm::LLVMRunPassManager(pm.llpm, llmod);
str::as_buf(filename,
str::as_c_str(filename,
{|buf|
llvm::LLVMWriteBitcodeToFile(llmod, buf)
});
@ -223,10 +223,10 @@ mod write {
// Save the assembly file if -S is used
if opts.output_type == output_type_assembly {
let _: () = str::as_buf(
let _: () = str::as_c_str(
sess.targ_cfg.target_strs.target_triple,
{|buf_t|
str::as_buf(output, {|buf_o|
str::as_c_str(output, {|buf_o|
llvm::LLVMRustWriteOutputFile(
pm.llpm,
llmod,
@ -243,10 +243,10 @@ mod write {
if opts.output_type == output_type_object ||
opts.output_type == output_type_exe {
let _: () =
str::as_buf(
str::as_c_str(
sess.targ_cfg.target_strs.target_triple,
{|buf_t|
str::as_buf(output, {|buf_o|
str::as_c_str(output, {|buf_o|
llvm::LLVMRustWriteOutputFile(
pm.llpm,
llmod,
@ -261,10 +261,10 @@ mod write {
// type corresponding to the '-c' or '-S' flag used
let _: () =
str::as_buf(
str::as_c_str(
sess.targ_cfg.target_strs.target_triple,
{|buf_t|
str::as_buf(output, {|buf_o|
str::as_c_str(output, {|buf_o|
llvm::LLVMRustWriteOutputFile(
pm.llpm,
llmod,
@ -283,13 +283,13 @@ mod write {
if opts.output_type == output_type_llvm_assembly {
// Given options "-S --emit-llvm": output LLVM assembly
str::as_buf(output, {|buf_o|
str::as_c_str(output, {|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::LLVMRunPassManager(pm.llpm, llmod);
str::as_buf(output,
str::as_c_str(output,
{|buf| llvm::LLVMWriteBitcodeToFile(llmod, buf) });
}

@ -1,6 +1,6 @@
import std::map::hashmap;
import libc::{c_int, c_uint, c_longlong, c_ulonglong};
import libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
type Opcode = u32;
type Bool = c_uint;
@ -147,28 +147,28 @@ native mod llvm {
fn LLVMContextCreate() -> ContextRef;
fn LLVMGetGlobalContext() -> ContextRef;
fn LLVMContextDispose(C: ContextRef);
fn LLVMGetMDKindIDInContext(C: ContextRef, Name: *u8, SLen: c_uint) ->
fn LLVMGetMDKindIDInContext(C: ContextRef, Name: *c_char, SLen: c_uint) ->
c_uint;
fn LLVMGetMDKindID(Name: *u8, SLen: c_uint) -> c_uint;
fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;
/* Create and destroy modules. */
fn LLVMModuleCreateWithNameInContext(ModuleID: *u8, C: ContextRef) ->
fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char, C: ContextRef) ->
ModuleRef;
fn LLVMDisposeModule(M: ModuleRef);
/** Data layout. See Module::getDataLayout. */
fn LLVMGetDataLayout(M: ModuleRef) -> *u8;
fn LLVMSetDataLayout(M: ModuleRef, Triple: *u8);
fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
/** Target triple. See Module::getTargetTriple. */
fn LLVMGetTarget(M: ModuleRef) -> *u8;
fn LLVMSetTarget(M: ModuleRef, Triple: *u8);
fn LLVMGetTarget(M: ModuleRef) -> *c_char;
fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
/** See Module::dump. */
fn LLVMDumpModule(M: ModuleRef);
/** See Module::setModuleInlineAsm. */
fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *u8);
fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
/** See llvm::LLVMTypeKind::getTypeID. */
@ -252,8 +252,8 @@ native mod llvm {
/* Operations on all values */
fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
fn LLVMGetValueName(Val: ValueRef) -> *u8;
fn LLVMSetValueName(Val: ValueRef, Name: *u8);
fn LLVMGetValueName(Val: ValueRef) -> *c_char;
fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
fn LLVMDumpValue(Val: ValueRef);
fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
fn LLVMHasMetadata(Val: ValueRef) -> c_int;
@ -282,13 +282,13 @@ native mod llvm {
fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
/* Operations on metadata */
fn LLVMMDStringInContext(C: ContextRef, Str: *u8, SLen: c_uint) ->
fn LLVMMDStringInContext(C: ContextRef, Str: *c_char, SLen: c_uint) ->
ValueRef;
fn LLVMMDString(Str: *u8, SLen: c_uint) -> ValueRef;
fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
fn LLVMMDNodeInContext(C: ContextRef, Vals: *ValueRef, Count: c_uint) ->
ValueRef;
fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *u8,
fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
Val: ValueRef);
/* Operations on scalar constants */
@ -296,25 +296,26 @@ native mod llvm {
ValueRef;
// FIXME: radix is actually u8, but our native layer can't handle this
// yet. lucky for us we're little-endian. Small miracles.
fn LLVMConstIntOfString(IntTy: TypeRef, Text: *u8, Radix: c_int) ->
fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: c_int) ->
ValueRef;
fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, Text: *u8, SLen: c_uint,
fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, Text: *c_char,
SLen: c_uint,
Radix: u8) -> ValueRef;
fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
fn LLVMConstRealOfString(RealTy: TypeRef, Text: *u8) -> ValueRef;
fn LLVMConstRealOfStringAndSize(RealTy: TypeRef, Text: *u8,
fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char) -> ValueRef;
fn LLVMConstRealOfStringAndSize(RealTy: TypeRef, Text: *c_char,
SLen: c_uint) -> ValueRef;
fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
/* Operations on composite constants */
fn LLVMConstStringInContext(C: ContextRef, Str: *u8, Length: c_uint,
fn LLVMConstStringInContext(C: ContextRef, Str: *c_char, Length: c_uint,
DontNullTerminate: Bool) -> ValueRef;
fn LLVMConstStructInContext(C: ContextRef, ConstantVals: *ValueRef,
Count: c_uint, Packed: Bool) -> ValueRef;
fn LLVMConstString(Str: *u8, Length: c_uint,
fn LLVMConstString(Str: *c_char, Length: c_uint,
DontNullTerminate: Bool) -> ValueRef;
fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef,
Length: c_uint) -> ValueRef;
@ -416,9 +417,9 @@ native mod llvm {
fn LLVMConstInsertValue(AggConstant: ValueRef,
ElementValueConstant: ValueRef, IdxList: *uint,
NumIdx: c_uint) -> ValueRef;
fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *u8, Constraints: *u8,
HasSideEffects: Bool, IsAlignStack: Bool) ->
ValueRef;
fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
Constraints: *c_char, HasSideEffects: Bool,
IsAlignStack: Bool) -> ValueRef;
fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
@ -428,8 +429,8 @@ native mod llvm {
fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
fn LLVMGetSection(Global: ValueRef) -> *u8;
fn LLVMSetSection(Global: ValueRef, Section: *u8);
fn LLVMGetSection(Global: ValueRef) -> *c_char;
fn LLVMSetSection(Global: ValueRef, Section: *c_char);
fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
@ -437,10 +438,10 @@ native mod llvm {
/* Operations on global variables */
fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *u8) -> ValueRef;
fn LLVMAddGlobalInAddressSpace(M: ModuleRef, Ty: TypeRef, Name: *u8,
fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
fn LLVMAddGlobalInAddressSpace(M: ModuleRef, Ty: TypeRef, Name: *c_char,
AddressSpace: c_uint) -> ValueRef;
fn LLVMGetNamedGlobal(M: ModuleRef, Name: *u8) -> ValueRef;
fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
@ -454,25 +455,25 @@ native mod llvm {
fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
/* Operations on aliases */
fn LLVMAddAlias(M: ModuleRef, Ty: TypeRef, Aliasee: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMAddAlias(M: ModuleRef, Ty: TypeRef, Aliasee: ValueRef,
Name: *c_char) -> ValueRef;
/* Operations on functions */
fn LLVMAddFunction(M: ModuleRef, Name: *u8, FunctionTy: TypeRef) ->
fn LLVMAddFunction(M: ModuleRef, Name: *c_char, FunctionTy: TypeRef) ->
ValueRef;
fn LLVMGetNamedFunction(M: ModuleRef, Name: *u8) -> ValueRef;
fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
fn LLVMDeleteFunction(Fn: ValueRef);
fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *u8, FunctionTy: TypeRef)
-> ValueRef;
fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *c_char,
FunctionTy: TypeRef) -> ValueRef;
fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
fn LLVMGetGC(Fn: ValueRef) -> *u8;
fn LLVMSetGC(Fn: ValueRef, Name: *u8);
fn LLVMGetGC(Fn: ValueRef) -> *c_char;
fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint, HighPA: c_uint);
fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_uint;
fn LLVMRemoveFunctionAttr(Fn: ValueRef, PA: c_uint, HighPA: c_uint);
@ -504,13 +505,13 @@ native mod llvm {
fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
fn LLVMAppendBasicBlockInContext(C: ContextRef, Fn: ValueRef, Name: *u8)
-> BasicBlockRef;
fn LLVMAppendBasicBlockInContext(C: ContextRef, Fn: ValueRef,
Name: *c_char) -> BasicBlockRef;
fn LLVMInsertBasicBlockInContext(C: ContextRef, BB: BasicBlockRef,
Name: *u8) -> BasicBlockRef;
Name: *c_char) -> BasicBlockRef;
fn LLVMAppendBasicBlock(Fn: ValueRef, Name: *u8) -> BasicBlockRef;
fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef, Name: *u8) ->
fn LLVMAppendBasicBlock(Fn: ValueRef, Name: *c_char) -> BasicBlockRef;
fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef, Name: *c_char) ->
BasicBlockRef;
fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
@ -553,7 +554,7 @@ native mod llvm {
fn LLVMClearInsertionPosition(Builder: BuilderRef);
fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef, Instr: ValueRef,
Name: *u8);
Name: *c_char);
fn LLVMDisposeBuilder(Builder: BuilderRef);
/* Metadata */
@ -575,9 +576,9 @@ native mod llvm {
NumDests: c_uint) -> ValueRef;
fn LLVMBuildInvoke(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
NumArgs: c_uint, Then: BasicBlockRef,
Catch: BasicBlockRef, Name: *u8) -> ValueRef;
Catch: BasicBlockRef, Name: *c_char) -> ValueRef;
fn LLVMBuildLandingPad(B: BuilderRef, Ty: TypeRef, PersFn: ValueRef,
NumClauses: c_uint, Name: *u8) -> ValueRef;
NumClauses: c_uint, Name: *c_char) -> ValueRef;
fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
@ -594,169 +595,172 @@ native mod llvm {
fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
/* Arithmetic */
fn LLVMBuildAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildNSWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildNUWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *u8) -> ValueRef;
fn LLVMBuildFAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildNSWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildNUWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *u8) -> ValueRef;
fn LLVMBuildFSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildNSWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildNUWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *u8) -> ValueRef;
fn LLVMBuildFMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildUDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildUDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildExactSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *u8) -> ValueRef;
fn LLVMBuildFDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildURem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildSRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildFRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildShl(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildLShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildAShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildAnd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
fn LLVMBuildOr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8) ->
ValueRef;
fn LLVMBuildXor(B: BuilderRef, LHS: ValueRef, RHS: ValueRef, Name: *u8)
-> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildURem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildSRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildFRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildShl(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildLShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildAShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildAnd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildOr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildXor(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildBinOp(B: BuilderRef, Op: Opcode, LHS: ValueRef, RHS: ValueRef,
Name: *u8) -> ValueRef;
fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *u8) -> ValueRef;
fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *u8) -> ValueRef;
fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *u8) -> ValueRef;
fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *u8) -> ValueRef;
fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
/* Memory */
fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *u8) -> ValueRef;
fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
fn LLVMBuildArrayMalloc(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
Name: *u8) -> ValueRef;
fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
fn LLVMBuildArrayAlloca(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
fn LLVMBuildLoad(B: BuilderRef, PointerVal: ValueRef, Name: *u8) ->
fn LLVMBuildLoad(B: BuilderRef, PointerVal: ValueRef, Name: *c_char) ->
ValueRef;
fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef) ->
ValueRef;
fn LLVMBuildGEP(B: BuilderRef, Pointer: ValueRef, Indices: *ValueRef,
NumIndices: c_uint, Name: *u8) -> ValueRef;
NumIndices: c_uint, Name: *c_char) -> ValueRef;
fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
Indices: *ValueRef, NumIndices: c_uint,
Name: *u8)
Name: *c_char)
-> ValueRef;
fn LLVMBuildStructGEP(B: BuilderRef, Pointer: ValueRef, Idx: c_uint,
Name: *u8) -> ValueRef;
fn LLVMBuildGlobalString(B: BuilderRef, Str: *u8, Name: *u8) ->
Name: *c_char) -> ValueRef;
fn LLVMBuildGlobalString(B: BuilderRef, Str: *c_char, Name: *c_char) ->
ValueRef;
fn LLVMBuildGlobalStringPtr(B: BuilderRef, Str: *u8, Name: *u8) ->
fn LLVMBuildGlobalStringPtr(B: BuilderRef, Str: *c_char, Name: *c_char) ->
ValueRef;
/* Casts */
fn LLVMBuildTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildZExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildSExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFPToUI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFPToSI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildUIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildSIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFPTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFPExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildPtrToInt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildIntToPtr(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildZExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildSExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildTruncOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
DestTy: TypeRef, Name: *u8) -> ValueRef;
DestTy: TypeRef, Name: *c_char) -> ValueRef;
fn LLVMBuildPointerCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildIntCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildFPCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
/* Comparisons */
fn LLVMBuildICmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
RHS: ValueRef, Name: *u8) -> ValueRef;
RHS: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildFCmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
RHS: ValueRef, Name: *u8) -> ValueRef;
RHS: ValueRef, Name: *c_char) -> ValueRef;
/* Miscellaneous instructions */
fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *u8) -> ValueRef;
fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
fn LLVMBuildCall(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
NumArgs: c_uint, Name: *u8) -> ValueRef;
NumArgs: c_uint, Name: *c_char) -> ValueRef;
fn LLVMBuildSelect(B: BuilderRef, If: ValueRef, Then: ValueRef,
Else: ValueRef, Name: *u8) -> ValueRef;
fn LLVMBuildVAArg(B: BuilderRef, list: ValueRef, Ty: TypeRef, Name: *u8)
Else: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildVAArg(B: BuilderRef, list: ValueRef, Ty: TypeRef,
Name: *c_char)
-> ValueRef;
fn LLVMBuildExtractElement(B: BuilderRef, VecVal: ValueRef,
Index: ValueRef, Name: *u8) -> ValueRef;
Index: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildInsertElement(B: BuilderRef, VecVal: ValueRef,
EltVal: ValueRef, Index: ValueRef, Name: *u8)
EltVal: ValueRef, Index: ValueRef,
Name: *c_char)
-> ValueRef;
fn LLVMBuildShuffleVector(B: BuilderRef, V1: ValueRef, V2: ValueRef,
Mask: ValueRef, Name: *u8) -> ValueRef;
Mask: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildExtractValue(B: BuilderRef, AggVal: ValueRef, Index: c_uint,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
fn LLVMBuildInsertValue(B: BuilderRef, AggVal: ValueRef, EltVal: ValueRef,
Index: c_uint, Name: *u8) -> ValueRef;
Index: c_uint, Name: *c_char) -> ValueRef;
fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *u8) -> ValueRef;
fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *u8) ->
fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char) ->
ValueRef;
fn LLVMBuildPtrDiff(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *u8) -> ValueRef;
Name: *c_char) -> ValueRef;
/* Selected entries from the downcasts. */
fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
/** Writes a module to the specified path. Returns 0 on success. */
fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *u8) -> c_int;
fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
/** Creates target data from a target layout string. */
fn LLVMCreateTargetData(StringRep: *u8) -> TargetDataRef;
fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
/** Adds the target data to the given pass manager. The pass manager
references the target data only weakly. */
fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
@ -856,38 +860,40 @@ native mod llvm {
/** Moves the section iterator to point to the next section. */
fn LLVMMoveToNextSection(SI: SectionIteratorRef);
/** Returns the current section name. */
fn LLVMGetSectionName(SI: SectionIteratorRef) -> *u8;
fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
/** Returns the current section size. */
fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
/** Returns the current section contents as a string buffer. */
fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *u8;
fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
/** Reads the given file and returns it as a memory buffer. Use
LLVMDisposeMemoryBuffer() to get rid of it. */
fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *u8) ->
fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char) ->
MemoryBufferRef;
/* FIXME: The FileType is an enum.*/
fn LLVMRustWriteOutputFile(PM: PassManagerRef, M: ModuleRef, Triple: *u8,
Output: *u8, FileType: c_int, OptLevel: c_int,
fn LLVMRustWriteOutputFile(PM: PassManagerRef, M: ModuleRef,
Triple: *c_char,
Output: *c_char, FileType: c_int,
OptLevel: c_int,
EnableSegmentedStacks: bool);
/** Returns a string describing the last error caused by an LLVMRust*
call. */
fn LLVMRustGetLastError() -> *u8;
fn LLVMRustGetLastError() -> *c_char;
/** Parses the bitcode in the given memory buffer. */
fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;
/** Parses LLVM asm in the given file */
fn LLVMRustParseAssemblyFile(Filename: *u8) -> ModuleRef;
fn LLVMRustParseAssemblyFile(Filename: *c_char) -> ModuleRef;
/** FiXME: Hacky adaptor for lack of c_ulonglong in FFI: */
fn LLVMRustConstInt(IntTy: TypeRef, N_hi: c_uint, N_lo: c_uint,
SignExtend: Bool) -> ValueRef;
fn LLVMRustAddPrintModulePass(PM: PassManagerRef, M: ModuleRef,
Output: *u8);
Output: *c_char);
/** Turn on LLVM pass-timing. */
fn LLVMRustEnableTimePasses();
@ -895,7 +901,7 @@ native mod llvm {
/** Print the pass timings since static dtors aren't picking them up. */
fn LLVMRustPrintPassTimings();
fn LLVMStructCreateNamed(C: ContextRef, Name: *u8) -> TypeRef;
fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
fn LLVMStructSetBody(StructTy: TypeRef, ElementTypes: *TypeRef,
ElementCount: c_uint, Packed: Bool);
@ -1058,7 +1064,7 @@ type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
fn mk_target_data(string_rep: str) -> target_data {
let lltd =
str::as_buf(string_rep, {|buf| llvm::LLVMCreateTargetData(buf) });
str::as_c_str(string_rep, {|buf| llvm::LLVMCreateTargetData(buf) });
ret {lltd: lltd, dtor: @target_data_res(lltd)};
}

@ -205,7 +205,7 @@ fn find_library_crate_aux(sess: session::session,
fn get_metadata_section(sess: session::session,
filename: str) -> option<@[u8]> unsafe {
let mb = str::as_buf(filename, {|buf|
let mb = str::as_c_str(filename, {|buf|
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
});
if mb as int == 0 { ret option::none::<@[u8]>; }
@ -216,13 +216,13 @@ fn get_metadata_section(sess: session::session,
let si = mk_section_iter(of.llof);
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
let name_buf = llvm::LLVMGetSectionName(si.llsi);
let name = unsafe { str::from_buf(name_buf) };
let name = unsafe { str::from_c_str(name_buf) };
if str::eq(name, sess.targ_cfg.target_strs.meta_sect_name) {
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
unsafe {
let cvbuf: *u8 = unsafe::reinterpret_cast(cbuf);
ret option::some::<@[u8]>(@vec::unsafe::from_buf(cvbuf, csz));
ret some(@vec::unsafe::from_buf(cvbuf, csz));
}
}
llvm::LLVMMoveToNextSection(si.llsi);

@ -166,7 +166,7 @@ fn log_fn_time(ccx: @crate_ctxt, name: str, start: time::timeval,
fn decl_fn(llmod: ModuleRef, name: str, cc: lib::llvm::CallConv,
llty: TypeRef) -> ValueRef {
let llfn: ValueRef = str::as_buf(name, {|buf|
let llfn: ValueRef = str::as_c_str(name, {|buf|
llvm::LLVMGetOrInsertFunction(llmod, buf, llty)
});
lib::llvm::SetFunctionCallConv(llfn, cc);
@ -198,7 +198,7 @@ fn get_extern_fn(externs: hashmap<str, ValueRef>, llmod: ModuleRef, name: str,
fn get_extern_const(externs: hashmap<str, ValueRef>, llmod: ModuleRef,
name: str, ty: TypeRef) -> ValueRef {
if externs.contains_key(name) { ret externs.get(name); }
let c = str::as_buf(name, {|buf| llvm::LLVMAddGlobal(llmod, ty, buf) });
let c = str::as_c_str(name, {|buf| llvm::LLVMAddGlobal(llmod, ty, buf) });
externs.insert(name, c);
ret c;
}
@ -698,7 +698,7 @@ fn declare_tydesc(ccx: @crate_ctxt, t: ty::t, ty_params: [uint])
name = mangle_internal_name_by_type_only(ccx, t, "tydesc");
name = sanitize(name);
} else { name = mangle_internal_name_by_seq(ccx, "tydesc"); }
let gvar = str::as_buf(name, {|buf|
let gvar = str::as_c_str(name, {|buf|
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type, buf)
});
let info =
@ -1028,7 +1028,7 @@ fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef, t: ty::t) -> block {
// Structural comparison: a rather involved form of glue.
fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: str) {
if cx.sess.opts.save_temps {
let _: () = str::as_buf(s, {|buf| llvm::LLVMSetValueName(v, buf) });
let _: () = str::as_c_str(s, {|buf| llvm::LLVMSetValueName(v, buf) });
}
}
@ -2306,7 +2306,7 @@ fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
// It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate);
let sym = csearch::get_symbol(ccx.sess.cstore, vid);
let gvar = str::as_buf(sym, {|buf|
let gvar = str::as_c_str(sym, {|buf|
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
});
lib::llvm::SetLinkage(gvar, lib::llvm::ExternalLinkage);
@ -3407,7 +3407,7 @@ fn trans_log(lvl: @ast::expr, bcx: block, e: @ast::expr) -> block {
} else {
let s = link::mangle_internal_name_by_path_and_seq(
ccx, modpath, "loglevel");
let global = str::as_buf(s, {|buf|
let global = str::as_c_str(s, {|buf|
llvm::LLVMAddGlobal(ccx.llmod, T_i32(), buf)
});
llvm::LLVMSetGlobalConstant(global, False);
@ -3669,7 +3669,7 @@ fn new_block(cx: fn_ctxt, parent: block_parent, kind: block_kind,
if cx.ccx.sess.opts.save_temps || cx.ccx.sess.opts.debuginfo {
s = cx.ccx.names(name);
}
let llbb: BasicBlockRef = str::as_buf(s, {|buf|
let llbb: BasicBlockRef = str::as_c_str(s, {|buf|
llvm::LLVMAppendBasicBlock(cx.llfn, buf)
});
let bcx = @{llbb: llbb,
@ -3892,7 +3892,7 @@ fn alloc_local(cx: block, local: @ast::local) -> block {
let {bcx, val} = alloc_ty(cx, t);
if cx.sess().opts.debuginfo {
option::may(simple_name) {|name|
str::as_buf(name, {|buf|
str::as_c_str(name, {|buf|
llvm::LLVMSetValueName(val, buf)
});
}
@ -3928,15 +3928,15 @@ fn mk_standard_basic_blocks(llfn: ValueRef) ->
dt: BasicBlockRef,
da: BasicBlockRef,
rt: BasicBlockRef} {
ret {sa: str::as_buf("static_allocas", {|buf|
ret {sa: str::as_c_str("static_allocas", {|buf|
llvm::LLVMAppendBasicBlock(llfn, buf) }),
ca: str::as_buf("load_env", {|buf|
ca: str::as_c_str("load_env", {|buf|
llvm::LLVMAppendBasicBlock(llfn, buf) }),
dt: str::as_buf("derived_tydescs", {|buf|
dt: str::as_c_str("derived_tydescs", {|buf|
llvm::LLVMAppendBasicBlock(llfn, buf) }),
da: str::as_buf("dynamic_allocas", {|buf|
da: str::as_c_str("dynamic_allocas", {|buf|
llvm::LLVMAppendBasicBlock(llfn, buf) }),
rt: str::as_buf("return", {|buf|
rt: str::as_c_str("return", {|buf|
llvm::LLVMAppendBasicBlock(llfn, buf) })};
}
@ -4629,7 +4629,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
fn main_name() -> str { ret "main"; }
let llfty = T_fn([ccx.int_type, ccx.int_type], ccx.int_type);
let llfn = decl_cdecl_fn(ccx.llmod, main_name(), llfty);
let llbb = str::as_buf("top", {|buf|
let llbb = str::as_c_str("top", {|buf|
llvm::LLVMAppendBasicBlock(llfn, buf)
});
let bld = *ccx.builder;
@ -4637,7 +4637,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
let crate_map = ccx.crate_map;
let start_ty = T_fn([val_ty(rust_main), ccx.int_type, ccx.int_type,
val_ty(crate_map)], ccx.int_type);
let start = str::as_buf("rust_start", {|buf|
let start = str::as_c_str("rust_start", {|buf|
llvm::LLVMAddGlobal(ccx.llmod, start_ty, buf)
});
let args = [rust_main, llvm::LLVMGetParam(llfn, 0 as c_uint),
@ -4687,7 +4687,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
ast::item_const(_, _) {
let typ = ty::node_id_to_type(ccx.tcx, i.id);
let s = mangle_exported_name(ccx, my_path, typ);
let g = str::as_buf(s, {|buf|
let g = str::as_c_str(s, {|buf|
llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, typ), buf)
});
ccx.item_symbols.insert(i.id, s);
@ -4772,7 +4772,7 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item) {
path_name("discrim")];
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
let disr_val = vi[i].disr_val;
let discrim_gvar = str::as_buf(s, {|buf|
let discrim_gvar = str::as_c_str(s, {|buf|
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
});
llvm::LLVMSetInitializer(discrim_gvar, C_int(ccx, disr_val));
@ -4876,7 +4876,7 @@ fn trap(bcx: block) {
fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
let elttype = T_struct([ccx.int_type, ccx.int_type]);
let maptype = T_array(elttype, ccx.module_data.size() + 1u);
let map = str::as_buf("_rust_mod_map", {|buf|
let map = str::as_c_str("_rust_mod_map", {|buf|
llvm::LLVMAddGlobal(ccx.llmod, maptype, buf)
});
lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
@ -4904,7 +4904,7 @@ fn decl_crate_map(sess: session::session, mapname: str,
let sym_name = "_rust_crate_map_" + mapname;
let arrtype = T_array(int_type, n_subcrates as uint);
let maptype = T_struct([int_type, arrtype]);
let map = str::as_buf(sym_name, {|buf|
let map = str::as_c_str(sym_name, {|buf|
llvm::LLVMAddGlobal(llmod, maptype, buf)
});
lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage);
@ -4918,7 +4918,7 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
let cstore = ccx.sess.cstore;
while cstore::have_crate_data(cstore, i) {
let nm = "_rust_crate_map_" + cstore::get_crate_data(cstore, i).name;
let cr = str::as_buf(nm, {|buf|
let cr = str::as_c_str(nm, {|buf|
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
});
subcrates += [p2i(ccx, cr)];
@ -4934,18 +4934,18 @@ fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
if !cx.sess.building_library { ret; }
let llmeta = C_bytes(metadata::encoder::encode_metadata(cx, crate));
let llconst = C_struct([llmeta]);
let llglobal = str::as_buf("rust_metadata", {|buf|
let llglobal = str::as_c_str("rust_metadata", {|buf|
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst), buf)
});
llvm::LLVMSetInitializer(llglobal, llconst);
str::as_buf(cx.sess.targ_cfg.target_strs.meta_sect_name, {|buf|
str::as_c_str(cx.sess.targ_cfg.target_strs.meta_sect_name, {|buf|
llvm::LLVMSetSection(llglobal, buf)
});
lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage);
let t_ptr_i8 = T_ptr(T_i8());
llglobal = llvm::LLVMConstBitCast(llglobal, t_ptr_i8);
let llvm_used = str::as_buf("llvm.used", {|buf|
let llvm_used = str::as_c_str("llvm.used", {|buf|
llvm::LLVMAddGlobal(cx.llmod, T_array(t_ptr_i8, 1u), buf)
});
lib::llvm::SetLinkage(llvm_used, lib::llvm::AppendingLinkage);
@ -4974,17 +4974,17 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
let llmod_id = link_meta.name + ".rc";
let llmod = str::as_buf(llmod_id, {|buf|
let llmod = str::as_c_str(llmod_id, {|buf|
llvm::LLVMModuleCreateWithNameInContext
(buf, llvm::LLVMGetGlobalContext())
});
let data_layout = sess.targ_cfg.target_strs.data_layout;
let targ_triple = sess.targ_cfg.target_strs.target_triple;
let _: () =
str::as_buf(data_layout,
str::as_c_str(data_layout,
{|buf| llvm::LLVMSetDataLayout(llmod, buf) });
let _: () =
str::as_buf(targ_triple,
str::as_c_str(targ_triple,
{|buf| llvm::LLVMSetTarget(llmod, buf) });
let targ_cfg = sess.targ_cfg;
let td = mk_target_data(sess.targ_cfg.target_strs.data_layout);

@ -81,8 +81,8 @@ fn IndirectBr(cx: block, Addr: ValueRef, NumDests: uint) {
}
// This is a really awful way to get a zero-length c-string, but better (and a
// lot more efficient) than doing str::as_buf("", ...) every time.
fn noname() -> *u8 unsafe {
// lot more efficient) than doing str::as_c_str("", ...) every time.
fn noname() -> *libc::c_char unsafe {
const cnull: uint = 0u;
ret unsafe::reinterpret_cast(ptr::addr_of(cnull));
}
@ -359,12 +359,12 @@ fn StructGEP(cx: block, Pointer: ValueRef, Idx: uint) -> ValueRef {
ret llvm::LLVMBuildStructGEP(B(cx), Pointer, Idx as c_uint, noname());
}
fn GlobalString(cx: block, _Str: *u8) -> ValueRef {
fn GlobalString(cx: block, _Str: *libc::c_char) -> ValueRef {
if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_i8())); }
ret llvm::LLVMBuildGlobalString(B(cx), _Str, noname());
}
fn GlobalStringPtr(cx: block, _Str: *u8) -> ValueRef {
fn GlobalStringPtr(cx: block, _Str: *libc::c_char) -> ValueRef {
if cx.unreachable { ret llvm::LLVMGetUndef(T_ptr(T_i8())); }
ret llvm::LLVMBuildGlobalStringPtr(B(cx), _Str, noname());
}
@ -534,8 +534,8 @@ fn add_comment(bcx: block, text: str) {
if (!ccx.sess.opts.no_asm_comments) {
let sanitized = str::replace(text, "$", "");
let comment_text = "; " + sanitized;
let asm = str::as_buf(comment_text, {|c|
str::as_buf("", {|e|
let asm = str::as_c_str(comment_text, {|c|
str::as_c_str("", {|e|
llvm::LLVMConstInlineAsm(T_fn([], T_void()), c, e,
False, False)
})
@ -636,7 +636,7 @@ fn Trap(cx: block) {
let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(b);
let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB);
let M: ModuleRef = llvm::LLVMGetGlobalParent(FN);
let T: ValueRef = str::as_buf("llvm.trap", {|buf|
let T: ValueRef = str::as_c_str("llvm.trap", {|buf|
llvm::LLVMGetNamedFunction(M, buf)
});
assert (T as int != 0);

@ -530,7 +530,7 @@ fn T_struct(elts: [TypeRef]) -> TypeRef unsafe {
fn T_named_struct(name: str) -> TypeRef {
let c = llvm::LLVMGetGlobalContext();
ret str::as_buf(name, {|buf| llvm::LLVMStructCreateNamed(c, buf) });
ret str::as_c_str(name, {|buf| llvm::LLVMStructCreateNamed(c, buf) });
}
fn set_struct_body(t: TypeRef, elts: [TypeRef]) unsafe {
@ -746,7 +746,7 @@ fn C_integral(t: TypeRef, u: u64, sign_extend: Bool) -> ValueRef {
}
fn C_floating(s: str, t: TypeRef) -> ValueRef {
ret str::as_buf(s, {|buf| llvm::LLVMConstRealOfString(t, buf) });
ret str::as_c_str(s, {|buf| llvm::LLVMConstRealOfString(t, buf) });
}
fn C_nil() -> ValueRef {
@ -783,11 +783,11 @@ fn C_u8(i: uint) -> ValueRef { ret C_integral(T_i8(), i as u64, False); }
// This is a 'c-like' raw string, which differs from
// our boxed-and-length-annotated strings.
fn C_cstr(cx: @crate_ctxt, s: str) -> ValueRef {
let sc = str::as_buf(s) {|buf|
let sc = str::as_c_str(s) {|buf|
llvm::LLVMConstString(buf, str::len(s) as c_uint, False)
};
let g =
str::as_buf(cx.names("str"),
str::as_c_str(cx.names("str"),
{|buf| llvm::LLVMAddGlobal(cx.llmod, val_ty(sc), buf) });
llvm::LLVMSetInitializer(g, sc);
llvm::LLVMSetGlobalConstant(g, True);
@ -797,7 +797,7 @@ fn C_cstr(cx: @crate_ctxt, s: str) -> ValueRef {
// Returns a Plain Old LLVM String:
fn C_postr(s: str) -> ValueRef {
ret str::as_buf(s) {|buf|
ret str::as_c_str(s) {|buf|
llvm::LLVMConstString(buf, str::len(s) as c_uint, False)
};
}
@ -833,7 +833,7 @@ fn C_bytes(bytes: [u8]) -> ValueRef unsafe {
fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
let llshape = C_bytes(bytes);
let llglobal = str::as_buf(ccx.names("shape"), {|buf|
let llglobal = str::as_c_str(ccx.names("shape"), {|buf|
llvm::LLVMAddGlobal(ccx.llmod, val_ty(llshape), buf)
});
llvm::LLVMSetInitializer(llglobal, llshape);

@ -46,7 +46,7 @@ const DW_ATE_unsigned: int = 0x07;
const DW_ATE_unsigned_char: int = 0x08;
fn llstr(s: str) -> ValueRef {
str::as_buf(s, {|sbuf|
str::as_c_str(s, {|sbuf|
llvm::LLVMMDString(sbuf, str::len(s) as libc::c_uint)
})
}
@ -74,7 +74,7 @@ fn llnull() -> ValueRef unsafe {
}
fn add_named_metadata(cx: @crate_ctxt, name: str, val: ValueRef) {
str::as_buf(name, {|sbuf|
str::as_c_str(name, {|sbuf|
llvm::LLVMAddNamedMetadataOperand(cx.llmod, sbuf,
val)
})

@ -210,7 +210,7 @@ fn llfn_arg_tys(ft: TypeRef) -> {inputs: [TypeRef], output: TypeRef} {
fn trans_vtable(ccx: @crate_ctxt, id: ast::node_id, name: str,
ptrs: [ValueRef]) {
let tbl = C_struct(ptrs);
let vt_gvar = str::as_buf(name, {|buf|
let vt_gvar = str::as_c_str(name, {|buf|
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl), buf)
});
llvm::LLVMSetInitializer(vt_gvar, tbl);
@ -467,7 +467,7 @@ fn get_static_dict(bcx: block, origin: typeck::dict_origin)
}
let ptrs = C_struct(get_dict_ptrs(bcx, origin).ptrs);
let name = ccx.names("dict");
let gvar = str::as_buf(name, {|buf|
let gvar = str::as_c_str(name, {|buf|
llvm::LLVMAddGlobal(ccx.llmod, val_ty(ptrs), buf)
});
llvm::LLVMSetGlobalConstant(gvar, lib::llvm::True);

@ -79,7 +79,7 @@ fn eq_res_info(a: res_info, b: res_info) -> bool {
fn mk_global(ccx: @crate_ctxt, name: str, llval: ValueRef, internal: bool) ->
ValueRef {
let llglobal =
str::as_buf(name,
str::as_c_str(name,
{|buf|
lib::llvm::llvm::LLVMAddGlobal(ccx.llmod,
val_ty(llval), buf)
@ -270,7 +270,7 @@ fn s_send_tydesc(_tcx: ty_ctxt) -> u8 {
fn mk_ctxt(llmod: ModuleRef) -> ctxt {
let llshapetablesty = trans::common::T_named_struct("shapes");
let llshapetables = str::as_buf("shapes", {|buf|
let llshapetables = str::as_c_str("shapes", {|buf|
lib::llvm::llvm::LLVMAddGlobal(llmod, llshapetablesty, buf)
});