aboutsummaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-06-15 17:36:57 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-06-15 17:36:57 -0300
commit8e586c13fcf3066886a7edd69011304eaad57a2b (patch)
tree417c2102ba8c4d693c49a2df839612d371eded50 /lobject.h
parenteadf2aaaffa7a35e7f67b150ce0d57f2c17b9231 (diff)
downloadlua-8e586c13fcf3066886a7edd69011304eaad57a2b.tar.gz
lua-8e586c13fcf3066886a7edd69011304eaad57a2b.tar.bz2
lua-8e586c13fcf3066886a7edd69011304eaad57a2b.zip
cleaner way to ensure alignment for strings and userdata
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h50
1 files changed, 23 insertions, 27 deletions
diff --git a/lobject.h b/lobject.h
index 53df58cc..2f363ec7 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.104 2001/06/06 18:00:19 roberto Exp roberto $ 2** $Id: lobject.h,v 1.105 2001/06/07 15:01:21 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*/
@@ -28,8 +28,8 @@
28 28
29 29
30typedef union { 30typedef union {
31 struct TString *ts; 31 union TString *ts;
32 struct Udata *u; 32 union Udata *u;
33 struct Closure *cl; 33 struct Closure *cl;
34 struct Hash *h; 34 struct Hash *h;
35 lua_Number n; /* LUA_TNUMBER */ 35 lua_Number n; /* LUA_TNUMBER */
@@ -80,40 +80,36 @@ typedef TObject *StkId; /* index to stack elements */
80/* 80/*
81** String headers for string table 81** String headers for string table
82*/ 82*/
83typedef struct TString { 83typedef union TString {
84 lu_hash hash;
85 size_t len;
86 unsigned short constindex; /* hint to reuse constants */
87 short marked;
88 struct TString *nexthash; /* chain for hash table */
89} TString;
90
91
92
93/*
94** type equivalent to TString, but with maximum alignment requirements
95*/
96union L_UTString {
97 TString ts;
98 union L_Umaxalign dummy; /* ensures maximum alignment for strings */ 84 union L_Umaxalign dummy; /* ensures maximum alignment for strings */
99}; 85 struct {
86 lu_hash hash;
87 size_t len;
88 unsigned short constindex; /* hint to reuse constants */
89 short marked;
90 union TString *nexthash; /* chain for hash table */
91 } tsv;
92} TString;
100 93
101 94
102#define getstr(ts) ((l_char *)((union L_UTString *)(ts) + 1)) 95#define getstr(ts) ((l_char *)((ts) + 1))
103#define svalue(o) getstr(tsvalue(o)) 96#define svalue(o) getstr(tsvalue(o))
104 97
105 98
106 99
107typedef struct Udata { 100typedef union Udata {
108 int tag; /* negative means `marked' (only during GC) */ 101 union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
109 void *value; 102 struct {
110 size_t len; 103 int tag; /* negative means `marked' (only during GC) */
111 struct Udata *next; /* chain for list of all udata */ 104 void *value;
105 size_t len;
106 union Udata *next; /* chain for list of all udata */
107 } uv;
112} Udata; 108} Udata;
113 109
114 110
115#define switchudatamark(u) ((u)->tag = (-((u)->tag+1))) 111#define switchudatamark(u) ((u)->uv.tag = (-((u)->uv.tag+1)))
116#define ismarkedudata(u) ((u)->tag < 0) 112#define ismarkedudata(u) ((u)->uv.tag < 0)
117 113
118 114
119 115