Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust the die macro to only accept ~str and to work in statement positi... #4154

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/libcore/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ use gc::{cleanup_stack_for_failure, gc, Word};
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;

Expand All @@ -47,11 +44,7 @@ extern mod rustrt {
// 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)]
Expand Down
29 changes: 28 additions & 1 deletion src/libcore/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -43,6 +43,11 @@ extern mod rusti {
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 {
Expand Down Expand Up @@ -108,6 +113,28 @@ pub pure fn log_str<T>(t: &T) -> ~str {
}
}

/** 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 {

Expand Down
15 changes: 2 additions & 13 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,21 +378,10 @@ fn core_macros() -> ~str {

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\")
)
)
}";
Expand Down
5 changes: 5 additions & 0 deletions src/test/compile-fail/die-not-unique.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error-pattern:mismatched types

fn main() {
die!("test");
}
5 changes: 5 additions & 0 deletions src/test/run-fail/die-macro-expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error-pattern:test

fn main() {
let i: int = die!(~"test");
}
9 changes: 9 additions & 0 deletions src/test/run-fail/die-macro-pure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// error-pattern:test

pure fn f() {
die!(~"test");
}

fn main() {
f();
}
5 changes: 5 additions & 0 deletions src/test/run-fail/die-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error-pattern:test

fn main() {
die!(~"test");
}
11 changes: 11 additions & 0 deletions src/test/run-pass/die-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Just testing that die!() type checks in statement or expr

fn f() {
die!();

let x: int = die!();
}

fn main() {

}