From c3ad785d83b583ad693424d9f0f993e36f0990f5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Sep 2013 14:45:50 -0700 Subject: [PATCH] Remove rust_run_program.cpp Some of the functions could be converted to rust, but the functions dealing with signals were moved to rust_builtin.cpp instead (no reason to keep the original file around for one function). Closes #2674 --- mk/rt.mk | 1 - src/libstd/run.rs | 21 ++++++++--- src/rt/rust_builtin.cpp | 23 ++++++++++++ src/rt/rust_run_program.cpp | 71 ------------------------------------- src/rt/rustrt.def.in | 1 - 5 files changed, 40 insertions(+), 77 deletions(-) delete mode 100644 src/rt/rust_run_program.cpp diff --git a/mk/rt.mk b/mk/rt.mk index 35ee42f9cb4..e41b7ce413b 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -71,7 +71,6 @@ RUNTIME_CXXS_$(1)_$(2) := \ rt/sync/lock_and_signal.cpp \ rt/sync/rust_thread.cpp \ rt/rust_builtin.cpp \ - rt/rust_run_program.cpp \ rt/rust_rng.cpp \ rt/rust_upcall.cpp \ rt/rust_uv.cpp \ diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 83646dc59b3..94673ac5a59 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -643,15 +643,28 @@ fn spawn_process_os(prog: &str, args: &[~str], use libc::funcs::bsd44::getdtablesize; mod rustrt { - use libc::c_void; - #[abi = "cdecl"] extern { pub fn rust_unset_sigprocmask(); - pub fn rust_set_environ(envp: *c_void); } } + #[cfg(windows)] + unsafe fn set_environ(_envp: *c_void) {} + #[cfg(target_os = "macos")] + unsafe fn set_environ(envp: *c_void) { + externfn!(fn _NSGetEnviron() -> *mut *c_void); + + *_NSGetEnviron() = envp; + } + #[cfg(not(target_os = "macos"), not(windows))] + unsafe fn set_environ(envp: *c_void) { + extern { + static mut environ: *c_void; + } + environ = envp; + } + unsafe { let pid = fork(); @@ -685,7 +698,7 @@ fn spawn_process_os(prog: &str, args: &[~str], do with_envp(env) |envp| { if !envp.is_null() { - rustrt::rust_set_environ(envp); + set_environ(envp); } do with_argv(prog, args) |argv| { execvp(*argv, argv); diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 4b718303f2c..8877b082588 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -643,6 +643,29 @@ rust_valgrind_stack_deregister(unsigned int id) { VALGRIND_STACK_DEREGISTER(id); } +#if defined(__WIN32__) + +extern "C" CDECL void +rust_unset_sigprocmask() { + // empty stub for windows to keep linker happy +} + +#else + +#include +#include + +extern "C" CDECL void +rust_unset_sigprocmask() { + // this can't be safely converted to rust code because the + // representation of sigset_t is platform-dependent + sigset_t sset; + sigemptyset(&sset); + sigprocmask(SIG_SETMASK, &sset, NULL); +} + +#endif + // // Local Variables: // mode: C++ diff --git a/src/rt/rust_run_program.cpp b/src/rt/rust_run_program.cpp deleted file mode 100644 index 25cbaf822f0..00000000000 --- a/src/rt/rust_run_program.cpp +++ /dev/null @@ -1,71 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -#include "rust_globals.h" - -#ifdef __APPLE__ -#include -#endif - -#if defined(__WIN32__) - -extern "C" CDECL void -rust_unset_sigprocmask() { - // empty stub for windows to keep linker happy -} - -extern "C" CDECL void -rust_set_environ(void* envp) { - // empty stub for windows to keep linker happy -} - -#elif defined(__GNUC__) - -#include -#include - -#ifdef __FreeBSD__ -extern char **environ; -#endif - -extern "C" CDECL void -rust_unset_sigprocmask() { - // this can't be safely converted to rust code because the - // representation of sigset_t is platform-dependent - sigset_t sset; - sigemptyset(&sset); - sigprocmask(SIG_SETMASK, &sset, NULL); -} - -extern "C" CDECL void -rust_set_environ(void* envp) { - // FIXME: this could actually be converted to rust (see issue #2674) -#ifdef __APPLE__ - *_NSGetEnviron() = (char **) envp; -#else - environ = (char **) envp; -#endif -} - -#else -#error "Platform not supported." -#endif - -// -// Local Variables: -// mode: C++ -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; -// End: -// diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 4cbee0dcbd0..93e8d34ca5f 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -25,7 +25,6 @@ rust_list_dir_wfd_fp_buf rust_log_console_on rust_log_console_off rust_should_log_console -rust_set_environ rust_unset_sigprocmask rust_env_pairs upcall_rust_personality