Skip to content

Commit 36ad366

Browse files
committed
core::rt: Add a test of standalone use of the runtime
1 parent bfd9aa9 commit 36ad366

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

src/libcore/rt/mod.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,41 +131,21 @@ pub mod tube;
131131
///
132132
/// # Arguments
133133
///
134-
/// * `main` - A C-abi function that takes no arguments and returns `c_void`.
135-
/// It is a wrapper around the user-defined `main` function, and will be run
136-
/// in a task.
137134
/// * `argc` & `argv` - The argument vector. On Unix this information is used
138135
/// by os::args.
139136
/// * `crate_map` - Runtime information about the executing crate, mostly for logging
140137
///
141138
/// # Return value
142139
///
143140
/// The return value is used as the process return code. 0 on success, 101 on error.
144-
pub fn start(main: *u8, _argc: int, _argv: **c_char, _crate_map: *u8) -> int {
141+
pub fn start(_argc: int, _argv: **c_char, _crate_map: *u8, main: ~fn()) -> int {
145142

146143
use self::sched::{Scheduler, Task};
147144
use self::uv::uvio::UvEventLoop;
148-
use sys::Closure;
149-
use ptr;
150-
use cast;
151145

152146
let loop_ = ~UvEventLoop::new();
153147
let mut sched = ~Scheduler::new(loop_);
154-
155-
let main_task = ~do Task::new(&mut sched.stack_pool) {
156-
157-
unsafe {
158-
// `main` is an `fn() -> ()` that doesn't take an environment
159-
// XXX: Could also call this as an `extern "Rust" fn` once they work
160-
let main = Closure {
161-
code: main as *(),
162-
env: ptr::null(),
163-
};
164-
let mainfn: &fn() = cast::transmute(main);
165-
166-
mainfn();
167-
}
168-
};
148+
let main_task = ~Task::new(&mut sched.stack_pool, main);
169149

170150
sched.task_queue.push_back(main_task);
171151
sched.run();

src/libcore/unstable/lang.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,10 @@ pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str {
424424
pub fn start(main: *u8, argc: int, argv: **c_char,
425425
crate_map: *u8) -> int {
426426
use libc::getenv;
427-
use rt::start;
427+
use rt;
428+
use sys::Closure;
429+
use ptr;
430+
use cast;
428431

429432
unsafe {
430433
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,
434437
return rust_start(main as *c_void, argc as c_int, argv,
435438
crate_map as *c_void) as int;
436439
} else {
437-
return start(main, argc, argv, crate_map);
440+
return do rt::start(argc, argv, crate_map) {
441+
unsafe {
442+
// `main` is an `fn() -> ()` that doesn't take an environment
443+
// XXX: Could also call this as an `extern "Rust" fn` once they work
444+
let main = Closure {
445+
code: main as *(),
446+
env: ptr::null(),
447+
};
448+
let mainfn: &fn() = cast::transmute(main);
449+
450+
mainfn();
451+
}
452+
};
438453
}
439454
}
440455

src/test/run-pass/core-rt-smoke.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// A simple test of starting the runtime manually
12+
13+
#[start]
14+
fn start(argc: int, argv: **u8, crate_map: *u8) -> int {
15+
do core::rt::start(argc, argv, crate_map) {
16+
debug!("creating my own runtime is joy");
17+
}
18+
}

0 commit comments

Comments
 (0)