From 6d04537ea660fd12fc16c328366b701fabaf4919 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 29 Nov 2018 16:02:44 -0200 Subject: A to-be-closed variable must have a closable value (or be nil) It is an error for a to-be-closed variable to have a non-closable non-nil value when it is being closed. This situation does not seem to be useful and often hints to an error. (Particularly in the C API, it is easy to change a to-be-closed index by mistake.) --- lvm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lvm.c') diff --git a/lvm.c b/lvm.c index a6dcc9ff..50d967c6 100644 --- a/lvm.c +++ b/lvm.c @@ -1427,7 +1427,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } vmcase(OP_CLOSE) { L->top = ra + 1; /* everything is free after this slot */ - ProtectNT(luaF_close(L, ra, LUA_OK)); + Protect(luaF_close(L, ra, LUA_OK)); vmbreak; } vmcase(OP_TBC) { @@ -1717,9 +1717,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_TFORPREP) { - /* is 'toclose' a function or has a '__close' metamethod? */ - if (ttisfunction(s2v(ra + 3)) || - !ttisnil(luaT_gettmbyobj(L, s2v(ra + 3), TM_CLOSE))) { + /* is 'toclose' not nil? */ + if (!ttisnil(s2v(ra + 3))) { /* create to-be-closed upvalue for it */ halfProtect(luaF_newtbcupval(L, ra + 3)); } -- cgit v1.2.3-55-g6feb