aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-20 13:52:50 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-20 13:52:50 -0300
commitca6fe7449a74efde6f959605dbe77acf3e64ca0b (patch)
treea6190e813ff712f7db750d4ecd3afd3ac9c0dbab /ltests.c
parent1afd5a152dc8b3a304236dc4e07bca38ea5eb53a (diff)
downloadlua-ca6fe7449a74efde6f959605dbe77acf3e64ca0b.tar.gz
lua-ca6fe7449a74efde6f959605dbe77acf3e64ca0b.tar.bz2
lua-ca6fe7449a74efde6f959605dbe77acf3e64ca0b.zip
userdata can have multiple user values
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/ltests.c b/ltests.c
index 24753d5f..97d1abd4 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.239 2018/01/09 11:24:12 roberto Exp roberto $ 2** $Id: ltests.c,v 2.240 2018/01/28 15:13: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*/
@@ -265,6 +265,15 @@ static void checktable (global_State *g, Table *h) {
265} 265}
266 266
267 267
268static void checkudata (global_State *g, Udata *u) {
269 int i;
270 GCObject *hgc = obj2gco(u);
271 checkobjref(g, hgc, u->metatable);
272 for (i = 0; i < u->nuvalue; i++)
273 checkvalref(g, hgc, &u->uv[i].uv);
274}
275
276
268/* 277/*
269** All marks are conditional because a GC may happen while the 278** All marks are conditional because a GC may happen while the
270** prototype is still being created 279** prototype is still being created
@@ -287,7 +296,6 @@ static void checkproto (global_State *g, Proto *f) {
287} 296}
288 297
289 298
290
291static void checkCclosure (global_State *g, CClosure *cl) { 299static void checkCclosure (global_State *g, CClosure *cl) {
292 GCObject *clgc = obj2gco(cl); 300 GCObject *clgc = obj2gco(cl);
293 int i; 301 int i;
@@ -344,11 +352,7 @@ static void checkstack (global_State *g, lua_State *L1) {
344static void checkrefs (global_State *g, GCObject *o) { 352static void checkrefs (global_State *g, GCObject *o) {
345 switch (o->tt) { 353 switch (o->tt) {
346 case LUA_TUSERDATA: { 354 case LUA_TUSERDATA: {
347 TValue uservalue; 355 checkudata(g, gco2u(o));
348 Table *mt = gco2u(o)->metatable;
349 checkobjref(g, o, mt);
350 getuservalue(g->mainthread, gco2u(o), &uservalue);
351 checkvalref(g, o, &uservalue);
352 break; 356 break;
353 } 357 }
354 case LUA_TUPVAL: { 358 case LUA_TUPVAL: {
@@ -728,7 +732,7 @@ static int gc_color (lua_State *L) {
728 GCObject *obj = gcvalue(o); 732 GCObject *obj = gcvalue(o);
729 lua_pushstring(L, isdead(G(L), obj) ? "dead" : 733 lua_pushstring(L, isdead(G(L), obj) ? "dead" :
730 iswhite(obj) ? "white" : 734 iswhite(obj) ? "white" :
731 isblack(obj) ? "black" : "grey"); 735 isblack(obj) ? "black" : "gray");
732 } 736 }
733 return 1; 737 return 1;
734} 738}
@@ -919,8 +923,9 @@ static int upvalue (lua_State *L) {
919 923
920 924
921static int newuserdata (lua_State *L) { 925static int newuserdata (lua_State *L) {
922 size_t size = cast_sizet(luaL_checkinteger(L, 1)); 926 size_t size = cast_sizet(luaL_optinteger(L, 1, 0));
923 char *p = cast_charp(lua_newuserdata(L, size)); 927 int nuv = luaL_optinteger(L, 2, 0);
928 char *p = cast_charp(lua_newuserdatauv(L, size, nuv));
924 while (size--) *p++ = '\0'; 929 while (size--) *p++ = '\0';
925 return 1; 930 return 1;
926} 931}