Skip to content

Commit 3c00131

Browse files
committed
auto merge of #9280 : alexcrichton/rust/less-c++, r=brson
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 Because less C++ is better C++!
2 parents 4dacd73 + c3ad785 commit 3c00131

File tree

5 files changed

+40
-77
lines changed

5 files changed

+40
-77
lines changed

mk/rt.mk

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ RUNTIME_CXXS_$(1)_$(2) := \
7171
rt/sync/lock_and_signal.cpp \
7272
rt/sync/rust_thread.cpp \
7373
rt/rust_builtin.cpp \
74-
rt/rust_run_program.cpp \
7574
rt/rust_rng.cpp \
7675
rt/rust_upcall.cpp \
7776
rt/rust_uv.cpp \

src/libstd/run.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -643,15 +643,28 @@ fn spawn_process_os(prog: &str, args: &[~str],
643643
use libc::funcs::bsd44::getdtablesize;
644644

645645
mod rustrt {
646-
use libc::c_void;
647-
648646
#[abi = "cdecl"]
649647
extern {
650648
pub fn rust_unset_sigprocmask();
651-
pub fn rust_set_environ(envp: *c_void);
652649
}
653650
}
654651

652+
#[cfg(windows)]
653+
unsafe fn set_environ(_envp: *c_void) {}
654+
#[cfg(target_os = "macos")]
655+
unsafe fn set_environ(envp: *c_void) {
656+
externfn!(fn _NSGetEnviron() -> *mut *c_void);
657+
658+
*_NSGetEnviron() = envp;
659+
}
660+
#[cfg(not(target_os = "macos"), not(windows))]
661+
unsafe fn set_environ(envp: *c_void) {
662+
extern {
663+
static mut environ: *c_void;
664+
}
665+
environ = envp;
666+
}
667+
655668
unsafe {
656669

657670
let pid = fork();
@@ -685,7 +698,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
685698

686699
do with_envp(env) |envp| {
687700
if !envp.is_null() {
688-
rustrt::rust_set_environ(envp);
701+
set_environ(envp);
689702
}
690703
do with_argv(prog, args) |argv| {
691704
execvp(*argv, argv);

src/rt/rust_builtin.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,29 @@ rust_valgrind_stack_deregister(unsigned int id) {
643643
VALGRIND_STACK_DEREGISTER(id);
644644
}
645645

646+
#if defined(__WIN32__)
647+
648+
extern "C" CDECL void
649+
rust_unset_sigprocmask() {
650+
// empty stub for windows to keep linker happy
651+
}
652+
653+
#else
654+
655+
#include <signal.h>
656+
#include <unistd.h>
657+
658+
extern "C" CDECL void
659+
rust_unset_sigprocmask() {
660+
// this can't be safely converted to rust code because the
661+
// representation of sigset_t is platform-dependent
662+
sigset_t sset;
663+
sigemptyset(&sset);
664+
sigprocmask(SIG_SETMASK, &sset, NULL);
665+
}
666+
667+
#endif
668+
646669
//
647670
// Local Variables:
648671
// mode: C++

src/rt/rust_run_program.cpp

-71
This file was deleted.

src/rt/rustrt.def.in

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ rust_list_dir_wfd_fp_buf
2525
rust_log_console_on
2626
rust_log_console_off
2727
rust_should_log_console
28-
rust_set_environ
2928
rust_unset_sigprocmask
3029
rust_env_pairs
3130
upcall_rust_personality

0 commit comments

Comments
 (0)