diff options
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 25 |
1 files changed, 10 insertions, 15 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.260 2017/02/23 21:07:34 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.261 2017/04/06 13:08:56 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1004,7 +1004,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
1004 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | 1004 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); |
1005 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ | 1005 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
1006 | setobj(L, f->upvals[0]->v, gt); | 1006 | setobj(L, f->upvals[0]->v, gt); |
1007 | luaC_upvalbarrier(L, f->upvals[0], gt); | 1007 | luaC_barrier(L, f->upvals[0], gt); |
1008 | } | 1008 | } |
1009 | } | 1009 | } |
1010 | lua_unlock(L); | 1010 | lua_unlock(L); |
@@ -1202,13 +1202,13 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | |||
1202 | 1202 | ||
1203 | 1203 | ||
1204 | static const char *aux_upvalue (StkId fi, int n, TValue **val, | 1204 | static const char *aux_upvalue (StkId fi, int n, TValue **val, |
1205 | CClosure **owner, UpVal **uv) { | 1205 | GCObject **owner) { |
1206 | switch (ttype(fi)) { | 1206 | switch (ttype(fi)) { |
1207 | case LUA_TCCL: { /* C closure */ | 1207 | case LUA_TCCL: { /* C closure */ |
1208 | CClosure *f = clCvalue(fi); | 1208 | CClosure *f = clCvalue(fi); |
1209 | if (!(1 <= n && n <= f->nupvalues)) return NULL; | 1209 | if (!(1 <= n && n <= f->nupvalues)) return NULL; |
1210 | *val = &f->upvalue[n-1]; | 1210 | *val = &f->upvalue[n-1]; |
1211 | if (owner) *owner = f; | 1211 | if (owner) *owner = obj2gco(f); |
1212 | return ""; | 1212 | return ""; |
1213 | } | 1213 | } |
1214 | case LUA_TLCL: { /* Lua closure */ | 1214 | case LUA_TLCL: { /* Lua closure */ |
@@ -1217,7 +1217,7 @@ static const char *aux_upvalue (StkId fi, int n, TValue **val, | |||
1217 | Proto *p = f->p; | 1217 | Proto *p = f->p; |
1218 | if (!(1 <= n && n <= p->sizeupvalues)) return NULL; | 1218 | if (!(1 <= n && n <= p->sizeupvalues)) return NULL; |
1219 | *val = f->upvals[n-1]->v; | 1219 | *val = f->upvals[n-1]->v; |
1220 | if (uv) *uv = f->upvals[n - 1]; | 1220 | if (owner) *owner = obj2gco(f->upvals[n - 1]); |
1221 | name = p->upvalues[n-1].name; | 1221 | name = p->upvalues[n-1].name; |
1222 | return (name == NULL) ? "(*no name)" : getstr(name); | 1222 | return (name == NULL) ? "(*no name)" : getstr(name); |
1223 | } | 1223 | } |
@@ -1230,7 +1230,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { | |||
1230 | const char *name; | 1230 | const char *name; |
1231 | TValue *val = NULL; /* to avoid warnings */ | 1231 | TValue *val = NULL; /* to avoid warnings */ |
1232 | lua_lock(L); | 1232 | lua_lock(L); |
1233 | name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL, NULL); | 1233 | name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL); |
1234 | if (name) { | 1234 | if (name) { |
1235 | setobj2s(L, L->top, val); | 1235 | setobj2s(L, L->top, val); |
1236 | api_incr_top(L); | 1236 | api_incr_top(L); |
@@ -1243,18 +1243,16 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { | |||
1243 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | 1243 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { |
1244 | const char *name; | 1244 | const char *name; |
1245 | TValue *val = NULL; /* to avoid warnings */ | 1245 | TValue *val = NULL; /* to avoid warnings */ |
1246 | CClosure *owner = NULL; | 1246 | GCObject *owner = NULL; /* to avoid warnings */ |
1247 | UpVal *uv = NULL; | ||
1248 | StkId fi; | 1247 | StkId fi; |
1249 | lua_lock(L); | 1248 | lua_lock(L); |
1250 | fi = index2addr(L, funcindex); | 1249 | fi = index2addr(L, funcindex); |
1251 | api_checknelems(L, 1); | 1250 | api_checknelems(L, 1); |
1252 | name = aux_upvalue(fi, n, &val, &owner, &uv); | 1251 | name = aux_upvalue(fi, n, &val, &owner); |
1253 | if (name) { | 1252 | if (name) { |
1254 | L->top--; | 1253 | L->top--; |
1255 | setobj(L, val, L->top); | 1254 | setobj(L, val, L->top); |
1256 | if (owner) { luaC_barrier(L, owner, val); } | 1255 | luaC_barrier(L, owner, val); |
1257 | else if (uv) { luaC_upvalbarrier(L, uv, val); } | ||
1258 | } | 1256 | } |
1259 | lua_unlock(L); | 1257 | lua_unlock(L); |
1260 | return name; | 1258 | return name; |
@@ -1296,11 +1294,8 @@ LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, | |||
1296 | LClosure *f1; | 1294 | LClosure *f1; |
1297 | UpVal **up1 = getupvalref(L, fidx1, n1, &f1); | 1295 | UpVal **up1 = getupvalref(L, fidx1, n1, &f1); |
1298 | UpVal **up2 = getupvalref(L, fidx2, n2, NULL); | 1296 | UpVal **up2 = getupvalref(L, fidx2, n2, NULL); |
1299 | luaC_upvdeccount(L, *up1); | ||
1300 | *up1 = *up2; | 1297 | *up1 = *up2; |
1301 | (*up1)->refcount++; | 1298 | luaC_objbarrier(L, f1, *up1); |
1302 | if (upisopen(*up1)) (*up1)->u.open.touched = 1; | ||
1303 | luaC_upvalbarrier(L, *up1, (*up1)->v); | ||
1304 | } | 1299 | } |
1305 | 1300 | ||
1306 | 1301 | ||