diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-17 14:09:50 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-17 14:09:50 -0300 |
commit | 5a9cc57a5ef75a28cd887715175a5a18db58616e (patch) | |
tree | de29400295cd5b3cc7633867488be12e5928e8b6 | |
parent | 1aa4f69b51a92dc4f5c9d35925b9977d35650679 (diff) | |
download | lua-5a9cc57a5ef75a28cd887715175a5a18db58616e.tar.gz lua-5a9cc57a5ef75a28cd887715175a5a18db58616e.tar.bz2 lua-5a9cc57a5ef75a28cd887715175a5a18db58616e.zip |
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.
-rw-r--r-- | lobject.h | 16 | ||||
-rw-r--r-- | lstate.h | 33 |
2 files changed, 30 insertions, 19 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.93 2014/05/29 19:30:07 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.94 2014/06/19 18:39:36 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 | */ |
@@ -69,9 +69,9 @@ | |||
69 | 69 | ||
70 | 70 | ||
71 | /* | 71 | /* |
72 | ** Union of all collectable objects | 72 | ** Common type for all collectable objects |
73 | */ | 73 | */ |
74 | typedef union GCObject GCObject; | 74 | typedef struct GCObject GCObject; |
75 | 75 | ||
76 | 76 | ||
77 | /* | 77 | /* |
@@ -82,11 +82,13 @@ typedef union GCObject GCObject; | |||
82 | 82 | ||
83 | 83 | ||
84 | /* | 84 | /* |
85 | ** Common header in struct form | 85 | ** Common type has only the common header |
86 | */ | 86 | */ |
87 | typedef struct GCheader { | 87 | struct GCObject { |
88 | CommonHeader; | 88 | struct { |
89 | } GCheader; | 89 | CommonHeader; |
90 | } gch; | ||
91 | }; | ||
90 | 92 | ||
91 | 93 | ||
92 | 94 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.107 2014/06/12 19:07:30 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.108 2014/07/17 13:53:37 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 | */ |
@@ -172,8 +172,8 @@ struct lua_State { | |||
172 | /* | 172 | /* |
173 | ** Union of all collectable objects | 173 | ** Union of all collectable objects |
174 | */ | 174 | */ |
175 | union GCObject { | 175 | union GCUnion { |
176 | GCheader gch; /* common header */ | 176 | GCObject gc; /* common header */ |
177 | union TString ts; | 177 | union TString ts; |
178 | union Udata u; | 178 | union Udata u; |
179 | union Closure cl; | 179 | union Closure cl; |
@@ -185,22 +185,31 @@ union GCObject { | |||
185 | 185 | ||
186 | #define gch(o) (&(o)->gch) | 186 | #define gch(o) (&(o)->gch) |
187 | 187 | ||
188 | #define cast_u(o) cast(union GCUnion *, (o)) | ||
189 | |||
188 | /* macros to convert a GCObject into a specific value */ | 190 | /* macros to convert a GCObject into a specific value */ |
189 | #define rawgco2ts(o) \ | 191 | #define rawgco2ts(o) \ |
190 | check_exp(novariant((o)->gch.tt) == LUA_TSTRING, &((o)->ts)) | 192 | check_exp(novariant((o)->gch.tt) == LUA_TSTRING, &((cast_u(o))->ts)) |
191 | #define gco2ts(o) (&rawgco2ts(o)->tsv) | 193 | #define gco2ts(o) (&rawgco2ts(o)->tsv) |
192 | #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) | 194 | #define rawgco2u(o) \ |
195 | check_exp((o)->gch.tt == LUA_TUSERDATA, &((cast_u(o))->u)) | ||
193 | #define gco2u(o) (&rawgco2u(o)->uv) | 196 | #define gco2u(o) (&rawgco2u(o)->uv) |
194 | #define gco2lcl(o) check_exp((o)->gch.tt == LUA_TLCL, &((o)->cl.l)) | 197 | #define gco2lcl(o) \ |
195 | #define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c)) | 198 | check_exp((o)->gch.tt == LUA_TLCL, &((cast_u(o))->cl.l)) |
199 | #define gco2ccl(o) \ | ||
200 | check_exp((o)->gch.tt == LUA_TCCL, &((cast_u(o))->cl.c)) | ||
196 | #define gco2cl(o) \ | 201 | #define gco2cl(o) \ |
197 | check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl)) | 202 | check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((cast_u(o))->cl)) |
198 | #define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) | 203 | #define gco2t(o) \ |
199 | #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) | 204 | check_exp((o)->gch.tt == LUA_TTABLE, &((cast_u(o))->h)) |
200 | #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) | 205 | #define gco2p(o) \ |
206 | check_exp((o)->gch.tt == LUA_TPROTO, &((cast_u(o))->p)) | ||
207 | #define gco2th(o) \ | ||
208 | check_exp((o)->gch.tt == LUA_TTHREAD, &((cast_u(o))->th)) | ||
209 | |||
201 | 210 | ||
202 | /* macro to convert any Lua object into a GCObject */ | 211 | /* macro to convert any Lua object into a GCObject */ |
203 | #define obj2gco(v) (cast(GCObject *, (v))) | 212 | #define obj2gco(v) (&(cast_u(v)->gc)) |
204 | 213 | ||
205 | 214 | ||
206 | /* actual number of total bytes allocated */ | 215 | /* actual number of total bytes allocated */ |