Skip to content

Commit 9621156

Browse files
committed
librustc/libstd: No longer pass crate_map to start.
1 parent d2b0b11 commit 9621156

File tree

6 files changed

+79
-13
lines changed

6 files changed

+79
-13
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,11 +2442,6 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
24422442
unsafe {
24432443
llvm::LLVMPositionBuilderAtEnd(bld, llbb);
24442444

2445-
let crate_map = ccx.crate_map;
2446-
let opaque_crate_map = do "crate_map".with_c_str |buf| {
2447-
llvm::LLVMBuildPointerCast(bld, crate_map, Type::i8p().to_ref(), buf)
2448-
};
2449-
24502445
let (start_fn, args) = if use_start_lang_item {
24512446
let start_def_id = match ccx.tcx.lang_items.require(StartFnLangItem) {
24522447
Ok(id) => id,
@@ -2469,8 +2464,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
24692464
C_null(Type::opaque_box(ccx).ptr_to()),
24702465
opaque_rust_main,
24712466
llvm::LLVMGetParam(llfn, 0),
2472-
llvm::LLVMGetParam(llfn, 1),
2473-
opaque_crate_map
2467+
llvm::LLVMGetParam(llfn, 1)
24742468
]
24752469
};
24762470
(start_fn, args)
@@ -2479,8 +2473,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
24792473
let args = ~[
24802474
C_null(Type::opaque_box(ccx).ptr_to()),
24812475
llvm::LLVMGetParam(llfn, 0 as c_uint),
2482-
llvm::LLVMGetParam(llfn, 1 as c_uint),
2483-
opaque_crate_map
2476+
llvm::LLVMGetParam(llfn, 1 as c_uint)
24842477
];
24852478

24862479
(rust_main, args)
@@ -2659,6 +2652,8 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
26592652
let path = vec::append((*pth).clone(), [path_name(ni.ident)]);
26602653
foreign::register_foreign_item_fn(ccx, abis, &path, ni)
26612654
}
2655+
ast::foreign_item_static(*) if attr::contains_name(ni.attrs, "crate_map")
2656+
=> ccx.crate_map,
26622657
ast::foreign_item_static(*) => {
26632658
let ident = foreign::link_name(ccx, ni);
26642659
let g = do ident.with_c_str |buf| {

src/librustc/middle/typeck/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
402402
bound_lifetime_names: opt_vec::Empty,
403403
inputs: ~[
404404
ty::mk_int(),
405-
ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8())),
406-
ty::mk_imm_ptr(tcx, ty::mk_u8())
405+
ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8()))
407406
],
408407
output: ty::mk_int()
409408
}

src/libstd/rt/crate_map.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ use vec;
1616
use hashmap::HashSet;
1717
use container::MutableSet;
1818

19-
pub struct ModEntry{
19+
extern {
20+
#[cfg(not(stage0))]
21+
#[crate_map]
22+
static CRATE_MAP: CrateMap;
23+
}
24+
25+
pub struct ModEntry {
2026
name: *c_char,
2127
log_level: *mut u32
2228
}
@@ -34,6 +40,11 @@ struct CrateMap {
3440
children: [*CrateMap, ..1]
3541
}
3642

43+
#[cfg(not(stage0))]
44+
pub fn get_crate_map() -> *CrateMap {
45+
&'static CRATE_MAP as *CrateMap
46+
}
47+
3748
unsafe fn version(crate_map: *CrateMap) -> i32 {
3849
match (*crate_map).version {
3950
1 => return 1,

src/libstd/rt/logging.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use libc::{uintptr_t, exit, STDERR_FILENO};
1212
use option::{Some, None, Option};
1313
use rt::util::dumb_println;
1414
use rt::crate_map::{ModEntry, iter_crate_map};
15+
#[cfg(not(stage0))] use rt::crate_map::get_crate_map;
1516
use str::StrSlice;
1617
use str::raw::from_c_str;
1718
use u32;
@@ -211,6 +212,7 @@ impl Logger for StdErrLogger {
211212
/// Configure logging by traversing the crate map and setting the
212213
/// per-module global logging flags based on the logging spec
213214
#[fixed_stack_segment] #[inline(never)]
215+
#[cfg(stage0)]
214216
pub fn init(crate_map: *u8) {
215217
use os;
216218

@@ -224,6 +226,22 @@ pub fn init(crate_map: *u8) {
224226
}
225227
}
226228
}
229+
#[cfg(not(stage0))]
230+
pub fn init() {
231+
use os;
232+
233+
let crate_map = get_crate_map() as *u8;
234+
235+
let log_spec = os::getenv("RUST_LOG");
236+
match log_spec {
237+
Some(spec) => {
238+
update_log_settings(crate_map, spec);
239+
}
240+
None => {
241+
update_log_settings(crate_map, ~"");
242+
}
243+
}
244+
}
227245

228246
#[fixed_stack_segment] #[inline(never)]
229247
pub fn console_on() { unsafe { rust_log_console_on() } }

src/libstd/rt/mod.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ pub mod borrowck;
171171
///
172172
/// * `argc` & `argv` - The argument vector. On Unix this information is used
173173
/// by os::args.
174-
/// * `crate_map` - Runtime information about the executing crate, mostly for logging
175174
///
176175
/// # Return value
177176
///
178177
/// The return value is used as the process return code. 0 on success, 101 on error.
178+
#[cfg(stage0)]
179179
pub fn start(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int {
180180

181181
init(argc, argv, crate_map);
@@ -184,25 +184,44 @@ pub fn start(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int {
184184

185185
return exit_code;
186186
}
187+
#[cfg(not(stage0))]
188+
pub fn start(argc: int, argv: **u8, main: ~fn()) -> int {
189+
190+
init(argc, argv);
191+
let exit_code = run(main);
192+
cleanup();
193+
194+
return exit_code;
195+
}
187196

188197
/// Like `start` but creates an additional scheduler on the current thread,
189198
/// which in most cases will be the 'main' thread, and pins the main task to it.
190199
///
191200
/// This is appropriate for running code that must execute on the main thread,
192201
/// such as the platform event loop and GUI.
202+
#[cfg(stage0)]
193203
pub fn start_on_main_thread(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int {
194204
init(argc, argv, crate_map);
195205
let exit_code = run_on_main_thread(main);
196206
cleanup();
197207

198208
return exit_code;
199209
}
210+
#[cfg(not(stage0))]
211+
pub fn start_on_main_thread(argc: int, argv: **u8, main: ~fn()) -> int {
212+
init(argc, argv);
213+
let exit_code = run_on_main_thread(main);
214+
cleanup();
215+
216+
return exit_code;
217+
}
200218

201219
/// One-time runtime initialization.
202220
///
203221
/// Initializes global state, including frobbing
204222
/// the crate's logging flags, registering GC
205223
/// metadata, and storing the process arguments.
224+
#[cfg(stage0)]
206225
pub fn init(argc: int, argv: **u8, crate_map: *u8) {
207226
// XXX: Derefing these pointers is not safe.
208227
// Need to propagate the unsafety to `start`.
@@ -212,6 +231,16 @@ pub fn init(argc: int, argv: **u8, crate_map: *u8) {
212231
logging::init(crate_map);
213232
}
214233
}
234+
#[cfg(not(stage0))]
235+
pub fn init(argc: int, argv: **u8) {
236+
// XXX: Derefing these pointers is not safe.
237+
// Need to propagate the unsafety to `start`.
238+
unsafe {
239+
args::init(argc, argv);
240+
env::init();
241+
logging::init();
242+
}
243+
}
215244

216245
/// One-time runtime cleanup.
217246
pub fn cleanup() {

src/libstd/unstable/lang.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub unsafe fn check_not_borrowed(a: *u8,
9393
borrowck::check_not_borrowed(a, file, line)
9494
}
9595

96+
#[cfg(stage0)]
9697
#[lang="start"]
9798
pub fn start(main: *u8, argc: int, argv: **c_char,
9899
crate_map: *u8) -> int {
@@ -105,3 +106,16 @@ pub fn start(main: *u8, argc: int, argv: **c_char,
105106
};
106107
}
107108
}
109+
110+
#[cfg(not(stage0))]
111+
#[lang="start"]
112+
pub fn start(main: *u8, argc: int, argv: **c_char) -> int {
113+
use rt;
114+
115+
unsafe {
116+
return do rt::start(argc, argv as **u8) {
117+
let main: extern "Rust" fn() = transmute(main);
118+
main();
119+
};
120+
}
121+
}

0 commit comments

Comments
 (0)