@@ -36,6 +36,7 @@ use rt::logging::StdErrLogger;
36
36
use rt:: sched:: { Scheduler , SchedHandle } ;
37
37
use rt:: stack:: { StackSegment , StackPool } ;
38
38
use send_str:: SendStr ;
39
+ use task:: LinkedFailure ;
39
40
use task:: spawn:: Taskgroup ;
40
41
use unstable:: finally:: Finally ;
41
42
@@ -95,8 +96,8 @@ pub enum UnwindResult {
95
96
/// The task is ending successfully
96
97
Success ,
97
98
98
- /// The Task is failing with reason `UnwindMessage `
99
- Failure ( UnwindMessage ) ,
99
+ /// The Task is failing with reason `~Any `
100
+ Failure ( ~ Any ) ,
100
101
}
101
102
102
103
impl UnwindResult {
@@ -119,27 +120,9 @@ impl UnwindResult {
119
120
}
120
121
}
121
122
122
- /// Represents the cause of a task failure
123
- #[ deriving( ToStr ) ]
124
- pub enum UnwindMessage {
125
- // FIXME: #9913 - This variant is not neccessary once Any works properly
126
- /// Failed with a static string message
127
- UnwindMessageStrStatic ( & ' static str ) ,
128
-
129
- // FIXME: #9913 - This variant is not neccessary once Any works properly
130
- /// Failed with a owned string message
131
- UnwindMessageStrOwned ( ~str ) ,
132
-
133
- /// Failed with an `~Any`
134
- UnwindMessageAny ( ~Any ) ,
135
-
136
- /// Failed because of linked failure
137
- UnwindMessageLinked
138
- }
139
-
140
123
pub struct Unwinder {
141
124
unwinding : bool ,
142
- cause : Option < UnwindMessage >
125
+ cause : Option < ~ Any >
143
126
}
144
127
145
128
impl Unwinder {
@@ -532,7 +515,7 @@ impl Unwinder {
532
515
}
533
516
}
534
517
535
- pub fn begin_unwind ( & mut self , cause : UnwindMessage ) -> ! {
518
+ pub fn begin_unwind ( & mut self , cause : ~ Any ) -> ! {
536
519
#[ fixed_stack_segment] ; #[ inline( never) ] ;
537
520
538
521
self . unwinding = true ;
@@ -648,46 +631,34 @@ pub fn begin_unwind_raw(msg: *c_char, file: *c_char, line: size_t) -> ! {
648
631
649
632
/// This is the entry point of unwinding for fail!() and assert!().
650
633
pub fn begin_unwind < M : Any + Send > ( msg : M , file : & ' static str , line : uint ) -> ! {
651
- // Wrap the fail message in a `Any` box for uniform representation.
652
- let any = ~msg as ~Any ;
653
-
654
- // FIXME: #9913 - This can be changed to be internal to begin_unwind_internal
655
- // once Any works properly.
656
- // As a workaround, string types need to be special cased right now
657
- // because `Any` does not support dynamically querying whether the
658
- // type implements a trait yet, so without requiring that every `Any`
659
- // also implements `ToStr` there is no way to get a failure message
660
- // out of it again during unwinding.
661
- let msg = if any. is :: < & ' static str > ( ) {
662
- UnwindMessageStrStatic ( * any. move :: < & ' static str > ( ) . unwrap ( ) )
663
- } else if any. is :: < ~str > ( ) {
664
- UnwindMessageStrOwned ( * any. move :: < ~str > ( ) . unwrap ( ) )
665
- } else {
666
- UnwindMessageAny ( any)
667
- } ;
668
-
669
- begin_unwind_internal ( msg, file, line)
670
- }
671
-
672
- fn begin_unwind_internal ( msg : UnwindMessage , file : & ' static str , line : uint ) -> ! {
634
+ use any:: AnyRefExt ;
673
635
use rt:: in_green_task_context;
674
- use rt:: task:: Task ;
675
636
use rt:: local:: Local ;
637
+ use rt:: task:: Task ;
676
638
use str:: Str ;
677
639
use unstable:: intrinsics;
678
640
679
641
unsafe {
680
- // Be careful not to allocate in this block, if we're failing we may
681
- // have been failing due to a lack of memory in the first place...
682
-
683
642
let task: * mut Task ;
643
+ // Note that this should be the only allocation performed in this block.
644
+ // Currently this means that fail!() on OOM will invoke this code path,
645
+ // but then again we're not really ready for failing on OOM anyway. If
646
+ // we do start doing this, then we should propagate this allocation to
647
+ // be performed in the parent of this task instead of the task that's
648
+ // failing.
649
+ let msg = ~msg as ~Any ;
684
650
685
651
{
686
- let msg_s = match msg {
687
- UnwindMessageAny ( _) => "~Any" ,
688
- UnwindMessageLinked => "linked failure" ,
689
- UnwindMessageStrOwned ( ref s) => s. as_slice ( ) ,
690
- UnwindMessageStrStatic ( ref s) => s. as_slice ( ) ,
652
+ //let msg: &Any = msg;
653
+ let msg_s = match msg. as_ref :: < & ' static str > ( ) {
654
+ Some ( s) => * s,
655
+ None => match msg. as_ref :: < ~str > ( ) {
656
+ Some ( s) => s. as_slice ( ) ,
657
+ None => match msg. as_ref :: < LinkedFailure > ( ) {
658
+ Some ( * ) => "linked failure" ,
659
+ None => "~Any" ,
660
+ }
661
+ }
691
662
} ;
692
663
693
664
if !in_green_task_context ( ) {
0 commit comments