提交 d5173b1f 编写于 作者: B Brian Anderson

Use cstrcache in C_str, C_cstr, C_shape.

This fixes up the current leaks.
上级 4e136d1f
......@@ -6395,7 +6395,8 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
task_type: task_type,
builder: BuilderRef_res(llvm::LLVMCreateBuilder()),
shape_cx: shape::mk_ctxt(llmod),
gc_cx: gc::mk_ctxt()};
gc_cx: gc::mk_ctxt(),
cstrcache: cstrcache::mk()};
let cx = new_local_ctxt(ccx);
collect_items(ccx, crate);
collect_tag_ctors(ccx, crate);
......
......@@ -154,7 +154,8 @@
task_type: TypeRef,
builder: BuilderRef_res,
shape_cx: shape::ctxt,
gc_cx: gc::ctxt};
gc_cx: gc::ctxt,
cstrcache: cstrcache::t};
type local_ctxt =
{path: [str],
......@@ -842,10 +843,11 @@ fn C_bool(b: bool) -> ValueRef {
// 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 = llvm::LLVMConstString(str::buf(s), str::byte_len(s), False);
let sc = llvm::LLVMConstString(safe_sbuf(cx, s),
str::byte_len(s), False);
let g =
llvm::LLVMAddGlobal(cx.llmod, val_ty(sc),
str::buf(cx.names.next("str")));
safe_sbuf(cx, cx.names.next("str")));
llvm::LLVMSetInitializer(g, sc);
llvm::LLVMSetGlobalConstant(g, True);
llvm::LLVMSetLinkage(g, lib::llvm::LLVMInternalLinkage as llvm::Linkage);
......@@ -863,10 +865,10 @@ fn C_str(cx: &@crate_ctxt, s: &str) -> ValueRef {
let box =
C_struct([C_int(abi::const_refcount as int), C_int(len + 1u as int),
C_int(len + 1u as int), C_int(0),
llvm::LLVMConstString(str::buf(s), len, False)]);
llvm::LLVMConstString(safe_sbuf(cx, s), len, False)]);
let g =
llvm::LLVMAddGlobal(cx.llmod, val_ty(box),
str::buf(cx.names.next("str")));
safe_sbuf(cx, cx.names.next("str")));
llvm::LLVMSetInitializer(g, box);
llvm::LLVMSetGlobalConstant(g, True);
llvm::LLVMSetLinkage(g, lib::llvm::LLVMInternalLinkage as llvm::Linkage);
......@@ -909,7 +911,7 @@ fn C_shape(ccx: &@crate_ctxt, bytes: &[u8]) -> ValueRef {
let llshape = C_bytes(bytes);
let llglobal =
llvm::LLVMAddGlobal(ccx.llmod, val_ty(llshape),
str::buf(ccx.names.next("shape")));
safe_sbuf(ccx, ccx.names.next("shape")));
llvm::LLVMSetInitializer(llglobal, llshape);
llvm::LLVMSetGlobalConstant(llglobal, True);
llvm::LLVMSetLinkage(llglobal,
......@@ -917,6 +919,10 @@ fn C_shape(ccx: &@crate_ctxt, bytes: &[u8]) -> ValueRef {
ret llvm::LLVMConstPointerCast(llglobal, T_ptr(T_i8()));
}
fn safe_sbuf(ccx: &@crate_ctxt, s: &str) -> str::rustrt::sbuf {
cstrcache::get_cstr(ccx.cstrcache, s)
}
//
// Local Variables:
// mode: rust
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册