lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Quae Quack schrieb:
> The stock lua implementation's xpcall doesn't handle an error in the
> error handler how you'd think: it keeps calling itself until it blows
> the stack.
> The expected behaviour would be to propogate the error up to the next
> protected call (IMO)
> luajit doesn't recursivly call xpcall, but the xpcall instead just
> returns "error in error handling".
> 
> lhf has said the bug still happens in 5.2

I tried a small patch (see attachment). With this patch xpcall would
return the error that was raised in the error handler.

lua_pcall (the C function) returns LUA_ERRRUN instead of LUA_ERRERR, but
this way it was easier to do and you actually get the error message from
the handler. (Else it would get overwritten by "error in error handling").

I didn't test it intensively, so there might be something I missed.

-- David

--- lua-5.1.4/src/ldebug.c	2008-05-08 18:56:26.000000000 +0200
+++ lua-5.1.4-errerr/src/ldebug.c	2010-10-07 12:00:13.000000000 +0200
@@ -618,6 +618,7 @@
 void luaG_errormsg (lua_State *L) {
   if (L->errfunc != 0) {  /* is there an error handling function? */
     StkId errfunc = restorestack(L, L->errfunc);
+    L->errfunc = 0; /* prevent stack overflow for errors in the error handler */
     if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
     setobjs2s(L, L->top, L->top - 1);  /* move argument */
     setobjs2s(L, L->top - 1, errfunc);  /* push function */