Skip to content

Commit 6023902

Browse files
committed
---
yaml --- r: 142696 b: refs/heads/try2 c: 07e52eb h: refs/heads/master v: v3
1 parent 3f97cbd commit 6023902

File tree

6 files changed

+58
-4
lines changed

6 files changed

+58
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ec6d4a1733b07d4cc561eda7463ad596a9d52bf0
8+
refs/heads/try2: 07e52eb7fc75466d294a1fd9d614f5e0276ab834
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/os.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,15 @@ pub fn last_os_error() -> ~str {
11341134
* ignored and the process exits with the default failure status
11351135
*/
11361136
pub fn set_exit_status(code: int) {
1137-
unsafe {
1138-
rustrt::rust_set_exit_status(code as libc::intptr_t);
1137+
use rt;
1138+
use rt::OldTaskContext;
1139+
1140+
if rt::context() == OldTaskContext {
1141+
unsafe {
1142+
rustrt::rust_set_exit_status(code as libc::intptr_t);
1143+
}
1144+
} else {
1145+
rt::util::set_exit_status(code);
11391146
}
11401147
}
11411148

branches/try2/src/libstd/rt/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,15 @@ pub fn run(main: ~fn()) -> int {
260260
}
261261

262262
unsafe {
263-
let exit_code = if exit_success { 0 } else { DEFAULT_ERROR_CODE };
263+
let exit_code = if exit_success {
264+
use rt::util;
265+
266+
// If we're exiting successfully, then return the global
267+
// exit status, which can be set programmatically.
268+
util::get_exit_status()
269+
} else {
270+
DEFAULT_ERROR_CODE
271+
};
264272
(*exit_code_clone.get()).store(exit_code, SeqCst);
265273
}
266274
};

branches/try2/src/libstd/rt/util.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,25 @@ memory and partly incapable of presentation to others.",
9797

9898
unsafe { libc::abort(); }
9999
}
100+
101+
pub fn set_exit_status(code: int) {
102+
103+
unsafe {
104+
return rust_set_exit_status_newrt(code as libc::uintptr_t);
105+
}
106+
107+
extern {
108+
fn rust_set_exit_status_newrt(code: libc::uintptr_t);
109+
}
110+
}
111+
112+
pub fn get_exit_status() -> int {
113+
114+
unsafe {
115+
return rust_get_exit_status_newrt() as int;
116+
}
117+
118+
extern {
119+
fn rust_get_exit_status_newrt() -> libc::uintptr_t;
120+
}
121+
}

branches/try2/src/rt/rust_builtin.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,21 @@ rust_get_global_args_ptr() {
960960
return &global_args_ptr;
961961
}
962962

963+
static lock_and_signal exit_status_lock;
964+
static uintptr_t exit_status = 0;
965+
966+
extern "C" CDECL void
967+
rust_set_exit_status_newrt(uintptr_t code) {
968+
scoped_lock with(exit_status_lock);
969+
exit_status = code;
970+
}
971+
972+
extern "C" CDECL uintptr_t
973+
rust_get_exit_status_newrt() {
974+
scoped_lock with(exit_status_lock);
975+
return exit_status;
976+
}
977+
963978
//
964979
// Local Variables:
965980
// mode: C++

branches/try2/src/rt/rustrt.def.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,5 @@ rust_get_global_args_ptr
270270
rust_current_boxed_region
271271
rust_take_global_args_lock
272272
rust_drop_global_args_lock
273+
rust_set_exit_status_newrt
274+
rust_get_exit_status_newrt

0 commit comments

Comments
 (0)