diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-09 18:22:29 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-09 18:22:29 -0200 |
commit | d2e340f467a46017fa3526074c1756124e569880 (patch) | |
tree | e5b08773a0f0734193b0c1c435fab8ee243f08dc /lobject.h | |
parent | 6875fdc8be9029b1bb29379c59d5409a0df42c10 (diff) | |
download | lua-d2e340f467a46017fa3526074c1756124e569880.tar.gz lua-d2e340f467a46017fa3526074c1756124e569880.tar.bz2 lua-d2e340f467a46017fa3526074c1756124e569880.zip |
string pointers are always fully aligned
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.93 2001/02/02 15:13:05 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.94 2001/02/02 16:32:00 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 | */ |
@@ -57,7 +57,6 @@ typedef struct lua_TObject { | |||
57 | #define clvalue(o) ((o)->value.cl) | 57 | #define clvalue(o) ((o)->value.cl) |
58 | #define hvalue(o) ((o)->value.h) | 58 | #define hvalue(o) ((o)->value.h) |
59 | #define infovalue(o) ((o)->value.info) | 59 | #define infovalue(o) ((o)->value.info) |
60 | #define svalue(o) (tsvalue(o)->str) | ||
61 | 60 | ||
62 | 61 | ||
63 | /* Macros to set values */ | 62 | /* Macros to set values */ |
@@ -91,13 +90,6 @@ typedef struct lua_TObject { | |||
91 | ** String headers for string table | 90 | ** String headers for string table |
92 | */ | 91 | */ |
93 | 92 | ||
94 | /* | ||
95 | ** most `malloc' libraries allocate memory in blocks of 8 bytes. TSPACK | ||
96 | ** tries to make sizeof(TString) a multiple of this granularity, to reduce | ||
97 | ** waste of space. | ||
98 | */ | ||
99 | #define TSPACK ((int)sizeof(int)) | ||
100 | |||
101 | typedef struct TString { | 93 | typedef struct TString { |
102 | union { | 94 | union { |
103 | struct { /* for strings */ | 95 | struct { /* for strings */ |
@@ -112,11 +104,24 @@ typedef struct TString { | |||
112 | size_t len; | 104 | size_t len; |
113 | int marked; | 105 | int marked; |
114 | struct TString *nexthash; /* chain for hash table */ | 106 | struct TString *nexthash; /* chain for hash table */ |
115 | char str[TSPACK]; /* variable length string!! must be the last field! */ | ||
116 | } TString; | 107 | } TString; |
117 | 108 | ||
118 | 109 | ||
119 | /* | 110 | /* |
111 | ** type equivalent to TString, but with maximum alignment requirements | ||
112 | */ | ||
113 | union L_UTString { | ||
114 | TString ts; | ||
115 | union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | ||
116 | }; | ||
117 | |||
118 | |||
119 | |||
120 | #define getstr(ts) ((char *)(ts) + sizeof(union L_UTString)) | ||
121 | #define svalue(o) getstr(tsvalue(o)) | ||
122 | |||
123 | |||
124 | /* | ||
120 | ** Function Prototypes | 125 | ** Function Prototypes |
121 | */ | 126 | */ |
122 | typedef struct Proto { | 127 | typedef struct Proto { |