lua_abort / lua_internal_abort macros
This commit is contained in:
parent
1426bdbc16
commit
9e3374ff9e
|
@ -51,8 +51,7 @@ impl Drop for Lua {
|
||||||
if cfg!(test) {
|
if cfg!(test) {
|
||||||
let top = ffi::lua_gettop(self.state);
|
let top = ffi::lua_gettop(self.state);
|
||||||
if top != 0 {
|
if top != 0 {
|
||||||
eprintln!("Lua stack leak detected, stack top is {}", top);
|
lua_internal_abort!("Lua stack leak detected, stack top is {}", top);
|
||||||
process::abort()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -894,8 +893,7 @@ impl Lua {
|
||||||
// not really a huge loss. Importantly, this allows us to turn off the gc, and
|
// not really a huge loss. Importantly, this allows us to turn off the gc, and
|
||||||
// then know that calling Lua API functions marked as 'm' will not result in a
|
// then know that calling Lua API functions marked as 'm' will not result in a
|
||||||
// 'longjmp' error while the gc is off.
|
// 'longjmp' error while the gc is off.
|
||||||
eprintln!("Out of memory in Lua allocation, aborting!");
|
lua_abort!("out of memory in Lua allocation, aborting!");
|
||||||
process::abort()
|
|
||||||
} else {
|
} else {
|
||||||
p as *mut c_void
|
p as *mut c_void
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,22 @@ macro_rules! lua_assert {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! lua_abort {
|
||||||
|
($msg:expr) => {
|
||||||
|
{
|
||||||
|
eprintln!($msg);
|
||||||
|
::std::process::abort()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
($msg:expr, $($arg:tt)+) => {
|
||||||
|
{
|
||||||
|
eprintln!($msg, $($arg)+);
|
||||||
|
::std::process::abort()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! lua_internal_panic {
|
macro_rules! lua_internal_panic {
|
||||||
($state:expr, $msg:expr) => {
|
($state:expr, $msg:expr) => {
|
||||||
lua_panic!($state, concat!("rlua internal error: ", $msg));
|
lua_panic!($state, concat!("rlua internal error: ", $msg));
|
||||||
|
@ -57,3 +73,17 @@ macro_rules! lua_internal_assert {
|
||||||
lua_assert!($state, $cond, concat!("rlua internal error: ", $msg), $($arg)+);
|
lua_assert!($state, $cond, concat!("rlua internal error: ", $msg), $($arg)+);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! lua_internal_abort {
|
||||||
|
($msg:expr) => {
|
||||||
|
{
|
||||||
|
lua_abort!(concat!("rlua internal error: ", $msg));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
($msg:expr, $($arg:tt)+) => {
|
||||||
|
{
|
||||||
|
lua_abort!(concat!("rlua internal error, aborting!: ", $msg), $($arg)+);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -226,8 +226,7 @@ pub unsafe fn pop_error(state: *mut ffi::lua_State, err_code: c_int) -> Error {
|
||||||
ffi::LUA_ERRMEM => {
|
ffi::LUA_ERRMEM => {
|
||||||
// This should be impossible, as we set the lua allocator to one that aborts
|
// This should be impossible, as we set the lua allocator to one that aborts
|
||||||
// instead of failing.
|
// instead of failing.
|
||||||
eprintln!("impossible Lua allocation error, aborting!");
|
lua_internal_abort!("impossible Lua allocation error, aborting!")
|
||||||
process::abort()
|
|
||||||
}
|
}
|
||||||
ffi::LUA_ERRGCMM => Error::GarbageCollectorError(err_string),
|
ffi::LUA_ERRGCMM => Error::GarbageCollectorError(err_string),
|
||||||
_ => lua_internal_panic!(state, "unrecognized lua error code"),
|
_ => lua_internal_panic!(state, "unrecognized lua error code"),
|
||||||
|
|
Loading…
Reference in New Issue