summaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorkyren <kerriganw@gmail.com>2017-07-27 17:16:40 -0400
committerkyren <kerriganw@gmail.com>2017-07-27 17:16:40 -0400
commitd415455ccb9789753d76f5e37a92d0dce2bca0bf (patch)
tree98665daf09053a62aa472e5b0413982331ec048d /src/util.rs
parenta2b77f37a232a487582c72030c1d625ba39a808f (diff)
downloadmlua-d415455ccb9789753d76f5e37a92d0dce2bca0bf.zip
Fix several bugs with error handling in xxx_with_traceback functions
In resume_with_traceback, always use the coroutine stack for error handling so we don't miss panics, in both _with_traceback functions remove the temporary traceback entry from the stack.
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/util.rs b/src/util.rs
index 7808fd2..2cc56ed 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -381,6 +381,7 @@ pub unsafe fn pcall_with_traceback(
.unwrap_or_else(|_| "<could not capture traceback>")
.to_owned();
push_wrapped_error(state, Error::CallbackError(traceback, Arc::new(error)));
+ ffi::lua_remove(state, -2);
} else if !is_wrapped_panic(state, 1) {
let s = ffi::lua_tolstring(state, 1, ptr::null_mut());
if !s.is_null() {
@@ -388,6 +389,7 @@ pub unsafe fn pcall_with_traceback(
} else {
ffi::luaL_traceback(state, state, cstr!("<unprintable lua error>"), 0);
}
+ ffi::lua_remove(state, -2);
}
1
}
@@ -408,19 +410,21 @@ pub unsafe fn resume_with_traceback(
let res = ffi::lua_resume(state, from, nargs);
if res != ffi::LUA_OK && res != ffi::LUA_YIELD {
if let Some(error) = pop_wrapped_error(state) {
- ffi::luaL_traceback(from, state, ptr::null(), 0);
- let traceback = CStr::from_ptr(ffi::lua_tolstring(from, -1, ptr::null_mut()))
+ ffi::luaL_traceback(state, state, ptr::null(), 0);
+ let traceback = CStr::from_ptr(ffi::lua_tolstring(state, -1, ptr::null_mut()))
.to_str()
.unwrap_or_else(|_| "<could not capture traceback>")
.to_owned();
- push_wrapped_error(from, Error::CallbackError(traceback, Arc::new(error)));
+ push_wrapped_error(state, Error::CallbackError(traceback, Arc::new(error)));
+ ffi::lua_remove(state, -2);
} else if !is_wrapped_panic(state, 1) {
let s = ffi::lua_tolstring(state, 1, ptr::null_mut());
if !s.is_null() {
- ffi::luaL_traceback(from, state, s, 0);
+ ffi::luaL_traceback(state, state, s, 0);
} else {
- ffi::luaL_traceback(from, state, cstr!("<unprintable lua error>"), 0);
+ ffi::luaL_traceback(state, state, cstr!("<unprintable lua error>"), 0);
}
+ ffi::lua_remove(state, -2);
}
}
res