aboutsummaryrefslogtreecommitdiff
path: root/lstring.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-30 15:49:19 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-30 15:49:19 -0200
commitd1c689af402e847f77dbe164265e097e90bdc61a (patch)
tree15280b1d60381277d904049ced37b07ded8ad6ac /lstring.c
parent37e9c2e74486ed443151430a9b73a3844d3554ef (diff)
downloadlua-d1c689af402e847f77dbe164265e097e90bdc61a.tar.gz
lua-d1c689af402e847f77dbe164265e097e90bdc61a.tar.bz2
lua-d1c689af402e847f77dbe164265e097e90bdc61a.zip
subtelties in layout of TString
Diffstat (limited to 'lstring.c')
-rw-r--r--lstring.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/lstring.c b/lstring.c
index 7990248c..f0343558 100644
--- a/lstring.c
+++ b/lstring.c
@@ -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*/
21union L_UTString {
22 TString ts;
23 union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
24};
25
26
18 27
19void luaS_init (lua_State *L) { 28void 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
105TString *luaS_newudata (lua_State *L, size_t s, void *udata) { 114TString *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));