]> git.lizzy.rs Git - rust.git/commitdiff
core::rt: Add a test of standalone use of the runtime
authorBrian Anderson <banderson@mozilla.com>
Wed, 8 May 2013 21:52:30 +0000 (14:52 -0700)
committerBrian Anderson <banderson@mozilla.com>
Wed, 15 May 2013 19:19:14 +0000 (12:19 -0700)
src/libcore/rt/mod.rs
src/libcore/unstable/lang.rs
src/test/run-pass/core-rt-smoke.rs [new file with mode: 0644]

index f04c38f79e80004fb348b349ec2def71172f2188..5dee9a7773155c33b0f079a8fbf3929ae42ab688 100644 (file)
 ///
 /// # Arguments
 ///
-/// * `main` - A C-abi function that takes no arguments and returns `c_void`.
-///   It is a wrapper around the user-defined `main` function, and will be run
-///   in a task.
 /// * `argc` & `argv` - The argument vector. On Unix this information is used
 ///   by os::args.
 /// * `crate_map` - Runtime information about the executing crate, mostly for logging
 /// # Return value
 ///
 /// The return value is used as the process return code. 0 on success, 101 on error.
-pub fn start(main: *u8, _argc: int, _argv: **c_char, _crate_map: *u8) -> int {
+pub fn start(_argc: int, _argv: **c_char, _crate_map: *u8, main: ~fn()) -> int {
 
     use self::sched::{Scheduler, Task};
     use self::uv::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) {
-
-        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();
-        }
-    };
+    let main_task = ~Task::new(&mut sched.stack_pool, main);
 
     sched.task_queue.push_back(main_task);
     sched.run();
index e521fb59fbe5f7ed7cfd9898df1577b0d93c819a..ce32cb4c282f219a5579813881f157a93b084d6f 100644 (file)
@@ -424,7 +424,10 @@ pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str {
 pub fn start(main: *u8, argc: int, argv: **c_char,
              crate_map: *u8) -> int {
     use libc::getenv;
-    use rt::start;
+    use rt;
+    use sys::Closure;
+    use ptr;
+    use cast;
 
     unsafe {
         let use_old_rt = do str::as_c_str("RUST_NEWRT") |s| {
@@ -434,7 +437,19 @@ pub fn start(main: *u8, argc: int, argv: **c_char,
             return rust_start(main as *c_void, argc as c_int, argv,
                               crate_map as *c_void) as int;
         } else {
-            return start(main, argc, argv, crate_map);
+            return do rt::start(argc, argv, crate_map) {
+                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();
+                }
+            };
         }
     }
 
diff --git a/src/test/run-pass/core-rt-smoke.rs b/src/test/run-pass/core-rt-smoke.rs
new file mode 100644 (file)
index 0000000..fb08cda
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// A simple test of starting the runtime manually
+
+#[start]
+fn start(argc: int, argv: **u8, crate_map: *u8) -> int {
+    do core::rt::start(argc, argv, crate_map) {
+        debug!("creating my own runtime is joy");
+    }
+}
\ No newline at end of file