From 92841793114d7e60e3227d9087dc8741e7592789 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 2 Oct 2012 12:19:04 -0700 Subject: libstd: Switch off legacy modes in both core and std. --- src/rt/rust_builtin.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/rt/rust_builtin.cpp') diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 91c5760d3e9..6f985601f8b 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -180,6 +180,11 @@ rand_new_seeded(rust_vec_box* seed) { return rctx; } +extern "C" CDECL void * +rand_new_seeded2(rust_vec_box** seed) { + return rand_new_seeded(*seed); +} + extern "C" CDECL size_t rand_next(randctx *rctx) { return isaac_rand(rctx); @@ -371,6 +376,11 @@ rust_list_files(rust_str *path) { return vec; } +extern "C" CDECL rust_vec_box* +rust_list_files2(rust_str **path) { + return rust_list_files(*path); +} + extern "C" CDECL int rust_path_is_dir(char *path) { struct stat buf; -- cgit 1.4.1-3-g733a5 From 365f17483800a9c688bc8606959a9121b8e855a6 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 3 Oct 2012 14:41:53 -0700 Subject: Attempt to fix os::args errors on various platforms. --- src/libcore/os.rs | 34 +++++++++++++++++++++------------- src/rt/rust.cpp | 2 +- src/rt/rust_builtin.cpp | 12 ++++++++++++ src/rt/rust_env.cpp | 5 +++-- src/rt/rust_env.h | 4 +++- src/rt/rustrt.def.in | 2 ++ 6 files changed, 42 insertions(+), 17 deletions(-) (limited to 'src/rt/rust_builtin.cpp') diff --git a/src/libcore/os.rs b/src/libcore/os.rs index d37bdabd48a..68571da3a1e 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -32,6 +32,8 @@ use task::TaskBuilder; // FIXME: move these to str perhaps? #2620 extern mod rustrt { + fn rust_get_argc() -> c_int; + fn rust_get_argv() -> **c_char; fn rust_getcwd() -> ~str; fn rust_path_is_dir(path: *libc::c_char) -> c_int; fn rust_path_exists(path: *libc::c_char) -> c_int; @@ -732,6 +734,14 @@ pub fn set_exit_status(code: int) { rustrt::rust_set_exit_status(code as libc::intptr_t); } +unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] { + let mut args = ~[]; + for uint::range(0, argc as uint) |i| { + vec::push(&mut args, str::raw::from_c_str(*argv.offset(i))); + } + return args; +} + /** * Returns the command line arguments * @@ -740,23 +750,20 @@ pub fn set_exit_status(code: int) { #[cfg(target_os = "macos")] fn real_args() -> ~[~str] { unsafe { - let (argc, argv) = (*_NSGetArgc() as uint, *_NSGetArgv()); - let mut args = ~[]; - for uint::range(0, argc) |i| { - vec::push(&mut args, str::raw::from_c_str(*argv.offset(i))); - } - return args; + let (argc, argv) = (*_NSGetArgc() as c_int, + *_NSGetArgv() as **c_char); + load_argc_and_argv(argc, argv) } } #[cfg(target_os = "linux")] -fn real_args() -> ~[~str] { - fail // Needs implementing. -} - #[cfg(target_os = "freebsd")] fn real_args() -> ~[~str] { - fail // Needs implementing. + unsafe { + let argc = rustrt::rust_get_argc(); + let argv = rustrt::rust_get_argv(); + load_argc_and_argv(argc, argv) + } } #[cfg(windows)] @@ -775,8 +782,9 @@ fn real_args() -> ~[~str] { while *ptr.offset(len) != 0 { len += 1; } // Push it onto the list. - vec::push(&mut args, vec::raw::form_slice(ptr, len, - str::from_utf16)); + vec::push(&mut args, + vec::raw::buf_as_slice(ptr, len, + str::from_utf16)); } } diff --git a/src/rt/rust.cpp b/src/rt/rust.cpp index dc28f624415..11e65347f11 100644 --- a/src/rt/rust.cpp +++ b/src/rt/rust.cpp @@ -86,7 +86,7 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) { // Load runtime configuration options from the environment. // FIXME #1497: Should provide a way to get these from the command // line as well. - rust_env *env = load_env(); + rust_env *env = load_env(argc, argv); global_crate_map = crate_map; diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 6f985601f8b..5baa95c7323 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -588,6 +588,18 @@ rust_num_threads() { return task->kernel->env->num_sched_threads; } +extern "C" CDECL int +rust_get_argc() { + rust_task *task = rust_get_current_task(); + return task->kernel->env->argc; +} + +extern "C" CDECL char** +rust_get_argv() { + rust_task *task = rust_get_current_task(); + return task->kernel->env->argv; +} + extern "C" CDECL rust_sched_id rust_new_sched(uintptr_t threads) { rust_task *task = rust_get_current_task(); diff --git a/src/rt/rust_env.cpp b/src/rt/rust_env.cpp index a54dc27c71f..4e653c8f9e6 100644 --- a/src/rt/rust_env.cpp +++ b/src/rt/rust_env.cpp @@ -107,7 +107,7 @@ copyenv(const char* name) { } rust_env* -load_env() { +load_env(int argc, char **argv) { rust_env *env = (rust_env*)malloc(sizeof(rust_env)); env->num_sched_threads = (size_t)get_num_threads(); @@ -118,7 +118,8 @@ load_env() { 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; return env; } diff --git a/src/rt/rust_env.h b/src/rt/rust_env.h index 007ac9b1e0b..0e3af9eae60 100644 --- a/src/rt/rust_env.h +++ b/src/rt/rust_env.h @@ -13,9 +13,11 @@ struct rust_env { bool detailed_leaks; char* rust_seed; bool poison_on_free; + int argc; + char **argv; }; -rust_env* load_env(); +rust_env* load_env(int argc, char **argv); void free_env(rust_env *rust_env); #endif diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 551378a3d6c..7412f06d8cd 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -31,6 +31,8 @@ rand_new_seeded2 rand_next rand_seed rust_get_sched_id +rust_get_argc +rust_get_argv rust_new_sched rust_new_task_in_sched rust_num_threads -- cgit 1.4.1-3-g733a5