change in GCObject: instead of being a union, it is now a structure

with the common header of all collectable objects; union is used
only for conversions. (Goal is to be able to check that the cast
'obj2gco' can have a check to ensure that object being converted
is really a collectable object.). This is the first step in the
change.
This commit is contained in:
Roberto Ierusalimschy 2014-07-17 14:09:50 -03:00
parent 1aa4f69b51
commit 5a9cc57a5e
2 changed files with 30 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 2.93 2014/05/29 19:30:07 roberto Exp roberto $
** $Id: lobject.h,v 2.94 2014/06/19 18:39:36 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -69,9 +69,9 @@
/*
** Union of all collectable objects
** Common type for all collectable objects
*/
typedef union GCObject GCObject;
typedef struct GCObject GCObject;
/*
@ -82,11 +82,13 @@ typedef union GCObject GCObject;
/*
** Common header in struct form
** Common type has only the common header
*/
typedef struct GCheader {
CommonHeader;
} GCheader;
struct GCObject {
struct {
CommonHeader;
} gch;
};

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 2.107 2014/06/12 19:07:30 roberto Exp roberto $
** $Id: lstate.h,v 2.108 2014/07/17 13:53:37 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -172,8 +172,8 @@ struct lua_State {
/*
** Union of all collectable objects
*/
union GCObject {
GCheader gch; /* common header */
union GCUnion {
GCObject gc; /* common header */
union TString ts;
union Udata u;
union Closure cl;
@ -185,22 +185,31 @@ union GCObject {
#define gch(o) (&(o)->gch)
#define cast_u(o) cast(union GCUnion *, (o))
/* macros to convert a GCObject into a specific value */
#define rawgco2ts(o) \
check_exp(novariant((o)->gch.tt) == LUA_TSTRING, &((o)->ts))
check_exp(novariant((o)->gch.tt) == LUA_TSTRING, &((cast_u(o))->ts))
#define gco2ts(o) (&rawgco2ts(o)->tsv)
#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
#define rawgco2u(o) \
check_exp((o)->gch.tt == LUA_TUSERDATA, &((cast_u(o))->u))
#define gco2u(o) (&rawgco2u(o)->uv)
#define gco2lcl(o) check_exp((o)->gch.tt == LUA_TLCL, &((o)->cl.l))
#define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c))
#define gco2lcl(o) \
check_exp((o)->gch.tt == LUA_TLCL, &((cast_u(o))->cl.l))
#define gco2ccl(o) \
check_exp((o)->gch.tt == LUA_TCCL, &((cast_u(o))->cl.c))
#define gco2cl(o) \
check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl))
#define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
#define gco2t(o) \
check_exp((o)->gch.tt == LUA_TTABLE, &((cast_u(o))->h))
#define gco2p(o) \
check_exp((o)->gch.tt == LUA_TPROTO, &((cast_u(o))->p))
#define gco2th(o) \
check_exp((o)->gch.tt == LUA_TTHREAD, &((cast_u(o))->th))
/* macro to convert any Lua object into a GCObject */
#define obj2gco(v) (cast(GCObject *, (v)))
#define obj2gco(v) (&(cast_u(v)->gc))
/* actual number of total bytes allocated */