diff options
| -rw-r--r-- | lapi.c | 10 | ||||
| -rw-r--r-- | lgc.c | 4 | ||||
| -rw-r--r-- | lobject.h | 45 | ||||
| -rw-r--r-- | lstate.h | 7 | ||||
| -rw-r--r-- | lstring.c | 10 | ||||
| -rw-r--r-- | lstring.h | 3 | ||||
| -rw-r--r-- | ltests.c | 4 |
7 files changed, 48 insertions, 35 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.226 2014/07/17 13:53:37 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.227 2014/07/18 12:17:54 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 | */ |
| @@ -420,7 +420,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { | |||
| 420 | LUA_API void *lua_touserdata (lua_State *L, int idx) { | 420 | LUA_API void *lua_touserdata (lua_State *L, int idx) { |
| 421 | StkId o = index2addr(L, idx); | 421 | StkId o = index2addr(L, idx); |
| 422 | switch (ttnov(o)) { | 422 | switch (ttnov(o)) { |
| 423 | case LUA_TUSERDATA: return (rawuvalue(o) + 1); | 423 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); |
| 424 | case LUA_TLIGHTUSERDATA: return pvalue(o); | 424 | case LUA_TLIGHTUSERDATA: return pvalue(o); |
| 425 | default: return NULL; | 425 | default: return NULL; |
| 426 | } | 426 | } |
| @@ -706,7 +706,7 @@ LUA_API int lua_getuservalue (lua_State *L, int idx) { | |||
| 706 | lua_lock(L); | 706 | lua_lock(L); |
| 707 | o = index2addr(L, idx); | 707 | o = index2addr(L, idx); |
| 708 | api_check(ttisfulluserdata(o), "full userdata expected"); | 708 | api_check(ttisfulluserdata(o), "full userdata expected"); |
| 709 | getuservalue(L, rawuvalue(o), L->top); | 709 | getuservalue(L, uvalue(o), L->top); |
| 710 | api_incr_top(L); | 710 | api_incr_top(L); |
| 711 | lua_unlock(L); | 711 | lua_unlock(L); |
| 712 | return ttnov(L->top - 1); | 712 | return ttnov(L->top - 1); |
| @@ -842,7 +842,7 @@ LUA_API void lua_setuservalue (lua_State *L, int idx) { | |||
| 842 | api_checknelems(L, 1); | 842 | api_checknelems(L, 1); |
| 843 | o = index2addr(L, idx); | 843 | o = index2addr(L, idx); |
| 844 | api_check(ttisfulluserdata(o), "full userdata expected"); | 844 | api_check(ttisfulluserdata(o), "full userdata expected"); |
| 845 | setuservalue(L, rawuvalue(o), L->top - 1); | 845 | setuservalue(L, uvalue(o), L->top - 1); |
| 846 | luaC_barrier(L, gcvalue(o), L->top - 1); | 846 | luaC_barrier(L, gcvalue(o), L->top - 1); |
| 847 | L->top--; | 847 | L->top--; |
| 848 | lua_unlock(L); | 848 | lua_unlock(L); |
| @@ -1142,7 +1142,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | |||
| 1142 | setuvalue(L, L->top, u); | 1142 | setuvalue(L, L->top, u); |
| 1143 | api_incr_top(L); | 1143 | api_incr_top(L); |
| 1144 | lua_unlock(L); | 1144 | lua_unlock(L); |
| 1145 | return u + 1; | 1145 | return getudatamem(u); |
| 1146 | } | 1146 | } |
| 1147 | 1147 | ||
| 1148 | 1148 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.186 2014/07/18 12:17:54 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.187 2014/07/18 13:36:14 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 | */ |
| @@ -237,7 +237,7 @@ static void reallymarkobject (global_State *g, GCObject *o) { | |||
| 237 | markobject(g, gco2u(o)->metatable); /* mark its metatable */ | 237 | markobject(g, gco2u(o)->metatable); /* mark its metatable */ |
| 238 | gray2black(o); | 238 | gray2black(o); |
| 239 | g->GCmemtrav += sizeudata(gco2u(o)); | 239 | g->GCmemtrav += sizeudata(gco2u(o)); |
| 240 | getuservalue(g->mainthread, rawgco2u(o), &uvalue); | 240 | getuservalue(g->mainthread, gco2u(o), &uvalue); |
| 241 | if (valiswhite(&uvalue)) { /* markvalue(g, &uvalue); */ | 241 | if (valiswhite(&uvalue)) { /* markvalue(g, &uvalue); */ |
| 242 | o = gcvalue(&uvalue); | 242 | o = gcvalue(&uvalue); |
| 243 | goto reentry; | 243 | goto reentry; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.97 2014/07/18 12:17:54 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.98 2014/07/18 13:36:14 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 | */ |
| @@ -157,8 +157,7 @@ typedef struct lua_TValue TValue; | |||
| 157 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) | 157 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) |
| 158 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) | 158 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) |
| 159 | #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc)) | 159 | #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc)) |
| 160 | #define rawuvalue(o) check_exp(ttisfulluserdata(o), rawgco2u(val_(o).gc)) | 160 | #define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc)) |
| 161 | #define uvalue(o) (&rawuvalue(o)->uv) | ||
| 162 | #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc)) | 161 | #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc)) |
| 163 | #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc)) | 162 | #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc)) |
| 164 | #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc)) | 163 | #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc)) |
| @@ -214,7 +213,7 @@ typedef struct lua_TValue TValue; | |||
| 214 | 213 | ||
| 215 | #define setuvalue(L,obj,x) \ | 214 | #define setuvalue(L,obj,x) \ |
| 216 | { TValue *io = (obj); Udata *x_ = (x); \ | 215 | { TValue *io = (obj); Udata *x_ = (x); \ |
| 217 | val_(io).gc = obj2gco(&x_->uv); settt_(io, ctb(LUA_TUSERDATA)); \ | 216 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \ |
| 218 | checkliveness(G(L),io); } | 217 | checkliveness(G(L),io); } |
| 219 | 218 | ||
| 220 | #define setthvalue(L,obj,x) \ | 219 | #define setthvalue(L,obj,x) \ |
| @@ -324,7 +323,7 @@ typedef union UTString { | |||
| 324 | */ | 323 | */ |
| 325 | #define getaddrstr(ts) (cast(char *, (ts)) + sizeof(UTString)) | 324 | #define getaddrstr(ts) (cast(char *, (ts)) + sizeof(UTString)) |
| 326 | #define getstr(ts) \ | 325 | #define getstr(ts) \ |
| 327 | ((void)(ts)->extra, cast(const char*, getaddrstr(ts))) | 326 | check_exp(sizeof((ts)->extra), cast(const char*, getaddrstr(ts))) |
| 328 | 327 | ||
| 329 | /* get the actual string (array of bytes) from a Lua value */ | 328 | /* get the actual string (array of bytes) from a Lua value */ |
| 330 | #define svalue(o) getstr(tsvalue(o)) | 329 | #define svalue(o) getstr(tsvalue(o)) |
| @@ -332,28 +331,42 @@ typedef union UTString { | |||
| 332 | 331 | ||
| 333 | /* | 332 | /* |
| 334 | ** Header for userdata; memory area follows the end of this structure | 333 | ** Header for userdata; memory area follows the end of this structure |
| 334 | ** (aligned according to 'UUdata'; see next). | ||
| 335 | */ | 335 | */ |
| 336 | typedef union Udata { | 336 | typedef struct Udata { |
| 337 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | 337 | CommonHeader; |
| 338 | struct { | 338 | lu_byte ttuv_; /* user value's tag */ |
| 339 | CommonHeader; | 339 | struct Table *metatable; |
| 340 | lu_byte ttuv_; /* user value's tag */ | 340 | size_t len; /* number of bytes */ |
| 341 | struct Table *metatable; | 341 | union Value user_; /* user value */ |
| 342 | size_t len; /* number of bytes */ | ||
| 343 | union Value user_; /* user value */ | ||
| 344 | } uv; | ||
| 345 | } Udata; | 342 | } Udata; |
| 346 | 343 | ||
| 347 | 344 | ||
| 345 | /* | ||
| 346 | ** Ensures that address after this type is always fully aligned. | ||
| 347 | */ | ||
| 348 | typedef union UUdata { | ||
| 349 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | ||
| 350 | Udata uv; | ||
| 351 | } UUdata; | ||
| 352 | |||
| 353 | |||
| 354 | /* | ||
| 355 | ** Get the address of memory block inside 'Udata'. | ||
| 356 | ** (Access to 'ttuv_' ensures that value is really a 'Udata'.) | ||
| 357 | */ | ||
| 358 | #define getudatamem(u) \ | ||
| 359 | check_exp(sizeof((u)->ttuv_), (cast(char*, (u)) + sizeof(UUdata))) | ||
| 360 | |||
| 348 | #define setuservalue(L,u,o) \ | 361 | #define setuservalue(L,u,o) \ |
| 349 | { const TValue *io=(o); Udata *iu = (u); \ | 362 | { const TValue *io=(o); Udata *iu = (u); \ |
| 350 | iu->uv.user_ = io->value_; iu->uv.ttuv_ = io->tt_; \ | 363 | iu->user_ = io->value_; iu->ttuv_ = io->tt_; \ |
| 351 | checkliveness(G(L),io); } | 364 | checkliveness(G(L),io); } |
| 352 | 365 | ||
| 353 | 366 | ||
| 354 | #define getuservalue(L,u,o) \ | 367 | #define getuservalue(L,u,o) \ |
| 355 | { TValue *io=(o); const Udata *iu = (u); \ | 368 | { TValue *io=(o); const Udata *iu = (u); \ |
| 356 | io->value_ = iu->uv.user_; io->tt_ = iu->uv.ttuv_; \ | 369 | io->value_ = iu->user_; io->tt_ = iu->ttuv_; \ |
| 357 | checkliveness(G(L),io); } | 370 | checkliveness(G(L),io); } |
| 358 | 371 | ||
| 359 | 372 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 2.111 2014/07/18 12:17:54 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.112 2014/07/18 13:36:14 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -175,7 +175,7 @@ struct lua_State { | |||
| 175 | union GCUnion { | 175 | union GCUnion { |
| 176 | GCObject gc; /* common header */ | 176 | GCObject gc; /* common header */ |
| 177 | struct TString ts; | 177 | struct TString ts; |
| 178 | union Udata u; | 178 | struct Udata u; |
| 179 | union Closure cl; | 179 | union Closure cl; |
| 180 | struct Table h; | 180 | struct Table h; |
| 181 | struct Proto p; | 181 | struct Proto p; |
| @@ -188,8 +188,7 @@ union GCUnion { | |||
| 188 | /* macros to convert a GCObject into a specific value */ | 188 | /* macros to convert a GCObject into a specific value */ |
| 189 | #define gco2ts(o) \ | 189 | #define gco2ts(o) \ |
| 190 | check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts)) | 190 | check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts)) |
| 191 | #define rawgco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u)) | 191 | #define gco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u)) |
| 192 | #define gco2u(o) (&rawgco2u(o)->uv) | ||
| 193 | #define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l)) | 192 | #define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l)) |
| 194 | #define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c)) | 193 | #define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c)) |
| 195 | #define gco2cl(o) \ | 194 | #define gco2cl(o) \ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 2.41 2014/07/18 12:17:54 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.42 2014/07/18 13:36:14 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 | */ |
| @@ -170,10 +170,10 @@ Udata *luaS_newudata (lua_State *L, size_t s) { | |||
| 170 | GCObject *o; | 170 | GCObject *o; |
| 171 | if (s > MAX_SIZE - sizeof(Udata)) | 171 | if (s > MAX_SIZE - sizeof(Udata)) |
| 172 | luaM_toobig(L); | 172 | luaM_toobig(L); |
| 173 | o = luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s); | 173 | o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s)); |
| 174 | u = rawgco2u(o); | 174 | u = gco2u(o); |
| 175 | u->uv.len = s; | 175 | u->len = s; |
| 176 | u->uv.metatable = NULL; | 176 | u->metatable = NULL; |
| 177 | setuservalue(L, u, luaO_nilobject); | 177 | setuservalue(L, u, luaO_nilobject); |
| 178 | return u; | 178 | return u; |
| 179 | } | 179 | } |
| @@ -15,7 +15,8 @@ | |||
| 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) |
| 16 | #define sizestring(s) sizelstring((s)->len) | 16 | #define sizestring(s) sizelstring((s)->len) |
| 17 | 17 | ||
| 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) | 18 | #define sizeludata(l) (sizeof(union UUdata) + (l)) |
| 19 | #define sizeudata(u) sizeludata((u)->len) | ||
| 19 | 20 | ||
| 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ | 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ |
| 21 | (sizeof(s)/sizeof(char))-1)) | 22 | (sizeof(s)/sizeof(char))-1)) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.178 2014/07/18 12:17:54 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.179 2014/07/18 13:36:14 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 | */ |
| @@ -319,7 +319,7 @@ static void checkobject (global_State *g, GCObject *o, int maybedead) { | |||
| 319 | TValue uservalue; | 319 | TValue uservalue; |
| 320 | Table *mt = gco2u(o)->metatable; | 320 | Table *mt = gco2u(o)->metatable; |
| 321 | checkobjref(g, o, mt); | 321 | checkobjref(g, o, mt); |
| 322 | getuservalue(g->mainthread, rawgco2u(o), &uservalue); | 322 | getuservalue(g->mainthread, gco2u(o), &uservalue); |
| 323 | checkvalref(g, o, &uservalue); | 323 | checkvalref(g, o, &uservalue); |
| 324 | break; | 324 | break; |
| 325 | } | 325 | } |
