auto merge of #5159 : brson/rust/rtcall, r=brson

This commit is contained in:
bors 2013-02-28 01:12:38 -08:00
commit b171d0ef7b
11 changed files with 37 additions and 43 deletions

View file

@ -154,7 +154,7 @@ fn debug_mem() -> bool {
#[cfg(notest)]
#[lang="annihilate"]
pub unsafe fn annihilate() {
use rt::rt_free;
use rt::local_free;
use io::WriterUtil;
use io;
use libc;
@ -192,7 +192,7 @@ pub unsafe fn annihilate() {
stats.n_bytes_freed +=
(*((*box).header.type_desc)).size
+ sys::size_of::<BoxRepr>();
rt_free(transmute(box));
local_free(transmute(box));
}
}

View file

@ -36,60 +36,54 @@ pub extern mod rustrt {
unsafe fn rust_upcall_free(ptr: *c_char);
}
#[rt(fail_)]
#[lang="fail_"]
pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
sys::begin_unwind_(expr, file, line);
}
#[rt(fail_bounds_check)]
#[lang="fail_bounds_check"]
pub unsafe fn rt_fail_bounds_check(file: *c_char, line: size_t,
index: size_t, len: size_t) {
pub unsafe fn fail_bounds_check(file: *c_char, line: size_t,
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 str::as_buf(msg) |p, _len| {
rt_fail_(p as *c_char, file, line);
fail_(p as *c_char, file, line);
}
}
pub unsafe fn rt_fail_borrowed() {
pub unsafe fn fail_borrowed() {
let msg = "borrowed";
do str::as_buf(msg) |msg_p, _| {
do str::as_buf("???") |file_p, _| {
rt_fail_(msg_p as *c_char, file_p as *c_char, 0);
fail_(msg_p as *c_char, file_p as *c_char, 0);
}
}
}
// FIXME #4942: Make these signatures agree with exchange_alloc's signatures
#[rt(exchange_malloc)]
#[lang="exchange_malloc"]
pub unsafe fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
transmute(exchange_alloc::malloc(transmute(td), transmute(size)))
}
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
// inside a landing pad may corrupt the state of the exception handler. If a
// problem occurs, call exit instead.
#[rt(exchange_free)]
#[lang="exchange_free"]
pub unsafe fn rt_exchange_free(ptr: *c_char) {
pub unsafe fn exchange_free(ptr: *c_char) {
exchange_alloc::free(transmute(ptr))
}
#[rt(malloc)]
#[lang="malloc"]
pub unsafe fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
return rustrt::rust_upcall_malloc(td, size);
}
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
// inside a landing pad may corrupt the state of the exception handler. If a
// problem occurs, call exit instead.
#[rt(free)]
#[lang="free"]
pub unsafe fn rt_free(ptr: *c_char) {
pub unsafe fn local_free(ptr: *c_char) {
rustrt::rust_upcall_free(ptr);
}
@ -112,7 +106,7 @@ pub unsafe fn return_to_mut(a: *u8) {
pub unsafe fn check_not_borrowed(a: *u8) {
let a: *mut BoxRepr = transmute(a);
if ((*a).header.ref_count & FROZEN_BIT) != 0 {
rt_fail_borrowed();
fail_borrowed();
}
}

View file

@ -1054,7 +1054,7 @@ pub fn compare_values(cx: block,
let scratch_rhs = alloca(cx, val_ty(rhs));
Store(cx, rhs, scratch_rhs);
let did = cx.tcx().lang_items.uniq_str_eq_fn();
let bcx = callee::trans_rtcall_or_lang_call(cx, did,
let bcx = callee::trans_lang_call(cx, did,
~[scratch_lhs,
scratch_rhs],
expr::SaveIn(
@ -1069,7 +1069,7 @@ pub fn compare_values(cx: block,
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
false);
let did = cx.tcx().lang_items.str_eq_fn();
let bcx = callee::trans_rtcall_or_lang_call(cx, did,
let bcx = callee::trans_lang_call(cx, did,
~[lhs, rhs],
expr::SaveIn(
scratch_result.val));

View file

@ -307,7 +307,7 @@ pub fn malloc_raw_dyn(bcx: block,
// Allocate space:
let tydesc = PointerCast(bcx, static_ti.tydesc, T_ptr(T_i8()));
let rval = alloca(bcx, T_ptr(T_i8()));
let bcx = callee::trans_rtcall_or_lang_call(
let bcx = callee::trans_lang_call(
bcx,
langcall,
~[tydesc, size],

View file

@ -332,11 +332,11 @@ pub fn trans_method_call(in_cx: block,
DontAutorefArg)
}
pub fn trans_rtcall_or_lang_call(bcx: block,
did: ast::def_id,
args: &[ValueRef],
dest: expr::Dest)
-> block {
pub fn trans_lang_call(bcx: block,
did: ast::def_id,
args: &[ValueRef],
dest: expr::Dest)
-> block {
let fty = if did.crate == ast::local_crate {
ty::node_id_to_type(bcx.ccx().tcx, did.node)
} else {
@ -349,12 +349,12 @@ pub fn trans_rtcall_or_lang_call(bcx: block,
ArgVals(args), dest, DontAutorefArg);
}
pub fn trans_rtcall_or_lang_call_with_type_params(bcx: block,
did: ast::def_id,
args: &[ValueRef],
type_params: ~[ty::t],
dest: expr::Dest)
-> block {
pub fn trans_lang_call_with_type_params(bcx: block,
did: ast::def_id,
args: &[ValueRef],
type_params: ~[ty::t],
dest: expr::Dest)
-> block {
let fty;
if did.crate == ast::local_crate {
fty = ty::node_id_to_type(bcx.tcx(), did.node);

View file

@ -500,7 +500,7 @@ pub fn make_opaque_cbox_take_glue(
// Allocate memory, update original ptr, and copy existing data
let opaque_tydesc = PointerCast(bcx, tydesc, T_ptr(T_i8()));
let rval = alloca(bcx, T_ptr(T_i8()));
let bcx = callee::trans_rtcall_or_lang_call(
let bcx = callee::trans_lang_call(
bcx,
bcx.tcx().lang_items.exchange_malloc_fn(),
~[opaque_tydesc, sz],

View file

@ -445,7 +445,7 @@ pub fn add_clean_frozen_root(bcx: block, val: ValueRef, t: ty::t) {
do in_scope_cx(bcx) |scope_info| {
scope_info.cleanups.push(
clean_temp(val, |bcx| {
let bcx = callee::trans_rtcall_or_lang_call(
let bcx = callee::trans_lang_call(
bcx,
bcx.tcx().lang_items.return_to_mut_fn(),
~[

View file

@ -216,7 +216,7 @@ pub fn trans_log(log_ex: @ast::expr,
// Call the polymorphic log function
let val = val_datum.to_ref_llval(bcx);
let did = bcx.tcx().lang_items.log_type_fn();
let bcx = callee::trans_rtcall_or_lang_call_with_type_params(
let bcx = callee::trans_lang_call_with_type_params(
bcx, did, ~[level, val], ~[val_datum.ty], expr::Ignore);
bcx
}
@ -384,7 +384,7 @@ fn trans_fail_value(bcx: block,
let V_str = PointerCast(bcx, V_fail_str, T_ptr(T_i8()));
let V_filename = PointerCast(bcx, V_filename, T_ptr(T_i8()));
let args = ~[V_str, V_filename, C_int(ccx, V_line)];
let bcx = callee::trans_rtcall_or_lang_call(
let bcx = callee::trans_lang_call(
bcx, bcx.tcx().lang_items.fail_fn(), args, expr::Ignore);
Unreachable(bcx);
return bcx;
@ -401,7 +401,7 @@ pub fn trans_fail_bounds_check(bcx: block, sp: span,
let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8()));
let args = ~[filename, line, index, len];
let bcx = callee::trans_rtcall_or_lang_call(
let bcx = callee::trans_lang_call(
bcx, bcx.tcx().lang_items.fail_bounds_check_fn(), args, expr::Ignore);
Unreachable(bcx);
return bcx;

View file

@ -544,7 +544,7 @@ pub impl Datum {
// If we need to freeze the box, do that now.
if root_info.freezes {
callee::trans_rtcall_or_lang_call(
callee::trans_lang_call(
bcx,
bcx.tcx().lang_items.borrow_as_imm_fn(),
~[
@ -566,7 +566,7 @@ pub impl Datum {
ByRef => Load(bcx, self.val),
};
callee::trans_rtcall_or_lang_call(
callee::trans_lang_call(
bcx,
bcx.tcx().lang_items.check_not_borrowed_fn(),
~[ PointerCast(bcx, llval, T_ptr(T_i8())) ],

View file

@ -30,7 +30,7 @@ use core::str;
pub fn trans_free(cx: block, v: ValueRef) -> block {
let _icx = cx.insn_ctxt("trans_free");
callee::trans_rtcall_or_lang_call(
callee::trans_lang_call(
cx,
cx.tcx().lang_items.free_fn(),
~[PointerCast(cx, v, T_ptr(T_i8()))],
@ -39,7 +39,7 @@ pub fn trans_free(cx: block, v: ValueRef) -> block {
pub fn trans_exchange_free(cx: block, v: ValueRef) -> block {
let _icx = cx.insn_ctxt("trans_exchange_free");
callee::trans_rtcall_or_lang_call(
callee::trans_lang_call(
cx,
cx.tcx().lang_items.exchange_free_fn(),
~[PointerCast(cx, v, T_ptr(T_i8()))],

View file

@ -306,7 +306,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block,
let llsizeval = C_uint(bcx.ccx(), s.len());
let typ = ty::mk_estr(bcx.tcx(), ty::vstore_uniq);
let lldestval = datum::scratch_datum(bcx, typ, false);
let bcx = callee::trans_rtcall_or_lang_call(
let bcx = callee::trans_lang_call(
bcx,
bcx.tcx().lang_items.strdup_uniq_fn(),
~[ llptrval, llsizeval ],