forked from M-Labs/artiq
1
0
Fork 0

ksupport: raise RuntimeError on reraise with no inflight exception.

Fixes #1123.
This commit is contained in:
whitequark 2018-08-07 05:53:13 +00:00
parent 2008d02f4d
commit a74958f01f
5 changed files with 25 additions and 7 deletions

View File

@ -169,6 +169,9 @@ def fn_ValueError():
def fn_ZeroDivisionError(): def fn_ZeroDivisionError():
return types.TExceptionConstructor(TException("ZeroDivisionError")) return types.TExceptionConstructor(TException("ZeroDivisionError"))
def fn_RuntimeError():
return types.TExceptionConstructor(TException("RuntimeError"))
def fn_range(): def fn_range():
return types.TBuiltinFunction("range") return types.TBuiltinFunction("range")

View File

@ -447,7 +447,7 @@ class CommKernel:
self._write_string(function) self._write_string(function)
else: else:
exn_type = type(exn) exn_type = type(exn)
if exn_type in (ZeroDivisionError, ValueError, IndexError) or \ if exn_type in (ZeroDivisionError, ValueError, IndexError, RuntimeError) or \
hasattr(exn, "artiq_builtin"): hasattr(exn, "artiq_builtin"):
self._write_string("0:{}".format(exn_type.__name__)) self._write_string("0:{}".format(exn_type.__name__))
else: else:

View File

@ -10,6 +10,7 @@ from artiq.coredevice.runtime import source_loader
ZeroDivisionError = builtins.ZeroDivisionError ZeroDivisionError = builtins.ZeroDivisionError
ValueError = builtins.ValueError ValueError = builtins.ValueError
IndexError = builtins.IndexError IndexError = builtins.IndexError
RuntimeError = builtins.RuntimeError
class CoreException: class CoreException:

View File

@ -392,7 +392,7 @@ static mut INFLIGHT: ExceptionInfo = ExceptionInfo {
private: [0; uw::unwinder_private_data_size], private: [0; uw::unwinder_private_data_size],
}, },
exception: None, exception: None,
handled: false, handled: true,
backtrace: [0; MAX_BACKTRACE_SIZE], backtrace: [0; MAX_BACKTRACE_SIZE],
backtrace_size: 0 backtrace_size: 0
}; };
@ -418,8 +418,22 @@ pub unsafe extern fn raise(exception: *const Exception) -> ! {
#[export_name="__artiq_reraise"] #[export_name="__artiq_reraise"]
#[unwind(allowed)] #[unwind(allowed)]
pub unsafe extern fn reraise() -> ! { pub unsafe extern fn reraise() -> ! {
use cslice::AsCSlice;
if INFLIGHT.handled { if INFLIGHT.handled {
raise(&INFLIGHT.exception.unwrap()) match INFLIGHT.exception {
Some(ref exception) => raise(exception),
None => raise(&Exception {
name: "0:artiq.coredevice.exceptions.RuntimeError".as_c_slice(),
file: file!().as_c_slice(),
line: line!(),
column: column!(),
// https://github.com/rust-lang/rfcs/pull/1719
function: "__artiq_reraise".as_c_slice(),
message: "No active exception to reraise".as_c_slice(),
param: [0, 0, 0]
})
}
} else { } else {
uw::_Unwind_Resume(&mut INFLIGHT.uw_exception) uw::_Unwind_Resume(&mut INFLIGHT.uw_exception)
} }

View File

@ -68,13 +68,13 @@ macro_rules! raise {
($name:expr, $message:expr, $param0:expr, $param1:expr, $param2:expr) => ({ ($name:expr, $message:expr, $param0:expr, $param1:expr, $param2:expr) => ({
use cslice::AsCSlice; use cslice::AsCSlice;
let exn = $crate::eh::Exception { let exn = $crate::eh::Exception {
name: concat!("0:artiq.coredevice.exceptions.", $name).as_bytes().as_c_slice(), name: concat!("0:artiq.coredevice.exceptions.", $name).as_c_slice(),
file: file!().as_bytes().as_c_slice(), file: file!().as_c_slice(),
line: line!(), line: line!(),
column: column!(), column: column!(),
// https://github.com/rust-lang/rfcs/pull/1719 // https://github.com/rust-lang/rfcs/pull/1719
function: "(Rust function)".as_bytes().as_c_slice(), function: "(Rust function)".as_c_slice(),
message: $message.as_bytes().as_c_slice(), message: $message.as_c_slice(),
param: [$param0, $param1, $param2] param: [$param0, $param1, $param2]
}; };
#[allow(unused_unsafe)] #[allow(unused_unsafe)]