Skip to content

Commit 80061ec

Browse files
committed
rt: Remove rust_call_nullary_fn
There's no need to delegate to C to call the Rust main function.
1 parent 3c4b32c commit 80061ec

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/libcore/rt/mod.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,35 @@ mod local_heap;
3838
pub mod test;
3939

4040
pub fn start(main: *u8, _argc: int, _argv: **c_char, _crate_map: *u8) -> int {
41+
4142
use self::sched::{Scheduler, Task};
4243
use self::uvio::UvEventLoop;
44+
use sys::Closure;
45+
use ptr;
46+
use cast;
4347

4448
let loop_ = ~UvEventLoop::new();
4549
let mut sched = ~Scheduler::new(loop_);
50+
4651
let main_task = ~do Task::new(&mut sched.stack_pool) {
47-
// XXX: Can't call a C function pointer from Rust yet
48-
unsafe { rust_call_nullary_fn(main) };
52+
53+
unsafe {
54+
// `main` is an `fn() -> ()` that doesn't take an environment
55+
// XXX: Could also call this as an `extern "Rust" fn` once they work
56+
let main = Closure {
57+
code: main as *(),
58+
env: ptr::null(),
59+
};
60+
let mainfn: &fn() = cast::transmute(main);
61+
62+
mainfn();
63+
}
4964
};
65+
5066
sched.task_queue.push_back(main_task);
5167
sched.run();
52-
return 0;
5368

54-
extern {
55-
fn rust_call_nullary_fn(f: *u8);
56-
}
69+
return 0;
5770
}
5871

5972
/// Possible contexts in which Rust code may be executing.

src/rt/rust_builtin.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -830,13 +830,6 @@ rust_get_rt_env() {
830830
return task->kernel->env;
831831
}
832832

833-
typedef void *(*nullary_fn)();
834-
835-
extern "C" CDECL void
836-
rust_call_nullary_fn(nullary_fn f) {
837-
f();
838-
}
839-
840833
#ifndef _WIN32
841834
pthread_key_t sched_key;
842835
#else

src/rt/rustrt.def.in

-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ rust_uv_ip4_addrp
222222
rust_uv_ip6_addrp
223223
rust_uv_free_ip4_addr
224224
rust_uv_free_ip6_addr
225-
rust_call_nullary_fn
226225
rust_initialize_global_state
227226
rust_dbg_next_port
228227
rust_new_memory_region

0 commit comments

Comments
 (0)