diff options
-rw-r--r-- | lapi.c | 18 | ||||
-rw-r--r-- | ldblib.c | 7 | ||||
-rw-r--r-- | lgc.c | 11 | ||||
-rw-r--r-- | lobject.h | 16 | ||||
-rw-r--r-- | lstring.c | 6 | ||||
-rw-r--r-- | lstring.h | 4 | ||||
-rw-r--r-- | ltests.c | 5 |
7 files changed, 37 insertions, 30 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.196 2014/02/14 16:43:14 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.197 2014/02/15 13:12:01 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 | */ |
@@ -740,10 +740,7 @@ LUA_API void lua_getuservalue (lua_State *L, int idx) { | |||
740 | lua_lock(L); | 740 | lua_lock(L); |
741 | o = index2addr(L, idx); | 741 | o = index2addr(L, idx); |
742 | api_check(L, ttisfulluserdata(o), "full userdata expected"); | 742 | api_check(L, ttisfulluserdata(o), "full userdata expected"); |
743 | if (uvalue(o)->env) { | 743 | getuservalue(L, rawuvalue(o), L->top); |
744 | sethvalue(L, L->top, uvalue(o)->env); | ||
745 | } else | ||
746 | setnilvalue(L->top); | ||
747 | api_incr_top(L); | 744 | api_incr_top(L); |
748 | lua_unlock(L); | 745 | lua_unlock(L); |
749 | } | 746 | } |
@@ -878,13 +875,8 @@ LUA_API void lua_setuservalue (lua_State *L, int idx) { | |||
878 | api_checknelems(L, 1); | 875 | api_checknelems(L, 1); |
879 | o = index2addr(L, idx); | 876 | o = index2addr(L, idx); |
880 | api_check(L, ttisfulluserdata(o), "full userdata expected"); | 877 | api_check(L, ttisfulluserdata(o), "full userdata expected"); |
881 | if (ttisnil(L->top - 1)) | 878 | setuservalue(L, rawuvalue(o), L->top - 1); |
882 | uvalue(o)->env = NULL; | 879 | luaC_barrier(L, gcvalue(o), L->top - 1); |
883 | else { | ||
884 | api_check(L, ttistable(L->top - 1), "table expected"); | ||
885 | uvalue(o)->env = hvalue(L->top - 1); | ||
886 | luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1)); | ||
887 | } | ||
888 | L->top--; | 880 | L->top--; |
889 | lua_unlock(L); | 881 | lua_unlock(L); |
890 | } | 882 | } |
@@ -1189,7 +1181,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | |||
1189 | Udata *u; | 1181 | Udata *u; |
1190 | lua_lock(L); | 1182 | lua_lock(L); |
1191 | luaC_checkGC(L); | 1183 | luaC_checkGC(L); |
1192 | u = luaS_newudata(L, size, NULL); | 1184 | u = luaS_newudata(L, size); |
1193 | setuvalue(L, L->top, u); | 1185 | setuvalue(L, L->top, u); |
1194 | api_incr_top(L); | 1186 | api_incr_top(L); |
1195 | lua_unlock(L); | 1187 | lua_unlock(L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.134 2013/07/10 20:57:05 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.135 2013/07/22 16:05:53 roberto Exp roberto $ |
3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -69,11 +69,8 @@ static int db_getuservalue (lua_State *L) { | |||
69 | 69 | ||
70 | 70 | ||
71 | static int db_setuservalue (lua_State *L) { | 71 | static int db_setuservalue (lua_State *L) { |
72 | if (lua_type(L, 1) == LUA_TLIGHTUSERDATA) | ||
73 | luaL_argerror(L, 1, "full userdata expected, got light userdata"); | ||
74 | luaL_checktype(L, 1, LUA_TUSERDATA); | 72 | luaL_checktype(L, 1, LUA_TUSERDATA); |
75 | if (!lua_isnoneornil(L, 2)) | 73 | luaL_checkany(L, 2); |
76 | luaL_checktype(L, 2, LUA_TTABLE); | ||
77 | lua_settop(L, 2); | 74 | lua_settop(L, 2); |
78 | lua_setuservalue(L, 1); | 75 | lua_setuservalue(L, 1); |
79 | return 1; | 76 | return 1; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.176 2014/02/18 13:39:37 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.177 2014/02/18 13:46:26 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -233,12 +233,15 @@ static void reallymarkobject (global_State *g, GCObject *o) { | |||
233 | break; | 233 | break; |
234 | } | 234 | } |
235 | case LUA_TUSERDATA: { | 235 | case LUA_TUSERDATA: { |
236 | TValue uvalue; | ||
236 | markobject(g, gco2u(o)->metatable); /* mark its metatable */ | 237 | markobject(g, gco2u(o)->metatable); /* mark its metatable */ |
237 | gray2black(o); | 238 | gray2black(o); |
238 | g->GCmemtrav += sizeudata(gco2u(o)); | 239 | g->GCmemtrav += sizeudata(gco2u(o)); |
239 | o = obj2gco(gco2u(o)->env); | 240 | getuservalue(g->mainthread, rawgco2u(o), &uvalue); |
240 | if (o && iswhite(o)) | 241 | if (valiswhite(&uvalue)) { /* markvalue(g, &uvalue); */ |
241 | goto reentry; /* reallymarkobject(g, gco2u(o)->env); */ | 242 | o = gcvalue(&uvalue); |
243 | goto reentry; | ||
244 | } | ||
242 | break; | 245 | break; |
243 | } | 246 | } |
244 | case LUA_TLCL: { | 247 | case LUA_TLCL: { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.83 2013/12/04 12:15:22 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.85 2014/02/19 13:51:09 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -331,13 +331,25 @@ typedef union Udata { | |||
331 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | 331 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ |
332 | struct { | 332 | struct { |
333 | CommonHeader; | 333 | CommonHeader; |
334 | lu_byte ttuv_; /* user value's tag */ | ||
334 | struct Table *metatable; | 335 | struct Table *metatable; |
335 | struct Table *env; | ||
336 | size_t len; /* number of bytes */ | 336 | size_t len; /* number of bytes */ |
337 | union Value user_; /* user value */ | ||
337 | } uv; | 338 | } uv; |
338 | } Udata; | 339 | } Udata; |
339 | 340 | ||
340 | 341 | ||
342 | #define setuservalue(L,u,o) \ | ||
343 | { const TValue *io=(o); Udata *iu = (u); \ | ||
344 | iu->uv.user_ = io->value_; iu->uv.ttuv_ = io->tt_; \ | ||
345 | checkliveness(G(L),io); } | ||
346 | |||
347 | |||
348 | #define getuservalue(L,u,o) \ | ||
349 | { TValue *io=(o); const Udata *iu = (u); \ | ||
350 | io->value_ = iu->uv.user_; io->tt_ = iu->uv.ttuv_; \ | ||
351 | checkliveness(G(L),io); } | ||
352 | |||
341 | 353 | ||
342 | /* | 354 | /* |
343 | ** Description of an upvalue for function prototypes | 355 | ** Description of an upvalue for function prototypes |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 2.35 2013/09/11 12:26:14 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.36 2013/09/11 14:56:15 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -172,14 +172,14 @@ TString *luaS_new (lua_State *L, const char *str) { | |||
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { | 175 | Udata *luaS_newudata (lua_State *L, size_t s) { |
176 | Udata *u; | 176 | Udata *u; |
177 | if (s > MAX_SIZE - sizeof(Udata)) | 177 | if (s > MAX_SIZE - sizeof(Udata)) |
178 | luaM_toobig(L); | 178 | luaM_toobig(L); |
179 | u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s)->u; | 179 | u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s)->u; |
180 | u->uv.len = s; | 180 | u->uv.len = s; |
181 | u->uv.metatable = NULL; | 181 | u->uv.metatable = NULL; |
182 | u->uv.env = e; | 182 | setuservalue(L, u, luaO_nilobject); |
183 | return u; | 183 | return u; |
184 | } | 184 | } |
185 | 185 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.h,v 1.51 2013/08/21 19:21:16 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.52 2013/08/21 20:09:51 roberto Exp roberto $ |
3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -37,7 +37,7 @@ LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); | |||
37 | LUAI_FUNC int luaS_eqstr (TString *a, TString *b); | 37 | LUAI_FUNC int luaS_eqstr (TString *a, TString *b); |
38 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); | 38 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); |
39 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); | 39 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); |
40 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); | 40 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); |
41 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); | 41 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); |
42 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); | 42 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); |
43 | 43 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.165 2014/02/15 13:12:01 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.166 2014/02/18 13:46:26 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -322,8 +322,11 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) { | |||
322 | lua_assert(g->gcstate != GCSpause || iswhite(o)); | 322 | lua_assert(g->gcstate != GCSpause || iswhite(o)); |
323 | switch (gch(o)->tt) { | 323 | switch (gch(o)->tt) { |
324 | case LUA_TUSERDATA: { | 324 | case LUA_TUSERDATA: { |
325 | TValue uservalue; | ||
325 | Table *mt = gco2u(o)->metatable; | 326 | Table *mt = gco2u(o)->metatable; |
326 | if (mt) checkobjref(g, o, mt); | 327 | if (mt) checkobjref(g, o, mt); |
328 | getuservalue(g->mainthread, rawgco2u(o), &uservalue); | ||
329 | checkobjref(g, o, &uservalue); | ||
327 | break; | 330 | break; |
328 | } | 331 | } |
329 | case LUA_TTABLE: { | 332 | case LUA_TTABLE: { |