about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-05-08 08:39:40 -0700
committerbors <bors@rust-lang.org>2013-05-08 08:39:40 -0700
commitb21f37c81804293168424697518d306542cdd798 (patch)
treee09109c9850741b5e4862964cef583ce50b1977c
parent8f94ac6118a3ce97d3d1186b38217a6ca4803771 (diff)
parent80061ecb1d11afd7c450673676e7708f85b73f12 (diff)
downloadrust-b21f37c81804293168424697518d306542cdd798.tar.gz
rust-b21f37c81804293168424697518d306542cdd798.zip
auto merge of #6323 : brson/rust/nullary, r=thestinger
There's no need to delegate to C to call the Rust main function.
-rw-r--r--src/libcore/rt/mod.rs25
-rw-r--r--src/rt/rust_builtin.cpp7
-rw-r--r--src/rt/rustrt.def.in1
3 files changed, 19 insertions, 14 deletions
diff --git a/src/libcore/rt/mod.rs b/src/libcore/rt/mod.rs
index a072fccd33d..25f6c870654 100644
--- a/src/libcore/rt/mod.rs
+++ b/src/libcore/rt/mod.rs
@@ -38,22 +38,35 @@ mod local_heap;
 pub mod test;
 
 pub fn start(main: *u8, _argc: int, _argv: **c_char, _crate_map: *u8) -> int {
+
     use self::sched::{Scheduler, Task};
     use self::uvio::UvEventLoop;
+    use sys::Closure;
+    use ptr;
+    use cast;
 
     let loop_ = ~UvEventLoop::new();
     let mut sched = ~Scheduler::new(loop_);
+
     let main_task = ~do Task::new(&mut sched.stack_pool) {
-        // XXX: Can't call a C function pointer from Rust yet
-        unsafe { rust_call_nullary_fn(main) };
+
+        unsafe {
+            // `main` is an `fn() -> ()` that doesn't take an environment
+            // XXX: Could also call this as an `extern "Rust" fn` once they work
+            let main = Closure {
+                code: main as *(),
+                env: ptr::null(),
+            };
+            let mainfn: &fn() = cast::transmute(main);
+
+            mainfn();
+        }
     };
+
     sched.task_queue.push_back(main_task);
     sched.run();
-    return 0;
 
-    extern {
-        fn rust_call_nullary_fn(f: *u8);
-    }
+    return 0;
 }
 
 /// Possible contexts in which Rust code may be executing.
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 885b40c0a50..90328928122 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -829,13 +829,6 @@ rust_get_rt_env() {
     return task->kernel->env;
 }
 
-typedef void *(*nullary_fn)();
-
-extern "C" CDECL void
-rust_call_nullary_fn(nullary_fn f) {
-    f();
-}
-
 #ifndef _WIN32
 pthread_key_t sched_key;
 #else
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index 1c3f6370ded..6be41251f1b 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -222,7 +222,6 @@ rust_uv_ip4_addrp
 rust_uv_ip6_addrp
 rust_uv_free_ip4_addr
 rust_uv_free_ip6_addr
-rust_call_nullary_fn
 rust_initialize_global_state
 rust_dbg_next_port
 rust_new_memory_region