]> git.lizzy.rs Git - rust.git/blob - src/libstd/rt/env.rs
std::rt: Pull RUST_MIN_STACK from the environment
[rust.git] / src / libstd / rt / env.rs
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 from_str::FromStr;
14 use libc::{size_t, c_char, c_int};
15 use option::{Some, None};
16 use os;
17
18 // OLD RT stuff
19
20 pub struct Environment {
21     /// The number of threads to use by default
22     num_sched_threads: size_t,
23     /// The minimum size of a stack segment
24     min_stack_size: size_t,
25     /// The maximum amount of total stack per task before aborting
26     max_stack_size: size_t,
27     /// The default logging configuration
28     logspec: *c_char,
29     /// Record and report detailed information about memory leaks
30     detailed_leaks: bool,
31     /// Seed the random number generator
32     rust_seed: *c_char,
33     /// Poison allocations on free
34     poison_on_free: bool,
35     /// The argc value passed to main
36     argc: c_int,
37     /// The argv value passed to main
38     argv: **c_char,
39     /// Print GC debugging info (true if env var RUST_DEBUG_MEM is set)
40     debug_mem: bool,
41     /// Print GC debugging info (true if env var RUST_DEBUG_BORROW is set)
42     debug_borrow: bool,
43 }
44
45 /// Get the global environment settings
46 /// # Safety Note
47 /// This will abort the process if run outside of task context
48 pub fn get() -> &Environment {
49     unsafe { rust_get_rt_env() }
50 }
51
52 extern {
53     fn rust_get_rt_env() -> &Environment;
54 }
55
56 // NEW RT stuff
57
58 // Note that these are all accessed without any synchronization.
59 // They are expected to be initialized once then left alone.
60
61 static mut MIN_STACK: uint = 2000000;
62
63 pub fn init() {
64     unsafe {
65         match os::getenv("RUST_MIN_STACK") {
66             Some(s) => match FromStr::from_str(s) {
67                 Some(i) => MIN_STACK = i,
68                 None => ()
69             },
70             None => ()
71         }
72     }
73 }
74
75 pub fn min_stack() -> uint {
76     unsafe { MIN_STACK }
77 }