diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-30 15:49:19 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-30 15:49:19 -0200 |
| commit | d1c689af402e847f77dbe164265e097e90bdc61a (patch) | |
| tree | 15280b1d60381277d904049ced37b07ded8ad6ac /lstring.c | |
| parent | 37e9c2e74486ed443151430a9b73a3844d3554ef (diff) | |
| download | lua-d1c689af402e847f77dbe164265e097e90bdc61a.tar.gz lua-d1c689af402e847f77dbe164265e097e90bdc61a.tar.bz2 lua-d1c689af402e847f77dbe164265e097e90bdc61a.zip | |
subtelties in layout of TString
Diffstat (limited to 'lstring.c')
| -rw-r--r-- | lstring.c | 17 |
1 files changed, 14 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.43 2000/09/29 12:42:13 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.44 2000/10/26 12:47:05 roberto Exp roberto $ |
| 3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -15,6 +15,15 @@ | |||
| 15 | #include "lstring.h" | 15 | #include "lstring.h" |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | /* | ||
| 19 | ** type equivalent to TString, but with maximum alignment requirements | ||
| 20 | */ | ||
| 21 | union L_UTString { | ||
| 22 | TString ts; | ||
| 23 | union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | ||
| 24 | }; | ||
| 25 | |||
| 26 | |||
| 18 | 27 | ||
| 19 | void luaS_init (lua_State *L) { | 28 | void luaS_init (lua_State *L) { |
| 20 | L->strt.hash = luaM_newvector(L, 1, TString *); | 29 | L->strt.hash = luaM_newvector(L, 1, TString *); |
| @@ -103,12 +112,14 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 103 | 112 | ||
| 104 | 113 | ||
| 105 | TString *luaS_newudata (lua_State *L, size_t s, void *udata) { | 114 | TString *luaS_newudata (lua_State *L, size_t s, void *udata) { |
| 106 | TString *ts = (TString *)luaM_malloc(L, (lint32)sizeof(TString)+s); | 115 | union L_UTString *uts = (union L_UTString *)luaM_malloc(L, |
| 116 | (lint32)sizeof(union L_UTString)+s); | ||
| 117 | TString *ts = &uts->ts; | ||
| 107 | ts->marked = 0; | 118 | ts->marked = 0; |
| 108 | ts->nexthash = NULL; | 119 | ts->nexthash = NULL; |
| 109 | ts->len = s; | 120 | ts->len = s; |
| 110 | ts->u.d.tag = 0; | 121 | ts->u.d.tag = 0; |
| 111 | ts->u.d.value = (udata == NULL) ? ts+1 : udata; | 122 | ts->u.d.value = (udata == NULL) ? uts+1 : udata; |
| 112 | L->nblocks += sizestring(s); | 123 | L->nblocks += sizestring(s); |
| 113 | /* insert it on table */ | 124 | /* insert it on table */ |
| 114 | newentry(L, &L->udt, ts, IntPoint(ts->u.d.value) & (L->udt.size-1)); | 125 | newentry(L, &L->udt, ts, IntPoint(ts->u.d.value) & (L->udt.size-1)); |
