Skip to content

Commit e54d43b

Browse files
committed
---
yaml --- r: 42995 b: refs/heads/try c: e91040c h: refs/heads/master i: 42993: ae21d8f 42991: 1003ff5 v: v3
1 parent 6822274 commit e54d43b

File tree

8 files changed

+87
-39
lines changed

8 files changed

+87
-39
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: 739e5ba369cfe19da10d7adf1bcfcd14b80f52bb
5+
refs/heads/try: e91040c704aa9ab46fb1c7a10e293fd5f6bfe079
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/mk/tests.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,6 @@ $(3)/test/$$(FT_DRIVER)-$(2).out: \
746746
--logfile tmp/$$(FT_DRIVER)-$(2).log
747747

748748
check-fast-T-$(2)-H-$(3): \
749-
check-stage2-T-$(2)-H-$(3)-rustc \
750-
check-stage2-T-$(2)-H-$(3)-core \
751-
check-stage2-T-$(2)-H-$(3)-std \
752749
$(3)/test/$$(FT_DRIVER)-$(2).out
753750

754751
endef

branches/try/src/librustc/middle/trans/base.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub fn log_fn_time(ccx: @crate_ctxt, +name: ~str, start: time::Timespec,
137137
ccx.stats.fn_times.push({ident: name, time: elapsed});
138138
}
139139

140-
pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
140+
pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv,
141141
llty: TypeRef) -> ValueRef {
142142
let llfn: ValueRef = str::as_c_str(name, |buf| {
143143
unsafe {
@@ -150,7 +150,7 @@ pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
150150
return llfn;
151151
}
152152

153-
pub fn decl_cdecl_fn(llmod: ModuleRef, name: &str, llty: TypeRef)
153+
pub fn decl_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef)
154154
-> ValueRef {
155155
return decl_fn(llmod, name, lib::llvm::CCallConv, llty);
156156
}
@@ -164,19 +164,20 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef) ->
164164
return llfn;
165165
}
166166

167-
pub fn get_extern_fn(externs: ExternMap,
167+
pub fn get_extern_fn(externs: HashMap<~str, ValueRef>,
168168
llmod: ModuleRef,
169-
name: @str,
169+
+name: ~str,
170170
cc: lib::llvm::CallConv,
171171
ty: TypeRef) -> ValueRef {
172172
if externs.contains_key_ref(&name) { return externs.get(&name); }
173-
let f = decl_fn(llmod, name, cc, ty);
173+
// XXX: Bad copy.
174+
let f = decl_fn(llmod, copy name, cc, ty);
174175
externs.insert(name, f);
175176
return f;
176177
}
177178

178-
pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
179-
name: @str, ty: TypeRef) -> ValueRef {
179+
pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
180+
+name: ~str, ty: TypeRef) -> ValueRef {
180181
unsafe {
181182
if externs.contains_key_ref(&name) { return externs.get(&name); }
182183
let c = str::as_c_str(name, |buf| {
@@ -188,9 +189,9 @@ pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
188189
}
189190

190191
fn get_simple_extern_fn(cx: block,
191-
externs: ExternMap,
192+
externs: HashMap<~str, ValueRef>,
192193
llmod: ModuleRef,
193-
name: @str,
194+
+name: ~str,
194195
n_args: int) -> ValueRef {
195196
let _icx = cx.insn_ctxt("get_simple_extern_fn");
196197
let ccx = cx.fcx.ccx;
@@ -200,8 +201,8 @@ pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
200201
return get_extern_fn(externs, llmod, name, lib::llvm::CCallConv, t);
201202
}
202203

203-
pub fn trans_foreign_call(cx: block, externs: ExternMap,
204-
llmod: ModuleRef, name: @str, args: ~[ValueRef]) ->
204+
pub fn trans_foreign_call(cx: block, externs: HashMap<~str, ValueRef>,
205+
llmod: ModuleRef, +name: ~str, args: ~[ValueRef]) ->
205206
ValueRef {
206207
let _icx = cx.insn_ctxt("trans_foreign_call");
207208
let n = args.len() as int;
@@ -473,7 +474,6 @@ pub fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
473474
let class_ty = ty::subst_tps(tcx, substs, None,
474475
ty::lookup_item_type(tcx, parent_id).ty);
475476
let llty = type_of_dtor(ccx, class_ty);
476-
let name = name.to_managed(); // :-(
477477
get_extern_fn(ccx.externs, ccx.llmod, name, lib::llvm::CCallConv,
478478
llty)
479479
}
@@ -766,7 +766,7 @@ pub fn null_env_ptr(bcx: block) -> ValueRef {
766766
767767
pub fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
768768
-> ValueRef {
769-
let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad
769+
let name = csearch::get_symbol(ccx.sess.cstore, did);
770770
match ty::get(t).sty {
771771
ty::ty_fn(_) => {
772772
let llty = type_of_fn_from_ty(ccx, t);

branches/try/src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,13 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
152152
}
153153
}
154154

155-
type ExternMap = HashMap<@str, ValueRef>;
156-
157155
// Crate context. Every crate we compile has one of these.
158156
pub struct crate_ctxt {
159157
sess: session::Session,
160158
llmod: ModuleRef,
161159
td: target_data,
162160
tn: type_names,
163-
externs: ExternMap,
161+
externs: HashMap<~str, ValueRef>,
164162
intrinsics: HashMap<~str, ValueRef>,
165163
item_vals: HashMap<ast::node_id, ValueRef>,
166164
exp_map2: resolve::ExportMap2,

branches/try/src/rt/rust_sched_loop.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct rust_sched_loop
135135
void place_task_in_tls(rust_task *task);
136136

137137
static rust_task *get_task_tls();
138+
static rust_task *try_get_task_tls();
138139

139140
// Called by each task when they are ready to be destroyed
140141
void release_task(rust_task *task);
@@ -154,7 +155,7 @@ rust_sched_loop::get_log() {
154155
return _log;
155156
}
156157

157-
inline rust_task* rust_sched_loop::get_task_tls()
158+
inline rust_task* rust_sched_loop::try_get_task_tls()
158159
{
159160
if (!tls_initialized)
160161
return NULL;
@@ -165,6 +166,12 @@ inline rust_task* rust_sched_loop::get_task_tls()
165166
rust_task *task = reinterpret_cast<rust_task *>
166167
(pthread_getspecific(task_key));
167168
#endif
169+
return task;
170+
}
171+
172+
inline rust_task* rust_sched_loop::get_task_tls()
173+
{
174+
rust_task *task = try_get_task_tls();
168175
assert(task && "Couldn't get the task from TLS!");
169176
return task;
170177
}

branches/try/src/rt/rust_task.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,14 @@ rust_task::record_stack_limit() {
619619
record_sp_limit(stk->data + LIMIT_OFFSET + RED_ZONE_SIZE);
620620
}
621621

622-
inline rust_task* rust_get_current_task() {
622+
inline rust_task* rust_try_get_current_task() {
623623
uintptr_t sp_limit = get_sp_limit();
624624

625625
// FIXME (#1226) - Because of a hack in upcall_call_shim_on_c_stack this
626626
// value is sometimes inconveniently set to 0, so we can't use this
627627
// method of retreiving the task pointer and need to fall back to TLS.
628628
if (sp_limit == 0)
629-
return rust_sched_loop::get_task_tls();
629+
return rust_sched_loop::try_get_task_tls();
630630

631631
// The stack pointer boundary is stored in a quickly-accessible location
632632
// in the TCB. From that we can calculate the address of the stack segment
@@ -642,6 +642,12 @@ inline rust_task* rust_get_current_task() {
642642
return stk->task;
643643
}
644644

645+
inline rust_task* rust_get_current_task() {
646+
rust_task* task = rust_try_get_current_task();
647+
assert(task != NULL && "no current task");
648+
return task;
649+
}
650+
645651
//
646652
// Local Variables:
647653
// mode: C++

branches/try/src/rt/rust_upcall.cpp

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ call_upcall_on_c_stack(rust_task *task, void *args, void *fn_ptr) {
4545
task->call_on_c_stack(args, fn_ptr);
4646
}
4747

48+
typedef void (*CDECL stack_switch_shim)(void*);
49+
4850
/**********************************************************************
4951
* Switches to the C-stack and invokes |fn_ptr|, passing |args| as argument.
5052
* This is used by the C compiler to call foreign functions and by other
@@ -54,13 +56,20 @@ call_upcall_on_c_stack(rust_task *task, void *args, void *fn_ptr) {
5456
*/
5557
extern "C" CDECL void
5658
upcall_call_shim_on_c_stack(void *args, void *fn_ptr) {
57-
rust_task *task = rust_get_current_task();
58-
59-
try {
60-
task->call_on_c_stack(args, fn_ptr);
61-
} catch (...) {
62-
// Logging here is not reliable
63-
assert(false && "Foreign code threw an exception");
59+
rust_task *task = rust_try_get_current_task();
60+
61+
if (task) {
62+
// We're running in task context, do a stack switch
63+
try {
64+
task->call_on_c_stack(args, fn_ptr);
65+
} catch (...) {
66+
// Logging here is not reliable
67+
assert(false && "Foreign code threw an exception");
68+
}
69+
} else {
70+
// There's no task. Call the function and hope for the best
71+
stack_switch_shim f = (stack_switch_shim)fn_ptr;
72+
f(args);
6473
}
6574
}
6675

@@ -70,15 +79,22 @@ upcall_call_shim_on_c_stack(void *args, void *fn_ptr) {
7079
*/
7180
extern "C" CDECL void
7281
upcall_call_shim_on_rust_stack(void *args, void *fn_ptr) {
73-
rust_task *task = rust_get_current_task();
74-
75-
try {
76-
task->call_on_rust_stack(args, fn_ptr);
77-
} catch (...) {
78-
// We can't count on being able to unwind through arbitrary
79-
// code. Our best option is to just fail hard.
80-
// Logging here is not reliable
81-
assert(false && "Rust task failed after reentering the Rust stack");
82+
rust_task *task = rust_try_get_current_task();
83+
84+
if (task) {
85+
try {
86+
task->call_on_rust_stack(args, fn_ptr);
87+
} catch (...) {
88+
// We can't count on being able to unwind through arbitrary
89+
// code. Our best option is to just fail hard.
90+
// Logging here is not reliable
91+
assert(false
92+
&& "Rust task failed after reentering the Rust stack");
93+
}
94+
} else {
95+
// There's no task. Call the function and hope for the best
96+
stack_switch_shim f = (stack_switch_shim)fn_ptr;
97+
f(args);
8298
}
8399
}
84100

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use core::private::run_in_bare_thread;
2+
3+
extern {
4+
pub fn rust_dbg_call(cb: *u8,
5+
data: libc::uintptr_t) -> libc::uintptr_t;
6+
}
7+
8+
pub fn main() {
9+
unsafe {
10+
do run_in_bare_thread() {
11+
unsafe {
12+
let i = &100;
13+
rust_dbg_call(callback, cast::transmute(i));
14+
}
15+
}
16+
}
17+
}
18+
19+
extern fn callback(data: libc::uintptr_t) {
20+
unsafe {
21+
let data: *int = cast::transmute(data);
22+
assert *data == 100;
23+
}
24+
}

0 commit comments

Comments
 (0)