Adjust the die macro to only accept ~str and to work in statement position

This commit is contained in:
Brian Anderson
2012-12-10 17:22:10 -08:00
parent ed686aeac4
commit 3fcdb7d6a7
8 changed files with 66 additions and 22 deletions
+1 -8
View File
@@ -26,9 +26,6 @@
pub type rust_task = c_void;
extern mod rustrt {
#[rust_stack]
fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t);
#[rust_stack]
fn rust_upcall_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char;
@@ -47,11 +44,7 @@
// gather_rust_rtcalls.
#[rt(fail_)]
pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
unsafe {
cleanup_stack_for_failure();
rustrt::rust_upcall_fail(expr, file, line);
cast::transmute(())
}
sys::begin_unwind_(expr, file, line);
}
#[rt(fail_bounds_check)]
+28 -1
View File
@@ -15,7 +15,7 @@
#[forbid(deprecated_pattern)];
use cmp::{Eq, Ord};
use libc::c_void;
use libc::{c_void, c_char, size_t};
pub type FreeGlue = fn(*TypeDesc, *c_void);
@@ -43,6 +43,11 @@ pub struct Closure {
fn min_align_of<T>() -> uint;
}
extern mod rustrt {
#[rust_stack]
fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t);
}
/// Compares contents of two pointers using the default method.
/// Equivalent to `*x1 == *x2`. Useful for hashtables.
pub pure fn shape_eq<T:Eq>(x1: &T, x2: &T) -> bool {
@@ -108,6 +113,28 @@ pub struct Closure {
}
}
/** Initiate task failure */
pub pure fn begin_unwind(msg: ~str, file: ~str, line: uint) -> ! {
do str::as_buf(msg) |msg_buf, _msg_len| {
do str::as_buf(file) |file_buf, _file_len| {
unsafe {
let msg_buf = cast::transmute(msg_buf);
let file_buf = cast::transmute(file_buf);
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
}
}
}
}
// XXX: Temorary until rt::rt_fail_ goes away
pub pure fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
unsafe {
gc::cleanup_stack_for_failure();
rustrt::rust_upcall_fail(msg, file, line);
cast::transmute(())
}
}
#[cfg(test)]
pub mod tests {
+2 -13
View File
@@ -378,21 +378,10 @@ macro_rules! debug ( ($( $arg:expr ),+) => (
macro_rules! die(
($msg: expr) => (
{
do core::str::as_buf($msg) |msg_buf, _msg_len| {
do core::str::as_buf(file!()) |file_buf, _file_len| {
unsafe {
let msg_buf = core::cast::transmute(msg_buf);
let file_buf = core::cast::transmute(file_buf);
let line = line!() as core::libc::size_t;
core::rt::rt_fail_(msg_buf, file_buf, line)
}
}
}
}
core::sys::begin_unwind($msg, file!(), line!())
);
() => (
die!(\"explicit failure\")
die!(~\"explicit failure\")
)
)
}";
+5
View File
@@ -0,0 +1,5 @@
// error-pattern:mismatched types
fn main() {
die!("test");
}
+5
View File
@@ -0,0 +1,5 @@
// error-pattern:test
fn main() {
let i: int = die!(~"test");
}
+9
View File
@@ -0,0 +1,9 @@
// error-pattern:test
pure fn f() {
die!(~"test");
}
fn main() {
f();
}
+5
View File
@@ -0,0 +1,5 @@
// error-pattern:test
fn main() {
die!(~"test");
}
+11
View File
@@ -0,0 +1,11 @@
// Just testing that die!() type checks in statement or expr
fn f() {
die!();
let x: int = die!();
}
fn main() {
}