about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-08-09 22:21:01 -0700
committerBrian Anderson <banderson@mozilla.com>2013-08-16 13:24:24 -0700
commit5923cc37458d609c66849df3613464f474cad9cd (patch)
treee500df4234b44b8aa9e7ecebeb573a5f130d4b8d
parent680eb71564ebba5e76ce1e1a8287b30042332cc5 (diff)
downloadrust-5923cc37458d609c66849df3613464f474cad9cd.tar.gz
rust-5923cc37458d609c66849df3613464f474cad9cd.zip
rt: Remove rust_env
-rw-r--r--mk/rt.mk1
-rw-r--r--src/rt/boxed_region.cpp1
-rw-r--r--src/rt/rust_builtin.cpp54
-rw-r--r--src/rt/rust_env.cpp163
-rw-r--r--src/rt/rust_env.h37
-rw-r--r--src/rt/rust_util.h1
6 files changed, 53 insertions, 204 deletions
diff --git a/mk/rt.mk b/mk/rt.mk
index 0aeeec3b487..6caa67e1a25 100644
--- a/mk/rt.mk
+++ b/mk/rt.mk
@@ -68,7 +68,6 @@ RUNTIME_CXXS_$(1)_$(2) := \
               rt/sync/rust_thread.cpp \
               rt/rust_builtin.cpp \
               rt/rust_run_program.cpp \
-              rt/rust_env.cpp \
               rt/rust_rng.cpp \
               rt/rust_stack.cpp \
               rt/rust_upcall.cpp \
diff --git a/src/rt/boxed_region.cpp b/src/rt/boxed_region.cpp
index 0d3d6c019f8..064648a9671 100644
--- a/src/rt/boxed_region.cpp
+++ b/src/rt/boxed_region.cpp
@@ -11,7 +11,6 @@
 #include "memory_region.h"
 #include "boxed_region.h"
 #include "rust_globals.h"
-#include "rust_env.h"
 #include "rust_util.h"
 
 // #define DUMP_BOXED_REGION
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index ddd452deef2..080dae7d7af 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -571,7 +571,47 @@ rust_running_on_valgrind() {
     return RUNNING_ON_VALGRIND;
 }
 
-extern int get_num_cpus();
+#if defined(__WIN32__)
+int
+get_num_cpus() {
+    SYSTEM_INFO sysinfo;
+    GetSystemInfo(&sysinfo);
+
+    return (int) sysinfo.dwNumberOfProcessors;
+}
+#elif defined(__BSD__)
+int
+get_num_cpus() {
+    /* swiped from http://stackoverflow.com/questions/150355/
+       programmatically-find-the-number-of-cores-on-a-machine */
+
+    unsigned int numCPU;
+    int mib[4];
+    size_t len = sizeof(numCPU);
+
+    /* set the mib for hw.ncpu */
+    mib[0] = CTL_HW;
+    mib[1] = HW_AVAILCPU;  // alternatively, try HW_NCPU;
+
+    /* get the number of CPUs from the system */
+    sysctl(mib, 2, &numCPU, &len, NULL, 0);
+
+    if( numCPU < 1 ) {
+        mib[1] = HW_NCPU;
+        sysctl( mib, 2, &numCPU, &len, NULL, 0 );
+
+        if( numCPU < 1 ) {
+            numCPU = 1;
+        }
+    }
+    return numCPU;
+}
+#elif defined(__GNUC__)
+int
+get_num_cpus() {
+    return sysconf(_SC_NPROCESSORS_ONLN);
+}
+#endif
 
 extern "C" CDECL uintptr_t
 rust_get_num_cpus() {
@@ -629,6 +669,18 @@ rust_get_task() {
     return 0;
 }
 
+static lock_and_signal env_lock;
+
+extern "C" CDECL void
+rust_take_env_lock() {
+    env_lock.lock();
+}
+
+extern "C" CDECL void
+rust_drop_env_lock() {
+    env_lock.unlock();
+}
+
 //
 // Local Variables:
 // mode: C++
diff --git a/src/rt/rust_env.cpp b/src/rt/rust_env.cpp
deleted file mode 100644
index 1a29cae2c8b..00000000000
--- a/src/rt/rust_env.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// The runtime wants to pull a number of variables out of the
-// environment but calling getenv is not threadsafe, so every value
-// that might come from the environment is loaded here, once, during
-// init.
-
-#include "sync/lock_and_signal.h"
-#include "rust_env.h"
-
-// The environment variables that the runtime knows about
-#define RUST_THREADS "RUST_THREADS"
-#define RUST_MIN_STACK "RUST_MIN_STACK"
-#define RUST_MAX_STACK "RUST_MAX_STACK"
-#define RUST_LOG "RUST_LOG"
-#define DETAILED_LEAKS "DETAILED_LEAKS"
-#define RUST_SEED "RUST_SEED"
-#define RUST_POISON_ON_FREE "RUST_POISON_ON_FREE"
-#define RUST_DEBUG_MEM "RUST_DEBUG_MEM"
-#define RUST_DEBUG_BORROW "RUST_DEBUG_BORROW"
-
-#define DEFAULT_RUST_MIN_STACK_32 0x300
-#define DEFAULT_RUST_MIN_STACK_64 0x400000
-
-static lock_and_signal env_lock;
-
-extern "C" CDECL void
-rust_take_env_lock() {
-    env_lock.lock();
-}
-
-extern "C" CDECL void
-rust_drop_env_lock() {
-    env_lock.unlock();
-}
-
-#if defined(__WIN32__)
-int
-get_num_cpus() {
-    SYSTEM_INFO sysinfo;
-    GetSystemInfo(&sysinfo);
-
-    return (int) sysinfo.dwNumberOfProcessors;
-}
-#elif defined(__BSD__)
-int
-get_num_cpus() {
-    /* swiped from http://stackoverflow.com/questions/150355/
-       programmatically-find-the-number-of-cores-on-a-machine */
-
-    unsigned int numCPU;
-    int mib[4];
-    size_t len = sizeof(numCPU);
-
-    /* set the mib for hw.ncpu */
-    mib[0] = CTL_HW;
-    mib[1] = HW_AVAILCPU;  // alternatively, try HW_NCPU;
-
-    /* get the number of CPUs from the system */
-    sysctl(mib, 2, &numCPU, &len, NULL, 0);
-
-    if( numCPU < 1 ) {
-        mib[1] = HW_NCPU;
-        sysctl( mib, 2, &numCPU, &len, NULL, 0 );
-
-        if( numCPU < 1 ) {
-            numCPU = 1;
-        }
-    }
-    return numCPU;
-}
-#elif defined(__GNUC__)
-int
-get_num_cpus() {
-    return sysconf(_SC_NPROCESSORS_ONLN);
-}
-#endif
-
-static int
-get_num_threads()
-{
-    char *env = getenv(RUST_THREADS);
-    if(env) {
-        int num = atoi(env);
-        if(num > 0)
-            return num;
-    }
-    return get_num_cpus();
-}
-
-static size_t
-get_min_stk_size() {
-    char *minsz = getenv(RUST_MIN_STACK);
-    if(minsz) {
-        return strtol(minsz, NULL, 0);
-    }
-    else if (sizeof(size_t) > 4) {
-        return DEFAULT_RUST_MIN_STACK_64;
-    } else {
-        return DEFAULT_RUST_MIN_STACK_32;
-    }
-}
-
-static size_t
-get_max_stk_size() {
-    char *maxsz = getenv(RUST_MAX_STACK);
-    if (maxsz) {
-        return strtol(maxsz, NULL, 0);
-    }
-    else {
-        return 1024*1024*1024;
-    }
-}
-
-static char*
-copyenv(const char* name) {
-    char *envvar = getenv(name);
-    if (!envvar) {
-        return NULL;
-    } else {
-        size_t slen = strlen(envvar);
-        size_t buflen = slen + 1;
-        char *var = (char*)malloc(buflen);
-        memset(var, 0, buflen);
-        strncpy(var, envvar, slen);
-        return var;
-    }
-}
-
-rust_env*
-load_env(int argc, char **argv) {
-    scoped_lock with(env_lock);
-
-    rust_env *env = (rust_env*)malloc(sizeof(rust_env));
-
-    env->num_sched_threads = (size_t)get_num_threads();
-    env->min_stack_size = get_min_stk_size();
-    env->max_stack_size = get_max_stk_size();
-    env->logspec = copyenv(RUST_LOG);
-    env->detailed_leaks = getenv(DETAILED_LEAKS) != NULL;
-    env->rust_seed = copyenv(RUST_SEED);
-    env->poison_on_free = getenv(RUST_POISON_ON_FREE) != NULL;
-    env->argc = argc;
-    env->argv = argv;
-    env->debug_mem = getenv(RUST_DEBUG_MEM) != NULL;
-    env->debug_borrow = getenv(RUST_DEBUG_BORROW) != NULL;
-    return env;
-}
-
-void
-free_env(rust_env *env) {
-    free(env->logspec);
-    free(env->rust_seed);
-    free(env);
-}
diff --git a/src/rt/rust_env.h b/src/rt/rust_env.h
deleted file mode 100644
index b897f0c09a9..00000000000
--- a/src/rt/rust_env.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-#ifndef RUST_ENV_H
-#define RUST_ENV_H
-
-#include "rust_globals.h"
-
-// Avoiding 'bool' type here since I'm not sure it has a standard size
-typedef uint8_t rust_bool;
-
-struct rust_env {
-    size_t num_sched_threads;
-    size_t min_stack_size;
-    size_t max_stack_size;
-    char* logspec;
-    rust_bool detailed_leaks;
-    char* rust_seed;
-    rust_bool poison_on_free;
-    int argc;
-    char **argv;
-    rust_bool debug_mem;
-    rust_bool debug_borrow;
-};
-
-rust_env* load_env(int argc, char **argv);
-void free_env(rust_env *rust_env);
-
-#endif
diff --git a/src/rt/rust_util.h b/src/rt/rust_util.h
index 30d4fcbdc49..7c531297ccd 100644
--- a/src/rt/rust_util.h
+++ b/src/rt/rust_util.h
@@ -14,7 +14,6 @@
 #include <limits.h>
 #include "rust_exchange_alloc.h"
 #include "rust_type.h"
-#include "rust_env.h"
 
 extern struct type_desc str_body_tydesc;