diff options
| -rw-r--r-- | lstate.h | 40 |
1 files changed, 20 insertions, 20 deletions
| @@ -383,7 +383,7 @@ typedef struct global_State { | |||
| 383 | 383 | ||
| 384 | 384 | ||
| 385 | /* | 385 | /* |
| 386 | ** Union of all collectable objects (only for conversions) | 386 | ** Union of all collectable objects |
| 387 | ** ISO C99, 6.5.2.3 p.5: | 387 | ** ISO C99, 6.5.2.3 p.5: |
| 388 | ** "if a union contains several structures that share a common initial | 388 | ** "if a union contains several structures that share a common initial |
| 389 | ** sequence [...], and if the union object currently contains one | 389 | ** sequence [...], and if the union object currently contains one |
| @@ -403,32 +403,32 @@ union GCUnion { | |||
| 403 | }; | 403 | }; |
| 404 | 404 | ||
| 405 | 405 | ||
| 406 | /* | 406 | /* macros to convert a GCObject into a specific value |
| 407 | ** ISO C99, 6.7.2.1 p.14: | 407 | ** ISO C99, 6.3.2.2 p.7: |
| 408 | ** "A pointer to a union object, suitably converted, points to each of | 408 | ** "A pointer to an object or incomplete type may be converted to a |
| 409 | ** its members [...], and vice versa." | 409 | ** pointer to a different object or incomplete type. If the resulting |
| 410 | ** pointer is not correctly aligned for the pointed-to type, the | ||
| 411 | ** behavior is undefined. Otherwise, when converted back again, the | ||
| 412 | ** result shall compare equal to the original pointer." | ||
| 410 | */ | 413 | */ |
| 411 | #define cast_u(o) cast(union GCUnion *, (o)) | 414 | #define gco2(v,T,o) check_exp((o)->tt == v, cast(T*, o)) |
| 412 | 415 | #define gco2nv(t,T,o) check_exp(novariant((o)->tt) == t, cast(T*, o)) | |
| 413 | /* macros to convert a GCObject into a specific value */ | 416 | #define gco2ts(o) gco2nv(LUA_TSTRING, TString, o) |
| 414 | #define gco2ts(o) \ | 417 | #define gco2u(o) gco2(LUA_VUSERDATA, Udata, o) |
| 415 | check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts)) | 418 | #define gco2lcl(o) (&gco2(LUA_VLCL, Closure, o)->l) |
| 416 | #define gco2u(o) check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u)) | 419 | #define gco2ccl(o) (&gco2(LUA_VCCL, Closure, o)->c) |
| 417 | #define gco2lcl(o) check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l)) | 420 | #define gco2cl(o) gco2nv(LUA_TFUNCTION, Closure, o) |
| 418 | #define gco2ccl(o) check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c)) | 421 | #define gco2t(o) gco2(LUA_VTABLE, Table, o) |
| 419 | #define gco2cl(o) \ | 422 | #define gco2p(o) gco2(LUA_VPROTO, Proto, o) |
| 420 | check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl)) | 423 | #define gco2th(o) gco2(LUA_VTHREAD, lua_State, o) |
| 421 | #define gco2t(o) check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h)) | 424 | #define gco2upv(o) gco2(LUA_VUPVAL, UpVal, o) |
| 422 | #define gco2p(o) check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p)) | ||
| 423 | #define gco2th(o) check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th)) | ||
| 424 | #define gco2upv(o) check_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv)) | ||
| 425 | 425 | ||
| 426 | 426 | ||
| 427 | /* | 427 | /* |
| 428 | ** macro to convert a Lua object into a GCObject | 428 | ** macro to convert a Lua object into a GCObject |
| 429 | */ | 429 | */ |
| 430 | #define obj2gco(v) \ | 430 | #define obj2gco(v) \ |
| 431 | check_exp(novariant((v)->tt) >= LUA_TSTRING, &(cast_u(v)->gc)) | 431 | check_exp(novariant((v)->tt) >= LUA_TSTRING, cast(GCObject*, v)) |
| 432 | 432 | ||
| 433 | 433 | ||
| 434 | /* actual number of total memory allocated */ | 434 | /* actual number of total memory allocated */ |
