Skip to content

Commit 29ad8e1

Browse files
committed
std::rt: Improve the rtabort! macro
1 parent 5b2dc52 commit 29ad8e1

File tree

3 files changed

+72
-15
lines changed

3 files changed

+72
-15
lines changed

src/libstd/macros.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@
1010

1111
#[macro_escape];
1212

13+
macro_rules! rterrln (
14+
($( $arg:expr),+) => ( {
15+
::rt::util::dumb_println(fmt!( $($arg),+ ));
16+
} )
17+
)
18+
1319
// Some basic logging
1420
macro_rules! rtdebug_ (
1521
($( $arg:expr),+) => ( {
16-
dumb_println(fmt!( $($arg),+ ));
17-
18-
fn dumb_println(s: &str) {
19-
use io::WriterUtil;
20-
let dbg = ::libc::STDERR_FILENO as ::io::fd_t;
21-
dbg.write_str(s);
22-
dbg.write_str("\n");
23-
}
24-
22+
rterrln!( $($arg),+ )
2523
} )
2624
)
2725

@@ -41,8 +39,7 @@ macro_rules! rtassert (
4139

4240
macro_rules! rtabort(
4341
($( $msg:expr),+) => ( {
44-
rtdebug!($($msg),+);
45-
::rt::util::abort();
42+
::rt::util::abort(fmt!($($msg),+));
4643
} )
4744
)
4845

src/libstd/rt/global_heap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ pub fn cleanup() {
8282
let count_ptr = exchange_count_ptr();
8383
let allocations = atomic_load(&*count_ptr);
8484
if allocations != 0 {
85-
rtabort!("exchange heap not empty on exit\
86-
%i dangling allocations", allocations);
85+
rtabort!("exchange heap not empty on exit - %i dangling allocations", allocations);
8786
}
8887
}
8988
}

src/libstd/rt/util.rs

+63-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use container::Container;
12+
use iterator::IteratorUtil;
1113
use libc;
14+
use str::StrSlice;
1215

1316
/// Get the number of cores available
1417
pub fn num_cpus() -> uint {
@@ -21,6 +24,64 @@ pub fn num_cpus() -> uint {
2124
}
2225
}
2326

24-
pub fn abort() -> ! {
27+
pub fn dumb_println(s: &str) {
28+
use io::WriterUtil;
29+
let dbg = ::libc::STDERR_FILENO as ::io::fd_t;
30+
dbg.write_str(s);
31+
dbg.write_str("\n");
32+
}
33+
34+
pub fn abort(msg: &str) -> ! {
35+
let msg = if !msg.is_empty() { msg } else { "aborted" };
36+
let hash = msg.iter().fold(0, |accum, val| accum + (val as uint) );
37+
let quote = match hash % 10 {
38+
0 => "
39+
It was from the artists and poets that the pertinent answers came, and I
40+
know that panic would have broken loose had they been able to compare notes.
41+
As it was, lacking their original letters, I half suspected the compiler of
42+
having asked leading questions, or of having edited the correspondence in
43+
corroboration of what he had latently resolved to see.",
44+
1 => "
45+
There are not many persons who know what wonders are opened to them in the
46+
stories and visions of their youth; for when as children we listen and dream,
47+
we think but half-formed thoughts, and when as men we try to remember, we are
48+
dulled and prosaic with the poison of life. But some of us awake in the night
49+
with strange phantasms of enchanted hills and gardens, of fountains that sing
50+
in the sun, of golden cliffs overhanging murmuring seas, of plains that stretch
51+
down to sleeping cities of bronze and stone, and of shadowy companies of heroes
52+
that ride caparisoned white horses along the edges of thick forests; and then
53+
we know that we have looked back through the ivory gates into that world of
54+
wonder which was ours before we were wise and unhappy.",
55+
2 => "
56+
Instead of the poems I had hoped for, there came only a shuddering blackness
57+
and ineffable loneliness; and I saw at last a fearful truth which no one had
58+
ever dared to breathe before — the unwhisperable secret of secrets — The fact
59+
that this city of stone and stridor is not a sentient perpetuation of Old New
60+
York as London is of Old London and Paris of Old Paris, but that it is in fact
61+
quite dead, its sprawling body imperfectly embalmed and infested with queer
62+
animate things which have nothing to do with it as it was in life.",
63+
3 => "
64+
The ocean ate the last of the land and poured into the smoking gulf, thereby
65+
giving up all it had ever conquered. From the new-flooded lands it flowed
66+
again, uncovering death and decay; and from its ancient and immemorial bed it
67+
trickled loathsomely, uncovering nighted secrets of the years when Time was
68+
young and the gods unborn. Above the waves rose weedy remembered spires. The
69+
moon laid pale lilies of light on dead London, and Paris stood up from its damp
70+
grave to be sanctified with star-dust. Then rose spires and monoliths that were
71+
weedy but not remembered; terrible spires and monoliths of lands that men never
72+
knew were lands...",
73+
4 => "
74+
There was a night when winds from unknown spaces whirled us irresistibly into
75+
limitless vacum beyond all thought and entity. Perceptions of the most
76+
maddeningly untransmissible sort thronged upon us; perceptions of infinity
77+
which at the time convulsed us with joy, yet which are now partly lost to my
78+
memory and partly incapable of presentation to others.",
79+
_ => "You've met with a terrible fate, haven't you?"
80+
};
81+
rterrln!("%s", "");
82+
rterrln!("%s", quote);
83+
rterrln!("%s", "");
84+
rterrln!("fatal runtime error: %s", msg);
85+
2586
unsafe { libc::abort(); }
26-
}
87+
}

0 commit comments

Comments
 (0)