diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-29 16:02:44 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-29 16:02:44 -0200 |
commit | 6d04537ea660fd12fc16c328366b701fabaf4919 (patch) | |
tree | 41eab6e4d87552e29731db552f7d58d679c56973 /lfunc.c | |
parent | 7696c6474fe51ed59fee324e78c1233af74febdd (diff) | |
download | lua-6d04537ea660fd12fc16c328366b701fabaf4919.tar.gz lua-6d04537ea660fd12fc16c328366b701fabaf4919.tar.bz2 lua-6d04537ea660fd12fc16c328366b701fabaf4919.zip |
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.)
Diffstat (limited to 'lfunc.c')
-rw-r--r-- | lfunc.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -14,6 +14,7 @@ | |||
14 | 14 | ||
15 | #include "lua.h" | 15 | #include "lua.h" |
16 | 16 | ||
17 | #include "ldebug.h" | ||
17 | #include "ldo.h" | 18 | #include "ldo.h" |
18 | #include "lfunc.h" | 19 | #include "lfunc.h" |
19 | #include "lgc.h" | 20 | #include "lgc.h" |
@@ -140,6 +141,11 @@ static int closeupval (lua_State *L, TValue *uv, StkId level, int status) { | |||
140 | if (likely(status == LUA_OK)) { | 141 | if (likely(status == LUA_OK)) { |
141 | if (prepclosingmethod(L, uv, &G(L)->nilvalue)) /* something to call? */ | 142 | if (prepclosingmethod(L, uv, &G(L)->nilvalue)) /* something to call? */ |
142 | callclose(L, NULL); /* call closing method */ | 143 | callclose(L, NULL); /* call closing method */ |
144 | else if (!ttisnil(uv)) { /* non-closable non-nil value? */ | ||
145 | const char *vname = luaG_findlocal(L, L->ci, level - L->ci->func, NULL); | ||
146 | if (vname == NULL) vname = "?"; | ||
147 | luaG_runerror(L, "attempt to close non-closable variable '%s'", vname); | ||
148 | } | ||
143 | } | 149 | } |
144 | else { /* there was an error */ | 150 | else { /* there was an error */ |
145 | /* save error message and set stack top to 'level + 1' */ | 151 | /* save error message and set stack top to 'level + 1' */ |