Skip to content

Commit 9847642

Browse files
committed
---
yaml --- r: 24136 b: refs/heads/master c: f41c536 h: refs/heads/master v: v3
1 parent 7e1a5ac commit 9847642

File tree

7 files changed

+70
-18
lines changed

7 files changed

+70
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 267ab11cca722c1c83dcb6df949961390af787c1
2+
refs/heads/master: f41c53667e3464ab324d4484e8601968f9eb313f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/logging.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
#[forbid(deprecated_mode)];
55
#[forbid(deprecated_pattern)];
66

7-
export console_on, console_off;
7+
use cast::transmute;
8+
9+
export console_on, console_off, log_type;
810

911
#[nolink]
1012
extern mod rustrt {
1113
#[legacy_exports];
1214
fn rust_log_console_on();
1315
fn rust_log_console_off();
16+
fn rust_log_str(level: u32, string: *libc::c_char, size: libc::size_t);
1417
}
1518

1619
/// Turns on logging to stdout globally
@@ -27,4 +30,17 @@ fn console_on() {
2730
*/
2831
fn console_off() {
2932
rustrt::rust_log_console_off();
30-
}
33+
}
34+
35+
#[cfg(notest)]
36+
#[lang="log_type"]
37+
pub fn log_type<T>(level: u32, object: &T) {
38+
let bytes = do io::with_bytes_writer() |writer| {
39+
repr::write_repr(writer, object);
40+
};
41+
unsafe {
42+
let len = bytes.len() as libc::size_t;
43+
rustrt::rust_log_str(level, transmute(vec::raw::to_ptr(bytes)), len);
44+
}
45+
}
46+

trunk/src/rt/rust_builtin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,9 @@ rust_call_tydesc_glue(void *root, size_t *tydesc, size_t glue_index) {
952952

953953
// Don't run on the Rust stack!
954954
extern "C" void
955-
rust_log_str(uint32_t level, const char *str) {
955+
rust_log_str(uint32_t level, const char *str, size_t size) {
956956
rust_task *task = rust_get_current_task();
957-
task->sched_loop->get_log().log(task, level, "%s", str);
957+
task->sched_loop->get_log().log(task, level, "%.*s", (int)size, str);
958958
}
959959

960960
//

trunk/src/rustc/middle/lang_items.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ struct LanguageItems {
4646

4747
mut str_eq_fn: Option<def_id>,
4848
mut uniq_str_eq_fn: Option<def_id>,
49-
mut annihilate_fn: Option<def_id>
49+
mut annihilate_fn: Option<def_id>,
50+
mut log_type_fn: Option<def_id>
5051
}
5152

5253
mod LanguageItems {
@@ -76,7 +77,8 @@ mod LanguageItems {
7677

7778
str_eq_fn: None,
7879
uniq_str_eq_fn: None,
79-
annihilate_fn: None
80+
annihilate_fn: None,
81+
log_type_fn: None
8082
}
8183
}
8284
}
@@ -111,6 +113,7 @@ fn LanguageItemCollector(crate: @crate, session: session,
111113
item_refs.insert(~"str_eq", &mut items.str_eq_fn);
112114
item_refs.insert(~"uniq_str_eq", &mut items.uniq_str_eq_fn);
113115
item_refs.insert(~"annihilate", &mut items.annihilate_fn);
116+
item_refs.insert(~"log_type", &mut items.log_type_fn);
114117

115118
LanguageItemCollector {
116119
crate: crate,

trunk/src/rustc/middle/trans/base.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,12 +2005,6 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
20052005
}
20062006
Call(bcx, main_llfn, args);
20072007

2008-
// Call the box annihilator.
2009-
// XXX: Crashes.
2010-
//let did = bcx.tcx().lang_items.annihilate_fn.get();
2011-
//let bcx = callee::trans_rtcall_or_lang_call(bcx, did, ~[],
2012-
// expr::Ignore);
2013-
20142008
build_return(bcx);
20152009
finish_fn(fcx, lltop);
20162010
return llfdecl;

trunk/src/rustc/middle/trans/callee.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ fn trans_fn_ref_with_vtables(
163163
//
164164
// - `bcx`: the current block where the reference to the fn occurs
165165
// - `def_id`: def id of the fn or method item being referenced
166-
// - `ref_id`: node id of the reference to the fn/method
166+
// - `ref_id`: node id of the reference to the fn/method, if applicable.
167+
// This parameter may be zero; but, if so, the resulting value may not
168+
// have the right type, so it must be cast before being used.
167169
// - `type_params`: values for each of the fn/method's type parameters
168170
// - `vtables`: values for each bound on each of the type parameters
169171

@@ -220,7 +222,7 @@ fn trans_fn_ref_with_vtables(
220222
let mut {val, must_cast} =
221223
monomorphize::monomorphic_fn(ccx, def_id, type_params,
222224
vtables, Some(ref_id));
223-
if must_cast {
225+
if must_cast && ref_id != 0 {
224226
// Monotype of the REFERENCE to the function (type params
225227
// are subst'd)
226228
let ref_ty = common::node_id_type(bcx, ref_id);
@@ -290,6 +292,43 @@ fn trans_rtcall_or_lang_call(bcx: block, did: ast::def_id, args: ~[ValueRef],
290292
ArgVals(args), dest, DontAutorefArg);
291293
}
292294

295+
fn trans_rtcall_or_lang_call_with_type_params(bcx: block,
296+
did: ast::def_id,
297+
args: ~[ValueRef],
298+
type_params: ~[ty::t],
299+
dest: expr::Dest) -> block {
300+
let fty;
301+
if did.crate == ast::local_crate {
302+
fty = ty::node_id_to_type(bcx.tcx(), did.node);
303+
} else {
304+
fty = csearch::get_type(bcx.tcx(), did).ty;
305+
}
306+
307+
let rty = ty::ty_fn_ret(fty);
308+
return callee::trans_call_inner(
309+
bcx, None, fty, rty,
310+
|bcx| {
311+
let callee =
312+
trans_fn_ref_with_vtables_to_callee(bcx, did, 0, type_params,
313+
None);
314+
315+
let new_llval;
316+
match callee.data {
317+
Fn(fn_data) => {
318+
let substituted = ty::subst_tps(callee.bcx.tcx(),
319+
type_params, fty);
320+
let mut llfnty = type_of::type_of(callee.bcx.ccx(),
321+
substituted);
322+
llfnty = T_ptr(struct_elt(llfnty, 0));
323+
new_llval = PointerCast(callee.bcx, fn_data.llfn, llfnty);
324+
}
325+
_ => fail
326+
}
327+
Callee { bcx: callee.bcx, data: Fn(FnData { llfn: new_llval }) }
328+
},
329+
ArgVals(args), dest, DontAutorefArg);
330+
}
331+
293332
fn body_contains_ret(body: ast::blk) -> bool {
294333
let cx = {mut found: false};
295334
visit::visit_block(body, cx, visit::mk_vt(@{

trunk/src/rustc/middle/trans/controlflow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ fn trans_log(log_ex: @ast::expr,
190190
191191
// Translate the value to be logged
192192
let val_datum = unpack_datum!(bcx, expr::trans_to_datum(bcx, e));
193-
let tydesc = get_tydesc_simple(ccx, val_datum.ty);
194193
195194
// Call the polymorphic log function
196195
let val = val_datum.to_ref_llval(bcx);
197-
let val = PointerCast(bcx, val, T_ptr(T_i8()));
198-
Call(bcx, ccx.upcalls.log_type, [tydesc, val, level]);
196+
let did = bcx.tcx().lang_items.log_type_fn.get();
197+
let bcx = callee::trans_rtcall_or_lang_call_with_type_params(
198+
bcx, did, ~[level, val], ~[val_datum.ty], expr::Ignore);
199199
bcx
200200
}
201201
}

0 commit comments

Comments
 (0)