Skip to content

Commit 6d41d9a

Browse files
committed
---
yaml --- r: 64154 b: refs/heads/snap-stage3 c: 07e52eb h: refs/heads/master v: v3
1 parent 5167648 commit 6d41d9a

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ec6d4a1733b07d4cc561eda7463ad596a9d52bf0
4+
refs/heads/snap-stage3: 07e52eb7fc75466d294a1fd9d614f5e0276ab834
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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/snap-stage3/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/snap-stage3/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/snap-stage3/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/snap-stage3/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)