Skip to content

Commit 41bf448

Browse files
committed
---
yaml --- r: 145767 b: refs/heads/try2 c: 23176fc h: refs/heads/master i: 145765: 6095970 145763: 77ad193 145759: 302cae8 v: v3
1 parent a34a77e commit 41bf448

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: b7b4f7a5e2982c8412fe71a9534f6f62435f9bc3
8+
refs/heads/try2: 23176fc567086715aab062a24e2b68e1f54ce5ba
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/rt/crate_map.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//#[cfg(not(stage0))] use cast::transmute;
1211
use container::MutableSet;
1312
use hashmap::HashSet;
14-
use option::{Some, None};
13+
use option::{Some, None, Option};
1514
use vec::ImmutableVector;
1615

1716
/// Imports for old crate map versions
@@ -61,22 +60,23 @@ pub struct ModEntry<'self> {
6160
pub struct CrateMap<'self> {
6261
version: i32,
6362
entries: &'self [ModEntry<'self>],
64-
/// a dynamically sized struct, where all pointers to children are listed adjacent
65-
/// to the struct, terminated with NULL
6663
children: &'self [&'self CrateMap<'self>]
6764
}
6865

69-
70-
7166
#[cfg(not(windows))]
72-
pub fn get_crate_map() -> &'static CrateMap<'static> {
73-
&'static CRATE_MAP
67+
pub fn get_crate_map() -> Option<&'static CrateMap<'static>> {
68+
let ptr: (*CrateMap) = &'static CRATE_MAP;
69+
if ptr.is_null() {
70+
return None;
71+
} else {
72+
return Some(&'static CRATE_MAP);
73+
}
7474
}
7575

7676
#[cfg(windows)]
7777
#[fixed_stack_segment]
7878
#[inline(never)]
79-
pub fn get_crate_map() -> &'static CrateMap<'static> {
79+
pub fn get_crate_map() -> Option<&'static CrateMap<'static>> {
8080
use c_str::ToCStr;
8181
use unstable::dynamic_lib::dl;
8282

@@ -88,7 +88,14 @@ pub fn get_crate_map() -> &'static CrateMap<'static> {
8888
dl::close(module);
8989
sym
9090
};
91-
sym
91+
let ptr: (*CrateMap) = sym as *CrateMap;
92+
if ptr.is_null() {
93+
return None;
94+
} else {
95+
unsafe {
96+
return Some(transmute(sym));
97+
}
98+
}
9299
}
93100

94101
fn version(crate_map: &CrateMap) -> i32 {
@@ -106,9 +113,9 @@ fn iter_module_map(mod_entries: &[ModEntry], f: &fn(&ModEntry)) {
106113
}
107114

108115
unsafe fn iter_module_map_v0(entries: *ModEntryV0, f: &fn(&ModEntry)) {
109-
let mut curr = entries;
116+
let mut curr = entries;
110117
while !(*curr).name.is_null() {
111-
let mod_entry = ModEntry { name: from_c_str((*curr).name), log_level: (*curr).log_level };
118+
let mod_entry = ModEntry { name: from_c_str((*curr).name), log_level: (*curr).log_level };
112119
f(&mod_entry);
113120
curr = curr.offset(1);
114121
}
@@ -125,7 +132,7 @@ fn do_iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry),
125132
do_iter_crate_map(*child, |x| f(x), visited);
126133
}
127134
},
128-
/// code for old crate map versions
135+
// code for old crate map versions
129136
1 => unsafe {
130137
let v1: *CrateMapV1 = transmute(crate_map);
131138
iter_module_map_v0((*v1).entries, |x| f(x));
@@ -142,7 +149,7 @@ fn do_iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry),
142149
do_iter_crate_map(transmute(child), |x| f(x), visited);
143150
}
144151
},
145-
_ => fail2!("invalid crate map version")
152+
_ => fail2!("invalid crate map version")
146153
}
147154
}
148155
}
@@ -260,7 +267,9 @@ mod tests {
260267

261268
let root_crate = CrateMapT3 {
262269
version: 1,
263-
entries: vec::raw::to_ptr([ModEntryV0 { name: ptr::null(), log_level: ptr::mut_null()}]),
270+
entries: vec::raw::to_ptr([
271+
ModEntryV0 { name: ptr::null(), log_level: ptr::mut_null()}
272+
]),
264273
children: [&child_crate as *CrateMapV1, &child_crate as *CrateMapV1, ptr::null()]
265274
};
266275

branches/try2/src/libstd/rt/logging.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,25 @@ impl rt::io::Writer for StdErrLogger {
199199
pub fn init() {
200200
use os;
201201

202-
let crate_map = get_crate_map();
203-
204202
let log_spec = os::getenv("RUST_LOG");
205-
match log_spec {
206-
Some(spec) => {
207-
update_log_settings(crate_map, spec);
208-
}
209-
None => {
210-
update_log_settings(crate_map, ~"");
203+
match get_crate_map() {
204+
Some(crate_map) => {
205+
match log_spec {
206+
Some(spec) => {
207+
update_log_settings(crate_map, spec);
208+
}
209+
None => {
210+
update_log_settings(crate_map, ~"");
211+
}
212+
}
213+
},
214+
_ => {
215+
match log_spec {
216+
Some(_) => {
217+
dumb_println("warning: RUST_LOG set, but no crate map found.");
218+
},
219+
None => {}
220+
}
211221
}
212222
}
213223
}

0 commit comments

Comments
 (0)