Keep memory errors as memory errors

Allow memory errors to be raised through the API (throwing the
error with the memory error message); error in external allocations
raises a memory error; memory errors in coroutines are re-raised
as memory errors.
This commit is contained in:
Roberto Ierusalimschy
2020-07-06 12:09:44 -03:00
parent bfcf06d91a
commit b57574d6fb
4 changed files with 75 additions and 23 deletions

8
lapi.c
View File

@@ -1195,9 +1195,15 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
LUA_API int lua_error (lua_State *L) {
TValue *errobj;
lua_lock(L);
errobj = s2v(L->top - 1);
api_checknelems(L, 1);
luaG_errormsg(L);
/* error object is the memory error message? */
if (ttisshrstring(errobj) && eqshrstr(tsvalue(errobj), G(L)->memerrmsg))
luaM_error(L); /* raise a memory error */
else
luaG_errormsg(L); /* raise a regular error */
/* code unreachable; will unlock when control actually leaves the kernel */
return 0; /* to avoid warnings */
}