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

View File

@@ -475,8 +475,10 @@ static void *resizebox (lua_State *L, int idx, size_t newsize) {
lua_Alloc allocf = lua_getallocf(L, &ud);
UBox *box = (UBox *)lua_touserdata(L, idx);
void *temp = allocf(ud, box->box, box->bsize, newsize);
if (temp == NULL && newsize > 0) /* allocation error? */
luaL_error(L, "not enough memory");
if (temp == NULL && newsize > 0) { /* allocation error? */
lua_pushliteral(L, "not enough memory");
lua_error(L); /* raise a memory error */
}
box->box = temp;
box->bsize = newsize;
return temp;