@@ -125,37 +125,56 @@ impl FailWithCause for &'static str {
125125 }
126126}
127127
128- // FIXME #4427: Temporary until rt::rt_fail_ goes away
128+ // This stage0 version is incredibly wrong.
129+ #[ cfg( stage0) ]
129130pub fn begin_unwind_ ( msg : * c_char , file : * c_char , line : size_t ) -> ! {
130131 use option:: { Some , None } ;
131132 use rt:: in_green_task_context;
132133 use rt:: task:: Task ;
133134 use rt:: local:: Local ;
134135 use rt:: logging:: Logger ;
135- use send_str:: SendStrOwned ;
136+ use str:: Str ;
137+
138+ unsafe {
139+ let msg = str:: raw:: from_c_str ( msg) ;
140+ let file = str:: raw:: from_c_str ( file) ;
141+ if in_green_task_context ( ) {
142+ rterrln ! ( "task failed at '%s', %s:%i" , msg, file, line as int) ;
143+ } else {
144+ rterrln ! ( "failed in non-task context at '%s', %s:%i" ,
145+ msg, file, line as int) ;
146+ }
147+
148+ let task: * mut Task = Local :: unsafe_borrow ( ) ;
149+ if ( * task) . unwinder . unwinding {
150+ rtabort ! ( "unwinding again" ) ;
151+ }
152+ ( * task) . unwinder . begin_unwind ( ) ;
153+ }
154+ }
155+
156+ // FIXME #4427: Temporary until rt::rt_fail_ goes away
157+ #[ cfg( not( stage0) ) ]
158+ pub fn begin_unwind_ ( msg : * c_char , file : * c_char , line : size_t ) -> ! {
159+ use rt:: in_green_task_context;
160+ use rt:: task:: Task ;
161+ use rt:: local:: Local ;
162+ use rt:: logging:: Logger ;
136163 use str:: Str ;
137164
138165 unsafe {
139166 // XXX: Bad re-allocations. fail! needs some refactoring
140167 let msg = str:: raw:: from_c_str ( msg) ;
141168 let file = str:: raw:: from_c_str ( file) ;
142169
143- // XXX: Logging doesn't work correctly in non-task context because it
144- // invokes the local heap
145170 if in_green_task_context ( ) {
146- // XXX: Logging doesn't work here - the check to call the log
147- // function never passes - so calling the log function directly .
171+ // Be careful not to allocate in this block, if we're failing we may
172+ // have been failing due to a lack of memory in the first place.. .
148173 do Local :: borrow |task: & mut Task | {
149- let msg = match task. name {
150- Some ( ref name) =>
151- fmt ! ( "task '%s' failed at '%s', %s:%i" ,
152- name. as_slice( ) , msg, file, line as int) ,
153- None =>
154- fmt ! ( "task <unnamed> failed at '%s', %s:%i" ,
155- msg, file, line as int)
156- } ;
157-
158- task. logger . log ( SendStrOwned ( msg) ) ;
174+ let n = task. name . map ( |n| n. as_slice ( ) ) . unwrap_or ( "<unnamed>" ) ;
175+ format_args ! ( |args| { task. logger. log( args) } ,
176+ "task '{}' failed at '{}', {}:{}" ,
177+ n, msg. as_slice( ) , file. as_slice( ) , line) ;
159178 }
160179 } else {
161180 rterrln ! ( "failed in non-task context at '%s', %s:%i" ,
0 commit comments