diff options
| -rw-r--r-- | ldebug.c | 10 | ||||
| -rw-r--r-- | lfunc.c | 4 | ||||
| -rw-r--r-- | llex.c | 4 | ||||
| -rw-r--r-- | lobject.h | 25 | ||||
| -rw-r--r-- | lparser.c | 8 | ||||
| -rw-r--r-- | lstring.c | 8 | ||||
| -rw-r--r-- | lstring.h | 15 | ||||
| -rw-r--r-- | ltests.c | 8 | ||||
| -rw-r--r-- | ltm.c | 4 | ||||
| -rw-r--r-- | ltm.h | 4 | ||||
| -rw-r--r-- | lvm.c | 8 |
11 files changed, 47 insertions, 51 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 1.60 2001/02/07 18:13:49 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.61 2001/02/09 18:37:33 roberto Exp roberto $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -198,7 +198,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
| 198 | 198 | ||
| 199 | 199 | ||
| 200 | static void infoLproto (lua_Debug *ar, Proto *f) { | 200 | static void infoLproto (lua_Debug *ar, Proto *f) { |
| 201 | ar->source = f->source->str; | 201 | ar->source = getstr(f->source); |
| 202 | ar->linedefined = f->lineDefined; | 202 | ar->linedefined = f->lineDefined; |
| 203 | ar->what = "Lua"; | 203 | ar->what = "Lua"; |
| 204 | } | 204 | } |
| @@ -249,7 +249,7 @@ static const char *travglobals (lua_State *L, const TObject *o) { | |||
| 249 | for (i=0; i<g->size; i++) { | 249 | for (i=0; i<g->size; i++) { |
| 250 | if (luaO_equalObj(o, val(node(g, i))) && | 250 | if (luaO_equalObj(o, val(node(g, i))) && |
| 251 | ttype_key(node(g, i)) == LUA_TSTRING) | 251 | ttype_key(node(g, i)) == LUA_TSTRING) |
| 252 | return tsvalue_key(node(g, i))->str; | 252 | return getstr(tsvalue_key(node(g, i))); |
| 253 | } | 253 | } |
| 254 | return NULL; | 254 | return NULL; |
| 255 | } | 255 | } |
| @@ -499,7 +499,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
| 499 | lua_assert(pc != -1); | 499 | lua_assert(pc != -1); |
| 500 | switch (GET_OPCODE(i)) { | 500 | switch (GET_OPCODE(i)) { |
| 501 | case OP_GETGLOBAL: { | 501 | case OP_GETGLOBAL: { |
| 502 | *name = p->kstr[GETARG_U(i)]->str; | 502 | *name = getstr(p->kstr[GETARG_U(i)]); |
| 503 | return "global"; | 503 | return "global"; |
| 504 | } | 504 | } |
| 505 | case OP_GETLOCAL: { | 505 | case OP_GETLOCAL: { |
| @@ -509,7 +509,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
| 509 | } | 509 | } |
| 510 | case OP_PUSHSELF: | 510 | case OP_PUSHSELF: |
| 511 | case OP_GETDOTTED: { | 511 | case OP_GETDOTTED: { |
| 512 | *name = p->kstr[GETARG_U(i)]->str; | 512 | *name = getstr(p->kstr[GETARG_U(i)]); |
| 513 | return "field"; | 513 | return "field"; |
| 514 | } | 514 | } |
| 515 | default: | 515 | default: |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 1.38 2001/01/29 19:34:02 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.39 2001/02/01 17:40:48 roberto Exp roberto $ |
| 3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -79,7 +79,7 @@ const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { | |||
| 79 | if (pc < f->locvars[i].endpc) { /* is variable active? */ | 79 | if (pc < f->locvars[i].endpc) { /* is variable active? */ |
| 80 | local_number--; | 80 | local_number--; |
| 81 | if (local_number == 0) | 81 | if (local_number == 0) |
| 82 | return f->locvars[i].varname->str; | 82 | return getstr(f->locvars[i].varname); |
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | return NULL; /* not found */ | 85 | return NULL; /* not found */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.75 2001/01/15 18:07:56 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.76 2001/01/19 13:20:30 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -55,7 +55,7 @@ void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { | |||
| 55 | 55 | ||
| 56 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { | 56 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { |
| 57 | char buff[MAXSRC]; | 57 | char buff[MAXSRC]; |
| 58 | luaO_chunkid(buff, ls->source->str, sizeof(buff)); | 58 | luaO_chunkid(buff, getstr(ls->source), sizeof(buff)); |
| 59 | luaO_verror(ls->L, "%.99s;\n last token read: `%.30s' at line %d in %.80s", | 59 | luaO_verror(ls->L, "%.99s;\n last token read: `%.30s' at line %d in %.80s", |
| 60 | s, token, ls->linenumber, buff); | 60 | s, token, ls->linenumber, buff); |
| 61 | } | 61 | } |
| @@ -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 { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.130 2001/02/08 11:19:10 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.131 2001/02/09 18:37:33 roberto Exp roberto $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -209,7 +209,7 @@ static int search_local (LexState *ls, TString *n, expdesc *var) { | |||
| 209 | static void singlevar (LexState *ls, TString *n, expdesc *var) { | 209 | static void singlevar (LexState *ls, TString *n, expdesc *var) { |
| 210 | int level = search_local(ls, n, var); | 210 | int level = search_local(ls, n, var); |
| 211 | if (level >= 1) /* neither local (0) nor global (-1)? */ | 211 | if (level >= 1) /* neither local (0) nor global (-1)? */ |
| 212 | luaX_syntaxerror(ls, "cannot access a variable in outer scope", n->str); | 212 | luaX_syntaxerror(ls, "cannot access a variable in outer scope", getstr(n)); |
| 213 | else if (level == -1) /* global? */ | 213 | else if (level == -1) /* global? */ |
| 214 | var->u.index = string_constant(ls->fs, n); | 214 | var->u.index = string_constant(ls->fs, n); |
| 215 | } | 215 | } |
| @@ -235,12 +235,12 @@ static void pushupvalue (LexState *ls, TString *n) { | |||
| 235 | int level = search_local(ls, n, &v); | 235 | int level = search_local(ls, n, &v); |
| 236 | if (level == -1) { /* global? */ | 236 | if (level == -1) { /* global? */ |
| 237 | if (fs->prev == NULL) | 237 | if (fs->prev == NULL) |
| 238 | luaX_syntaxerror(ls, "cannot access an upvalue at top level", n->str); | 238 | luaX_syntaxerror(ls, "cannot access an upvalue at top level", getstr(n)); |
| 239 | v.u.index = string_constant(fs->prev, n); | 239 | v.u.index = string_constant(fs->prev, n); |
| 240 | } | 240 | } |
| 241 | else if (level != 1) | 241 | else if (level != 1) |
| 242 | luaX_syntaxerror(ls, | 242 | luaX_syntaxerror(ls, |
| 243 | "upvalue must be global or local to immediately outer scope", n->str); | 243 | "upvalue must be global or local to immediately outer scope", getstr(n)); |
| 244 | luaK_code1(fs, OP_PUSHUPVALUE, indexupvalue(ls, &v)); | 244 | luaK_code1(fs, OP_PUSHUPVALUE, indexupvalue(ls, &v)); |
| 245 | } | 245 | } |
| 246 | 246 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.55 2001/02/01 17:40:48 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.56 2001/02/09 19:53:16 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 | */ |
| @@ -71,7 +71,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 71 | for (l1=l; l1>=step; l1-=step) /* compute hash */ | 71 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
| 72 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)str[l1-1]); | 72 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)str[l1-1]); |
| 73 | for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; ts; ts = ts->nexthash) { | 73 | for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; ts; ts = ts->nexthash) { |
| 74 | if (ts->len == l && (memcmp(str, ts->str, l) == 0)) | 74 | if (ts->len == l && (memcmp(str, getstr(ts), l) == 0)) |
| 75 | return ts; | 75 | return ts; |
| 76 | } | 76 | } |
| 77 | /* not found */ | 77 | /* not found */ |
| @@ -81,8 +81,8 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 81 | ts->len = l; | 81 | ts->len = l; |
| 82 | ts->u.s.hash = h; | 82 | ts->u.s.hash = h; |
| 83 | ts->u.s.constindex = 0; | 83 | ts->u.s.constindex = 0; |
| 84 | memcpy(ts->str, str, l); | 84 | memcpy(getstr(ts), str, l); |
| 85 | ts->str[l] = 0; /* ending 0 */ | 85 | getstr(ts)[l] = 0; /* ending 0 */ |
| 86 | newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ | 86 | newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ |
| 87 | return ts; | 87 | return ts; |
| 88 | } | 88 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.h,v 1.27 2001/01/10 17:41:50 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.28 2001/02/09 19:53:16 roberto Exp roberto $ |
| 3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -14,16 +14,6 @@ | |||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | /* | 16 | /* |
| 17 | ** type equivalent to TString, but with maximum alignment requirements | ||
| 18 | */ | ||
| 19 | union L_UTString { | ||
| 20 | TString ts; | ||
| 21 | union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | ||
| 22 | }; | ||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | /* | ||
| 27 | ** any TString with mark>=FIXMARK is never collected. | 17 | ** any TString with mark>=FIXMARK is never collected. |
| 28 | ** Marks>=RESERVEDMARK are used to identify reserved words. | 18 | ** Marks>=RESERVEDMARK are used to identify reserved words. |
| 29 | */ | 19 | */ |
| @@ -31,8 +21,7 @@ union L_UTString { | |||
| 31 | #define RESERVEDMARK 3 | 21 | #define RESERVEDMARK 3 |
| 32 | 22 | ||
| 33 | 23 | ||
| 34 | #define sizestring(l) ((lint32)sizeof(TString) + \ | 24 | #define sizestring(l) ((luint32)sizeof(union L_UTString)+(l)+1) |
| 35 | ((lint32)(l+1)-TSPACK)*(lint32)sizeof(char)) | ||
| 36 | 25 | ||
| 37 | #define sizeudata(l) ((luint32)sizeof(union L_UTString)+(l)) | 26 | #define sizeudata(l) ((luint32)sizeof(union L_UTString)+(l)) |
| 38 | 27 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.64 2001/02/06 18:18:58 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.65 2001/02/09 19:53:16 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -201,7 +201,7 @@ static int liststrings (lua_State *L) { | |||
| 201 | lua_newtable(L); | 201 | lua_newtable(L); |
| 202 | for (i=0; i<p->sizekstr; i++) { | 202 | for (i=0; i<p->sizekstr; i++) { |
| 203 | lua_pushnumber(L, i+1); | 203 | lua_pushnumber(L, i+1); |
| 204 | lua_pushstring(L, p->kstr[i]->str); | 204 | lua_pushstring(L, getstr(p->kstr[i])); |
| 205 | lua_settable(L, -3); | 205 | lua_settable(L, -3); |
| 206 | } | 206 | } |
| 207 | return 1; | 207 | return 1; |
| @@ -537,7 +537,9 @@ static int testC (lua_State *L) { | |||
| 537 | lua_pushnumber(L, lua_tonumber(L, getnum)); | 537 | lua_pushnumber(L, lua_tonumber(L, getnum)); |
| 538 | } | 538 | } |
| 539 | else if EQ("tostring") { | 539 | else if EQ("tostring") { |
| 540 | lua_pushstring(L, lua_tostring(L, getnum)); | 540 | const char *s = lua_tostring(L, getnum); |
| 541 | lua_assert((unsigned long)s % 4 == 0); /* check alignment */ | ||
| 542 | lua_pushstring(L, s); | ||
| 541 | } | 543 | } |
| 542 | else if EQ("tonumber") { | 544 | else if EQ("tonumber") { |
| 543 | lua_pushnumber(L, lua_tonumber(L, getnum)); | 545 | lua_pushnumber(L, lua_tonumber(L, getnum)); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 1.64 2001/01/26 11:45:51 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.65 2001/02/02 15:13:05 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -150,7 +150,7 @@ const char *luaT_typename (global_State *G, const TObject *o) { | |||
| 150 | ts = G->TMtable[tag].name; | 150 | ts = G->TMtable[tag].name; |
| 151 | if (ts == NULL) | 151 | if (ts == NULL) |
| 152 | ts = G->TMtable[t].name; | 152 | ts = G->TMtable[t].name; |
| 153 | return ts->str; | 153 | return getstr(ts); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | 156 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.h,v 1.21 2001/01/24 16:20:54 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 1.22 2001/01/25 16:45:36 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -62,7 +62,7 @@ struct TM { | |||
| 62 | #define luaT_gettm(G,tag,event) (G->TMtable[tag].method[event]) | 62 | #define luaT_gettm(G,tag,event) (G->TMtable[tag].method[event]) |
| 63 | #define luaT_gettmbyObj(G,o,e) (luaT_gettm((G),luaT_tag(o),(e))) | 63 | #define luaT_gettmbyObj(G,o,e) (luaT_gettm((G),luaT_tag(o),(e))) |
| 64 | 64 | ||
| 65 | #define basictypename(G, t) (G->TMtable[t].name->str) | 65 | #define basictypename(G, t) getstr(G->TMtable[t].name) |
| 66 | 66 | ||
| 67 | 67 | ||
| 68 | #define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag) | 68 | #define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.166 2001/02/07 18:13:49 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.167 2001/02/09 18:07:47 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -225,9 +225,9 @@ static void call_arith (lua_State *L, StkId p1, TMS event) { | |||
| 225 | 225 | ||
| 226 | 226 | ||
| 227 | static int luaV_strlessthan (const TString *ls, const TString *rs) { | 227 | static int luaV_strlessthan (const TString *ls, const TString *rs) { |
| 228 | const char *l = ls->str; | 228 | const char *l = getstr(ls); |
| 229 | size_t ll = ls->len; | 229 | size_t ll = ls->len; |
| 230 | const char *r = rs->str; | 230 | const char *r = getstr(rs); |
| 231 | size_t lr = rs->len; | 231 | size_t lr = rs->len; |
| 232 | for (;;) { | 232 | for (;;) { |
| 233 | int temp = strcoll(l, r); | 233 | int temp = strcoll(l, r); |
| @@ -281,7 +281,7 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
| 281 | tl = 0; | 281 | tl = 0; |
| 282 | for (i=n; i>0; i--) { /* concat all strings */ | 282 | for (i=n; i>0; i--) { /* concat all strings */ |
| 283 | size_t l = tsvalue(top-i)->len; | 283 | size_t l = tsvalue(top-i)->len; |
| 284 | memcpy(buffer+tl, tsvalue(top-i)->str, l); | 284 | memcpy(buffer+tl, svalue(top-i), l); |
| 285 | tl += l; | 285 | tl += l; |
| 286 | } | 286 | } |
| 287 | setsvalue(top-n, luaS_newlstr(L, buffer, tl)); | 287 | setsvalue(top-n, luaS_newlstr(L, buffer, tl)); |
