diff options
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 45 |
1 files changed, 29 insertions, 16 deletions
@@ -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 | ||