cleaner way to ensure alignment for strings and userdata
This commit is contained in:
14
lapi.c
14
lapi.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 1.144 2001/06/08 19:00:57 roberto Exp roberto $
|
** $Id: lapi.c,v 1.145 2001/06/15 19:16:41 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -244,11 +244,11 @@ LUA_API size_t lua_strlen (lua_State *L, int index) {
|
|||||||
if (o == NULL)
|
if (o == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
else if (ttype(o) == LUA_TSTRING)
|
else if (ttype(o) == LUA_TSTRING)
|
||||||
return tsvalue(o)->len;
|
return tsvalue(o)->tsv.len;
|
||||||
else {
|
else {
|
||||||
size_t l;
|
size_t l;
|
||||||
lua_lock(L); /* `luaV_tostring' may create a new string */
|
lua_lock(L); /* `luaV_tostring' may create a new string */
|
||||||
l = (luaV_tostring(L, o) == 0) ? tsvalue(o)->len : 0;
|
l = (luaV_tostring(L, o) == 0) ? tsvalue(o)->tsv.len : 0;
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) {
|
|||||||
|
|
||||||
LUA_API void *lua_touserdata (lua_State *L, int index) {
|
LUA_API void *lua_touserdata (lua_State *L, int index) {
|
||||||
StkId o = luaA_indexAcceptable(L, index);
|
StkId o = luaA_indexAcceptable(L, index);
|
||||||
return (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : uvalue(o)->value;
|
return (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : uvalue(o)->uv.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -633,7 +633,7 @@ LUA_API void lua_settag (lua_State *L, int tag) {
|
|||||||
hvalue(L->top-1)->htag = tag;
|
hvalue(L->top-1)->htag = tag;
|
||||||
break;
|
break;
|
||||||
case LUA_TUSERDATA:
|
case LUA_TUSERDATA:
|
||||||
uvalue(L->top-1)->tag = tag;
|
uvalue(L->top-1)->uv.tag = tag;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
luaO_verror(L, l_s("cannot change the tag of a %.20s"),
|
luaO_verror(L, l_s("cannot change the tag of a %.20s"),
|
||||||
@@ -744,7 +744,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
|
|||||||
void *p;
|
void *p;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
u = pushnewudata(L, size);
|
u = pushnewudata(L, size);
|
||||||
p = u->value;
|
p = u->uv.value;
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@@ -754,7 +754,7 @@ LUA_API void lua_newuserdatabox (lua_State *L, void *p) {
|
|||||||
Udata *u;
|
Udata *u;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
u = pushnewudata(L, 0);
|
u = pushnewudata(L, 0);
|
||||||
u->value = p;
|
u->uv.value = p;
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
lcode.c
6
lcode.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lcode.c,v 1.74 2001/06/11 14:56:42 roberto Exp roberto $
|
** $Id: lcode.c,v 1.75 2001/06/12 14:36:48 roberto Exp roberto $
|
||||||
** Code generator for Lua
|
** Code generator for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -232,12 +232,12 @@ static int addk (FuncState *fs, TObject *k) {
|
|||||||
|
|
||||||
int luaK_stringk (FuncState *fs, TString *s) {
|
int luaK_stringk (FuncState *fs, TString *s) {
|
||||||
Proto *f = fs->f;
|
Proto *f = fs->f;
|
||||||
int c = s->constindex;
|
int c = s->tsv.constindex;
|
||||||
if (c >= fs->nk || ttype(&f->k[c]) != LUA_TSTRING || tsvalue(&f->k[c]) != s) {
|
if (c >= fs->nk || ttype(&f->k[c]) != LUA_TSTRING || tsvalue(&f->k[c]) != s) {
|
||||||
TObject o;
|
TObject o;
|
||||||
setsvalue(&o, s);
|
setsvalue(&o, s);
|
||||||
c = addk(fs, &o);
|
c = addk(fs, &o);
|
||||||
s->constindex = (unsigned short)c; /* hint for next time */
|
s->tsv.constindex = (unsigned short)c; /* hint for next time */
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|||||||
6
ldebug.c
6
ldebug.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ldebug.c,v 1.81 2001/06/08 19:00:57 roberto Exp roberto $
|
** $Id: ldebug.c,v 1.82 2001/06/11 14:56:42 roberto Exp roberto $
|
||||||
** Debug Interface
|
** Debug Interface
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -483,7 +483,7 @@ static const l_char *getobjname (lua_State *L, StkId obj, const l_char **name) {
|
|||||||
switch (GET_OPCODE(i)) {
|
switch (GET_OPCODE(i)) {
|
||||||
case OP_GETGLOBAL: {
|
case OP_GETGLOBAL: {
|
||||||
lua_assert(ttype(&p->k[GETARG_Bc(i)]) == LUA_TSTRING);
|
lua_assert(ttype(&p->k[GETARG_Bc(i)]) == LUA_TSTRING);
|
||||||
*name = getstr(tsvalue(&p->k[GETARG_Bc(i)]));
|
*name = svalue(&p->k[GETARG_Bc(i)]);
|
||||||
return l_s("global");
|
return l_s("global");
|
||||||
}
|
}
|
||||||
case OP_MOVE: {
|
case OP_MOVE: {
|
||||||
@@ -497,7 +497,7 @@ static const l_char *getobjname (lua_State *L, StkId obj, const l_char **name) {
|
|||||||
case OP_SELF: {
|
case OP_SELF: {
|
||||||
int c = GETARG_C(i) - MAXSTACK;
|
int c = GETARG_C(i) - MAXSTACK;
|
||||||
if (c >= 0 && ttype(&p->k[c]) == LUA_TSTRING) {
|
if (c >= 0 && ttype(&p->k[c]) == LUA_TSTRING) {
|
||||||
*name = getstr(tsvalue(&p->k[c]));
|
*name = svalue(&p->k[c]);
|
||||||
return l_s("field");
|
return l_s("field");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
30
lgc.c
30
lgc.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lgc.c,v 1.104 2001/06/13 18:51:20 roberto Exp roberto $
|
** $Id: lgc.c,v 1.105 2001/06/15 19:17:33 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -27,7 +27,7 @@ typedef struct GCState {
|
|||||||
|
|
||||||
|
|
||||||
/* mark a string; marks larger than 1 cannot be changed */
|
/* mark a string; marks larger than 1 cannot be changed */
|
||||||
#define strmark(s) {if ((s)->marked == 0) (s)->marked = 1;}
|
#define strmark(s) {if ((s)->tsv.marked == 0) (s)->tsv.marked = 1;}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ static void markall (lua_State *L) {
|
|||||||
static int hasmark (int tt, Value *v) {
|
static int hasmark (int tt, Value *v) {
|
||||||
switch (tt) {
|
switch (tt) {
|
||||||
case LUA_TSTRING:
|
case LUA_TSTRING:
|
||||||
return v->ts->marked;
|
return v->ts->tsv.marked;
|
||||||
case LUA_TUSERDATA:
|
case LUA_TUSERDATA:
|
||||||
return ismarkedudata(v->u);
|
return ismarkedudata(v->u);
|
||||||
case LUA_TTABLE:
|
case LUA_TTABLE:
|
||||||
@@ -274,12 +274,12 @@ void luaC_collectudata (lua_State *L) {
|
|||||||
while ((curr = *p) != NULL) {
|
while ((curr = *p) != NULL) {
|
||||||
if (ismarkedudata(curr)) {
|
if (ismarkedudata(curr)) {
|
||||||
switchudatamark(curr); /* unmark */
|
switchudatamark(curr); /* unmark */
|
||||||
p = &curr->next;
|
p = &curr->uv.next;
|
||||||
}
|
}
|
||||||
else { /* collect */
|
else { /* collect */
|
||||||
int tag = curr->tag;
|
int tag = curr->uv.tag;
|
||||||
*p = curr->next;
|
*p = curr->uv.next;
|
||||||
curr->next = G(L)->TMtable[tag].collected; /* chain udata */
|
curr->uv.next = G(L)->TMtable[tag].collected; /* chain udata */
|
||||||
G(L)->TMtable[tag].collected = curr;
|
G(L)->TMtable[tag].collected = curr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,15 +292,15 @@ static void collectstrings (lua_State *L, int all) {
|
|||||||
TString **p = &G(L)->strt.hash[i];
|
TString **p = &G(L)->strt.hash[i];
|
||||||
TString *curr;
|
TString *curr;
|
||||||
while ((curr = *p) != NULL) {
|
while ((curr = *p) != NULL) {
|
||||||
if (curr->marked && !all) { /* preserve? */
|
if (curr->tsv.marked && !all) { /* preserve? */
|
||||||
if (curr->marked < FIXMARK) /* does not change FIXMARKs */
|
if (curr->tsv.marked < FIXMARK) /* does not change FIXMARKs */
|
||||||
curr->marked = 0;
|
curr->tsv.marked = 0;
|
||||||
p = &curr->nexthash;
|
p = &curr->tsv.nexthash;
|
||||||
}
|
}
|
||||||
else { /* collect */
|
else { /* collect */
|
||||||
*p = curr->nexthash;
|
*p = curr->tsv.nexthash;
|
||||||
G(L)->strt.nuse--;
|
G(L)->strt.nuse--;
|
||||||
luaM_free(L, curr, sizestring(curr->len));
|
luaM_free(L, curr, sizestring(curr->tsv.len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,10 +344,10 @@ void luaC_callgcTMudata (lua_State *L) {
|
|||||||
Udata *udata;
|
Udata *udata;
|
||||||
while ((udata = G(L)->TMtable[tag].collected) != NULL) {
|
while ((udata = G(L)->TMtable[tag].collected) != NULL) {
|
||||||
TObject obj;
|
TObject obj;
|
||||||
G(L)->TMtable[tag].collected = udata->next; /* remove it from list */
|
G(L)->TMtable[tag].collected = udata->uv.next; /* remove it from list */
|
||||||
setuvalue(&obj, udata);
|
setuvalue(&obj, udata);
|
||||||
callgcTM(L, &obj);
|
callgcTM(L, &obj);
|
||||||
luaM_free(L, udata, sizeudata(udata->len));
|
luaM_free(L, udata, sizeudata(udata->uv.len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
llex.c
8
llex.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: llex.c,v 1.85 2001/06/07 15:01:21 roberto Exp roberto $
|
** $Id: llex.c,v 1.86 2001/06/13 14:25:49 roberto Exp roberto $
|
||||||
** Lexical Analyzer
|
** Lexical Analyzer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -40,7 +40,7 @@ void luaX_init (lua_State *L) {
|
|||||||
for (i=0; i<NUM_RESERVED; i++) {
|
for (i=0; i<NUM_RESERVED; i++) {
|
||||||
TString *ts = luaS_new(L, token2string[i]);
|
TString *ts = luaS_new(L, token2string[i]);
|
||||||
lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN);
|
lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN);
|
||||||
ts->marked = (unsigned short)(RESERVEDMARK+i); /* reserved word */
|
ts->tsv.marked = (unsigned short)(RESERVEDMARK+i); /* reserved word */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,8 +370,8 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) {
|
|||||||
/* identifier or reserved word */
|
/* identifier or reserved word */
|
||||||
size_t l = readname(LS);
|
size_t l = readname(LS);
|
||||||
TString *ts = luaS_newlstr(LS->L, (l_char *)G(LS->L)->Mbuffer, l);
|
TString *ts = luaS_newlstr(LS->L, (l_char *)G(LS->L)->Mbuffer, l);
|
||||||
if (ts->marked >= RESERVEDMARK) /* reserved word? */
|
if (ts->tsv.marked >= RESERVEDMARK) /* reserved word? */
|
||||||
return ts->marked-RESERVEDMARK+FIRST_RESERVED;
|
return ts->tsv.marked-RESERVEDMARK+FIRST_RESERVED;
|
||||||
seminfo->ts = ts;
|
seminfo->ts = ts;
|
||||||
return TK_NAME;
|
return TK_NAME;
|
||||||
}
|
}
|
||||||
|
|||||||
50
lobject.h
50
lobject.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lobject.h,v 1.104 2001/06/06 18:00:19 roberto Exp roberto $
|
** $Id: lobject.h,v 1.105 2001/06/07 15:01:21 roberto Exp roberto $
|
||||||
** Type definitions for Lua objects
|
** Type definitions for Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
struct TString *ts;
|
union TString *ts;
|
||||||
struct Udata *u;
|
union Udata *u;
|
||||||
struct Closure *cl;
|
struct Closure *cl;
|
||||||
struct Hash *h;
|
struct Hash *h;
|
||||||
lua_Number n; /* LUA_TNUMBER */
|
lua_Number n; /* LUA_TNUMBER */
|
||||||
@@ -80,40 +80,36 @@ typedef TObject *StkId; /* index to stack elements */
|
|||||||
/*
|
/*
|
||||||
** String headers for string table
|
** String headers for string table
|
||||||
*/
|
*/
|
||||||
typedef struct TString {
|
typedef union TString {
|
||||||
lu_hash hash;
|
union L_Umaxalign dummy; /* ensures maximum alignment for strings */
|
||||||
size_t len;
|
struct {
|
||||||
unsigned short constindex; /* hint to reuse constants */
|
lu_hash hash;
|
||||||
short marked;
|
size_t len;
|
||||||
struct TString *nexthash; /* chain for hash table */
|
unsigned short constindex; /* hint to reuse constants */
|
||||||
|
short marked;
|
||||||
|
union TString *nexthash; /* chain for hash table */
|
||||||
|
} tsv;
|
||||||
} TString;
|
} TString;
|
||||||
|
|
||||||
|
|
||||||
|
#define getstr(ts) ((l_char *)((ts) + 1))
|
||||||
/*
|
|
||||||
** type equivalent to TString, but with maximum alignment requirements
|
|
||||||
*/
|
|
||||||
union L_UTString {
|
|
||||||
TString ts;
|
|
||||||
union L_Umaxalign dummy; /* ensures maximum alignment for strings */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#define getstr(ts) ((l_char *)((union L_UTString *)(ts) + 1))
|
|
||||||
#define svalue(o) getstr(tsvalue(o))
|
#define svalue(o) getstr(tsvalue(o))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct Udata {
|
typedef union Udata {
|
||||||
int tag; /* negative means `marked' (only during GC) */
|
union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
|
||||||
void *value;
|
struct {
|
||||||
size_t len;
|
int tag; /* negative means `marked' (only during GC) */
|
||||||
struct Udata *next; /* chain for list of all udata */
|
void *value;
|
||||||
|
size_t len;
|
||||||
|
union Udata *next; /* chain for list of all udata */
|
||||||
|
} uv;
|
||||||
} Udata;
|
} Udata;
|
||||||
|
|
||||||
|
|
||||||
#define switchudatamark(u) ((u)->tag = (-((u)->tag+1)))
|
#define switchudatamark(u) ((u)->uv.tag = (-((u)->uv.tag+1)))
|
||||||
#define ismarkedudata(u) ((u)->tag < 0)
|
#define ismarkedudata(u) ((u)->uv.tag < 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
34
lstring.c
34
lstring.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstring.c,v 1.63 2001/06/06 18:00:19 roberto Exp roberto $
|
** $Id: lstring.c,v 1.64 2001/06/07 15:01:21 roberto Exp roberto $
|
||||||
** String table (keeps all strings handled by Lua)
|
** String table (keeps all strings handled by Lua)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -32,11 +32,11 @@ void luaS_resize (lua_State *L, int newsize) {
|
|||||||
for (i=0; i<tb->size; i++) {
|
for (i=0; i<tb->size; i++) {
|
||||||
TString *p = tb->hash[i];
|
TString *p = tb->hash[i];
|
||||||
while (p) { /* for each node in the list */
|
while (p) { /* for each node in the list */
|
||||||
TString *next = p->nexthash; /* save next */
|
TString *next = p->tsv.nexthash; /* save next */
|
||||||
lu_hash h = p->hash;
|
lu_hash h = p->tsv.hash;
|
||||||
int h1 = lmod(h, newsize); /* new position */
|
int h1 = lmod(h, newsize); /* new position */
|
||||||
lua_assert((int)(h%newsize) == lmod(h, newsize));
|
lua_assert((int)(h%newsize) == lmod(h, newsize));
|
||||||
p->nexthash = newhash[h1]; /* chain it in new position */
|
p->tsv.nexthash = newhash[h1]; /* chain it in new position */
|
||||||
newhash[h1] = p;
|
newhash[h1] = p;
|
||||||
p = next;
|
p = next;
|
||||||
}
|
}
|
||||||
@@ -50,16 +50,16 @@ void luaS_resize (lua_State *L, int newsize) {
|
|||||||
static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) {
|
static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) {
|
||||||
TString *ts = (TString *)luaM_malloc(L, sizestring(l));
|
TString *ts = (TString *)luaM_malloc(L, sizestring(l));
|
||||||
stringtable *tb;
|
stringtable *tb;
|
||||||
ts->nexthash = NULL;
|
ts->tsv.nexthash = NULL;
|
||||||
ts->len = l;
|
ts->tsv.len = l;
|
||||||
ts->hash = h;
|
ts->tsv.hash = h;
|
||||||
ts->marked = 0;
|
ts->tsv.marked = 0;
|
||||||
ts->constindex = 0;
|
ts->tsv.constindex = 0;
|
||||||
memcpy(getstr(ts), str, l*sizeof(l_char));
|
memcpy(getstr(ts), str, l*sizeof(l_char));
|
||||||
getstr(ts)[l] = l_c('\0'); /* ending 0 */
|
getstr(ts)[l] = l_c('\0'); /* ending 0 */
|
||||||
tb = &G(L)->strt;
|
tb = &G(L)->strt;
|
||||||
h = lmod(h, tb->size);
|
h = lmod(h, tb->size);
|
||||||
ts->nexthash = tb->hash[h]; /* chain new entry */
|
ts->tsv.nexthash = tb->hash[h]; /* chain new entry */
|
||||||
tb->hash[h] = ts;
|
tb->hash[h] = ts;
|
||||||
tb->nuse++;
|
tb->nuse++;
|
||||||
if (tb->nuse > (ls_nstr)tb->size && tb->size <= MAX_INT/2)
|
if (tb->nuse > (ls_nstr)tb->size && tb->size <= MAX_INT/2)
|
||||||
@@ -75,8 +75,10 @@ TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) {
|
|||||||
size_t l1;
|
size_t l1;
|
||||||
for (l1=l; l1>=step; l1-=step) /* compute hash */
|
for (l1=l; l1>=step; l1-=step) /* compute hash */
|
||||||
h = h ^ ((h<<5)+(h>>2)+uchar(str[l1-1]));
|
h = h ^ ((h<<5)+(h>>2)+uchar(str[l1-1]));
|
||||||
for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; ts; ts = ts->nexthash) {
|
for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
|
||||||
if (ts->len == l && (memcmp(str, getstr(ts), l) == 0))
|
ts != NULL;
|
||||||
|
ts = ts->tsv.nexthash) {
|
||||||
|
if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0))
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
return newlstr(L, str, l, h); /* not found */
|
return newlstr(L, str, l, h); /* not found */
|
||||||
@@ -85,11 +87,11 @@ TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) {
|
|||||||
|
|
||||||
Udata *luaS_newudata (lua_State *L, size_t s) {
|
Udata *luaS_newudata (lua_State *L, size_t s) {
|
||||||
Udata *u = (Udata *)luaM_malloc(L, sizeudata(s));
|
Udata *u = (Udata *)luaM_malloc(L, sizeudata(s));
|
||||||
u->len = s;
|
u->uv.len = s;
|
||||||
u->tag = 0;
|
u->uv.tag = 0;
|
||||||
u->value = ((union L_UUdata *)(u) + 1);
|
u->uv.value = u + 1;
|
||||||
/* chain it on udata list */
|
/* chain it on udata list */
|
||||||
u->next = G(L)->rootudata;
|
u->uv.next = G(L)->rootudata;
|
||||||
G(L)->rootudata = u;
|
G(L)->rootudata = u;
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|||||||
16
lstring.h
16
lstring.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstring.h,v 1.31 2001/02/23 17:17:25 roberto Exp roberto $
|
** $Id: lstring.h,v 1.32 2001/06/06 18:00:19 roberto Exp roberto $
|
||||||
** String table (keep all strings handled by Lua)
|
** String table (keep all strings handled by Lua)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -13,16 +13,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** type equivalent to Udata, but with maximum alignment requirements
|
|
||||||
*/
|
|
||||||
union L_UUdata {
|
|
||||||
Udata u;
|
|
||||||
union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** any TString with mark>=FIXMARK is never collected.
|
** any TString with mark>=FIXMARK is never collected.
|
||||||
** Marks>=RESERVEDMARK are used to identify reserved words.
|
** Marks>=RESERVEDMARK are used to identify reserved words.
|
||||||
@@ -31,10 +21,10 @@ union L_UUdata {
|
|||||||
#define RESERVEDMARK 3
|
#define RESERVEDMARK 3
|
||||||
|
|
||||||
|
|
||||||
#define sizestring(l) ((lu_mem)sizeof(union L_UTString)+ \
|
#define sizestring(l) ((lu_mem)sizeof(union TString)+ \
|
||||||
((lu_mem)(l)+1)*sizeof(l_char))
|
((lu_mem)(l)+1)*sizeof(l_char))
|
||||||
|
|
||||||
#define sizeudata(l) ((lu_mem)sizeof(union L_UUdata)+(l))
|
#define sizeudata(l) ((lu_mem)sizeof(union Udata)+(l))
|
||||||
|
|
||||||
#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
|
#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
|
||||||
#define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \
|
#define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \
|
||||||
|
|||||||
4
ltable.c
4
ltable.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltable.c,v 1.79 2001/04/11 14:42:41 roberto Exp roberto $
|
** $Id: ltable.c,v 1.80 2001/06/06 18:00:19 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#define hashnum(t,n) (&t->node[lmod((lu_hash)(ls_hash)(n), t->size)])
|
#define hashnum(t,n) (&t->node[lmod((lu_hash)(ls_hash)(n), t->size)])
|
||||||
#define hashstr(t,str) (&t->node[lmod((str)->hash, t->size)])
|
#define hashstr(t,str) (&t->node[lmod((str)->tsv.hash, t->size)])
|
||||||
#define hashpointer(t,p) (&t->node[lmod(IntPoint(p), t->size)])
|
#define hashpointer(t,p) (&t->node[lmod(IntPoint(p), t->size)])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
ltests.c
6
ltests.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltests.c,v 1.81 2001/06/05 18:17:01 roberto Exp roberto $
|
** $Id: ltests.c,v 1.82 2001/06/06 18:00:19 roberto Exp roberto $
|
||||||
** Internal Module for Debugging of the Lua Implementation
|
** Internal Module for Debugging of the Lua Implementation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -290,7 +290,7 @@ static int mem_query (lua_State *L) {
|
|||||||
static int hash_query (lua_State *L) {
|
static int hash_query (lua_State *L) {
|
||||||
if (lua_isnull(L, 2)) {
|
if (lua_isnull(L, 2)) {
|
||||||
luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, l_s("string expected"));
|
luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, l_s("string expected"));
|
||||||
lua_pushnumber(L, tsvalue(luaA_index(L, 1))->hash);
|
lua_pushnumber(L, tsvalue(luaA_index(L, 1))->tsv.hash);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Hash *t;
|
Hash *t;
|
||||||
@@ -349,7 +349,7 @@ static int string_query (lua_State *L) {
|
|||||||
else if (s < tb->size) {
|
else if (s < tb->size) {
|
||||||
TString *ts;
|
TString *ts;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (ts = tb->hash[s]; ts; ts = ts->nexthash) {
|
for (ts = tb->hash[s]; ts; ts = ts->tsv.nexthash) {
|
||||||
setsvalue(L->top, ts);
|
setsvalue(L->top, ts);
|
||||||
incr_top;
|
incr_top;
|
||||||
n++;
|
n++;
|
||||||
|
|||||||
6
ltm.c
6
ltm.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltm.c,v 1.71 2001/03/26 14:31:49 roberto Exp roberto $
|
** $Id: ltm.c,v 1.72 2001/06/06 18:00:19 roberto Exp roberto $
|
||||||
** Tag methods
|
** Tag methods
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -127,7 +127,7 @@ LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) {
|
|||||||
int luaT_tag (const TObject *o) {
|
int luaT_tag (const TObject *o) {
|
||||||
int t = ttype(o);
|
int t = ttype(o);
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case LUA_TUSERDATA: return uvalue(o)->tag;
|
case LUA_TUSERDATA: return uvalue(o)->uv.tag;
|
||||||
case LUA_TTABLE: return hvalue(o)->htag;
|
case LUA_TTABLE: return hvalue(o)->htag;
|
||||||
default: return t;
|
default: return t;
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ const l_char *luaT_typename (global_State *G, const TObject *o) {
|
|||||||
TString *ts;
|
TString *ts;
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case LUA_TUSERDATA:
|
case LUA_TUSERDATA:
|
||||||
tag = uvalue(o)->tag;
|
tag = uvalue(o)->uv.tag;
|
||||||
break;
|
break;
|
||||||
case LUA_TTABLE:
|
case LUA_TTABLE:
|
||||||
tag = hvalue(o)->htag;
|
tag = hvalue(o)->htag;
|
||||||
|
|||||||
15
lvm.c
15
lvm.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 1.184 2001/06/11 14:56:42 roberto Exp roberto $
|
** $Id: lvm.c,v 1.185 2001/06/15 19:17:17 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -249,9 +249,9 @@ static void call_arith (lua_State *L, StkId p1, TObject *p2,
|
|||||||
|
|
||||||
static int luaV_strlessthan (const TString *ls, const TString *rs) {
|
static int luaV_strlessthan (const TString *ls, const TString *rs) {
|
||||||
const l_char *l = getstr(ls);
|
const l_char *l = getstr(ls);
|
||||||
size_t ll = ls->len;
|
size_t ll = ls->tsv.len;
|
||||||
const l_char *r = getstr(rs);
|
const l_char *r = getstr(rs);
|
||||||
size_t lr = rs->len;
|
size_t lr = rs->tsv.len;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int temp = strcoll(l, r);
|
int temp = strcoll(l, r);
|
||||||
if (temp != 0) return (temp < 0);
|
if (temp != 0) return (temp < 0);
|
||||||
@@ -289,20 +289,21 @@ void luaV_strconc (lua_State *L, int total, StkId top) {
|
|||||||
if (tostring(L, top-2) || tostring(L, top-1)) {
|
if (tostring(L, top-2) || tostring(L, top-1)) {
|
||||||
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
|
if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
|
||||||
luaG_concaterror(L, top-2, top-1);
|
luaG_concaterror(L, top-2, top-1);
|
||||||
} else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */
|
} else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */
|
||||||
/* at least two string values; get as many as possible */
|
/* at least two string values; get as many as possible */
|
||||||
lu_mem tl = (lu_mem)tsvalue(top-1)->len + (lu_mem)tsvalue(top-2)->len;
|
lu_mem tl = (lu_mem)tsvalue(top-1)->tsv.len +
|
||||||
|
(lu_mem)tsvalue(top-2)->tsv.len;
|
||||||
l_char *buffer;
|
l_char *buffer;
|
||||||
int i;
|
int i;
|
||||||
while (n < total && !tostring(L, top-n-1)) { /* collect total length */
|
while (n < total && !tostring(L, top-n-1)) { /* collect total length */
|
||||||
tl += tsvalue(top-n-1)->len;
|
tl += tsvalue(top-n-1)->tsv.len;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
if (tl > MAX_SIZET) luaD_error(L, l_s("string size overflow"));
|
if (tl > MAX_SIZET) luaD_error(L, l_s("string size overflow"));
|
||||||
buffer = luaO_openspace(L, tl, l_char);
|
buffer = luaO_openspace(L, tl, l_char);
|
||||||
tl = 0;
|
tl = 0;
|
||||||
for (i=n; i>0; i--) { /* concat all strings */
|
for (i=n; i>0; i--) { /* concat all strings */
|
||||||
size_t l = tsvalue(top-i)->len;
|
size_t l = tsvalue(top-i)->tsv.len;
|
||||||
memcpy(buffer+tl, svalue(top-i), l);
|
memcpy(buffer+tl, svalue(top-i), l);
|
||||||
tl += l;
|
tl += l;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user