aboutsummaryrefslogtreecommitdiff
path: root/lfunc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lfunc.c')
-rw-r--r--lfunc.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lfunc.c b/lfunc.c
index 11d2850f..bdf3cd25 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -127,17 +127,18 @@ static int prepclosingmethod (lua_State *L, TValue *obj, TValue *err) {
127 127
128 128
129/* 129/*
130** Prepare and call a closing method. If status is OK, code is 130** Prepare and call a closing method. If status is OK, code is still
131** still inside the original protected call, and so any error 131** inside the original protected call, and so any error will be handled
132** will be handled there. Otherwise, a previous error already 132** there. Otherwise, a previous error already activated original
133** activated original protected call, and so the call to the 133** protected call, and so the call to the closing method must be
134** closing method must be protected here. 134** protected here. (A status = CLOSEPROTECT behaves like a previous
135** error, to also run the closing method in protected mode).
135** If status is OK, the call to the closing method will be pushed 136** If status is OK, the call to the closing method will be pushed
136** at the top of the stack. Otherwise, values are pushed after 137** at the top of the stack. Otherwise, values are pushed after
137** the 'level' of the upvalue being closed, as everything after 138** the 'level' of the upvalue being closed, as everything after
138** that won't be used again. 139** that won't be used again.
139*/ 140*/
140static int closeupval (lua_State *L, TValue *uv, StkId level, int status) { 141static int callclosemth (lua_State *L, TValue *uv, StkId level, int status) {
141 if (likely(status == LUA_OK)) { 142 if (likely(status == LUA_OK)) {
142 if (prepclosingmethod(L, uv, &G(L)->nilvalue)) /* something to call? */ 143 if (prepclosingmethod(L, uv, &G(L)->nilvalue)) /* something to call? */
143 callclose(L, NULL); /* call closing method */ 144 callclose(L, NULL); /* call closing method */
@@ -207,9 +208,10 @@ int luaF_close (lua_State *L, StkId level, int status) {
207 if (!iswhite(uv)) 208 if (!iswhite(uv))
208 gray2black(uv); /* closed upvalues cannot be gray */ 209 gray2black(uv); /* closed upvalues cannot be gray */
209 luaC_barrier(L, uv, slot); 210 luaC_barrier(L, uv, slot);
210 if (status >= 0 && uv->tt == LUA_TUPVALTBC) { /* must be closed? */ 211 if (uv->tt == LUA_TUPVALTBC && status != NOCLOSINGMETH) {
212 /* must run closing method */
211 ptrdiff_t levelrel = savestack(L, level); 213 ptrdiff_t levelrel = savestack(L, level);
212 status = closeupval(L, uv->v, upl, status); /* may realloc. the stack */ 214 status = callclosemth(L, uv->v, upl, status); /* may change the stack */
213 level = restorestack(L, levelrel); 215 level = restorestack(L, levelrel);
214 } 216 }
215 } 217 }