Skip to content

Commit ba3210c

Browse files
committed
---
yaml --- r: 139051 b: refs/heads/try2 c: 6307d24 h: refs/heads/master i: 139049: c5b0fd7 139047: 04172ad v: v3
1 parent 28fef93 commit ba3210c

File tree

8 files changed

+64
-8
lines changed

8 files changed

+64
-8
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: deeeaf0ddbe3c5244442f3d12d0eaed512d65e75
8+
refs/heads/try2: 6307d24364c02ff636b6c76e0ac8b379d73b86f7
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/cleanup.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ unsafe fn each_live_alloc(f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) {
145145

146146
#[cfg(unix)]
147147
fn debug_mem() -> bool {
148-
use os;
149-
use libc;
150-
do os::as_c_charp("RUST_DEBUG_MEM") |p| {
151-
unsafe { libc::getenv(p) != null() }
152-
}
148+
::rt::env::get().debug_mem
153149
}
154150

155151
#[cfg(windows)]

branches/try2/src/libcore/rt/env.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2013 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+
//! Runtime environment settings
12+
13+
use libc::{size_t, c_char, c_int};
14+
15+
pub struct Environment {
16+
/// The number of threads to use by default
17+
num_sched_threads: size_t,
18+
/// The minimum size of a stack segment
19+
min_stack_size: size_t,
20+
/// The maximum amount of total stack per task before aborting
21+
max_stack_size: size_t,
22+
/// The default logging configuration
23+
logspec: *c_char,
24+
/// Record and report detailed information about memory leaks
25+
detailed_leaks: bool,
26+
/// Seed the random number generator
27+
rust_seed: *c_char,
28+
/// Poison allocations on free
29+
poison_on_free: bool,
30+
/// The argc value passed to main
31+
argc: c_int,
32+
/// The argv value passed to main
33+
argv: **c_char,
34+
/// Print GC debugging info
35+
debug_mem: bool
36+
}
37+
38+
/// Get the global environment settings
39+
/// # Safety Note
40+
/// This will abort the process if run outside of task context
41+
pub fn get() -> &Environment {
42+
unsafe { rust_get_rt_env() }
43+
}
44+
45+
extern {
46+
fn rust_get_rt_env() -> &Environment;
47+
}

branches/try2/src/libcore/rt/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ mod work_queue;
4545
mod stack;
4646
mod context;
4747
mod thread;
48+
pub mod env;

branches/try2/src/rt/rust_builtin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,11 @@ rust_dbg_extern_identity_u8(char u) {
876876
return u;
877877
}
878878

879+
extern "C" rust_env*
880+
rust_get_rt_env() {
881+
rust_task *task = rust_get_current_task();
882+
return task->kernel->env;
883+
}
879884

880885
//
881886
// Local Variables:

branches/try2/src/rt/rust_env.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define DETAILED_LEAKS "DETAILED_LEAKS"
2424
#define RUST_SEED "RUST_SEED"
2525
#define RUST_POISON_ON_FREE "RUST_POISON_ON_FREE"
26+
#define RUST_DEBUG_MEM "RUST_DEBUG_MEM"
2627

2728
#if defined(__WIN32__)
2829
static int
@@ -128,6 +129,7 @@ load_env(int argc, char **argv) {
128129
env->poison_on_free = getenv(RUST_POISON_ON_FREE) != NULL;
129130
env->argc = argc;
130131
env->argv = argv;
132+
env->debug_mem = getenv(RUST_DEBUG_MEM) != NULL;
131133
return env;
132134
}
133135

branches/try2/src/rt/rust_env.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@
1414

1515
#include "rust_globals.h"
1616

17+
// Avoiding 'bool' type here since I'm not sure it has a standard size
18+
typedef uint8_t rust_bool;
19+
1720
struct rust_env {
1821
size_t num_sched_threads;
1922
size_t min_stack_size;
2023
size_t max_stack_size;
2124
char* logspec;
22-
bool detailed_leaks;
25+
rust_bool detailed_leaks;
2326
char* rust_seed;
24-
bool poison_on_free;
27+
rust_bool poison_on_free;
2528
int argc;
2629
char **argv;
30+
rust_bool debug_mem;
2731
};
2832

2933
rust_env* load_env(int argc, char **argv);

branches/try2/src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,4 @@ rust_dbg_extern_identity_u64
201201
rust_dbg_extern_identity_TwoU64s
202202
rust_dbg_extern_identity_double
203203
rust_dbg_extern_identity_u8
204+
rust_get_rt_env

0 commit comments

Comments
 (0)