2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-08-06 14:32:30 -07:00
|
|
|
// xfail-test linked failure
|
2012-02-14 00:43:45 -08:00
|
|
|
// error-pattern:explicit failure
|
|
|
|
// Testing that runtime failure doesn't cause callbacks to abort abnormally.
|
|
|
|
// Instead the failure will be delivered after the callbacks return.
|
|
|
|
|
2013-05-24 19:35:29 -07:00
|
|
|
use std::libc;
|
|
|
|
use std::task;
|
2013-04-24 20:35:49 -04:00
|
|
|
|
2013-03-05 14:42:58 -08:00
|
|
|
mod rustrt {
|
2013-05-24 19:35:29 -07:00
|
|
|
use std::libc;
|
|
|
|
|
2013-07-18 19:08:57 -07:00
|
|
|
extern {
|
2013-03-05 14:42:58 -08:00
|
|
|
pub fn rust_dbg_call(cb: *u8, data: libc::uintptr_t)
|
2013-07-18 19:08:57 -07:00
|
|
|
-> libc::uintptr_t;
|
2013-03-05 14:42:58 -08:00
|
|
|
}
|
2012-02-14 00:43:45 -08:00
|
|
|
}
|
|
|
|
|
2012-07-03 16:32:02 -07:00
|
|
|
extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
2012-02-14 00:43:45 -08:00
|
|
|
if data == 1u {
|
|
|
|
data
|
|
|
|
} else {
|
|
|
|
count(data - 1u) + count(data - 1u)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn count(n: uint) -> uint {
|
2013-01-23 16:29:31 -08:00
|
|
|
unsafe {
|
2013-08-16 12:49:40 -07:00
|
|
|
task::deschedule();
|
2013-01-23 16:29:31 -08:00
|
|
|
rustrt::rust_dbg_call(cb, n)
|
|
|
|
}
|
2012-02-14 00:43:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2013-08-01 04:18:19 +02:00
|
|
|
do 10u.times {
|
2012-07-04 15:04:28 -04:00
|
|
|
do task::spawn {
|
2012-02-14 00:43:45 -08:00
|
|
|
let result = count(5u);
|
2013-07-17 03:08:08 +10:00
|
|
|
info!("result = %?", result);
|
2013-09-29 21:08:46 -07:00
|
|
|
fail2!();
|
2012-02-14 00:43:45 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|