diff options
-rw-r--r-- | lapi.c | 4 | ||||
-rw-r--r-- | ldo.c | 5 | ||||
-rw-r--r-- | lgc.c | 6 | ||||
-rw-r--r-- | llimits.h | 12 | ||||
-rw-r--r-- | lmem.c | 20 | ||||
-rw-r--r-- | lmem.h | 16 | ||||
-rw-r--r-- | lobject.c | 6 | ||||
-rw-r--r-- | lobject.h | 6 | ||||
-rw-r--r-- | lstate.h | 8 | ||||
-rw-r--r-- | lstring.c | 19 | ||||
-rw-r--r-- | lstring.h | 6 | ||||
-rw-r--r-- | lstrlib.c | 22 | ||||
-rw-r--r-- | ltable.c | 17 | ||||
-rw-r--r-- | ltable.h | 4 | ||||
-rw-r--r-- | lvm.c | 6 |
15 files changed, 85 insertions, 72 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.109 2000/10/26 12:47:05 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.110 2000/10/30 12:50:09 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -389,7 +389,7 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
389 | 389 | ||
390 | /* GC values are expressed in Kbytes: #bytes/2^10 */ | 390 | /* GC values are expressed in Kbytes: #bytes/2^10 */ |
391 | #define GCscale(x) ((int)((x)>>10)) | 391 | #define GCscale(x) ((int)((x)>>10)) |
392 | #define GCunscale(x) ((unsigned long)(x)<<10) | 392 | #define GCunscale(x) ((mem_int)(x)<<10) |
393 | 393 | ||
394 | LUA_API int lua_getgcthreshold (lua_State *L) { | 394 | LUA_API int lua_getgcthreshold (lua_State *L) { |
395 | return GCscale(L->GCthreshold); | 395 | return GCscale(L->GCthreshold); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.108 2000/10/20 16:39:03 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.109 2000/10/30 12:38:50 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -241,7 +241,7 @@ static void f_parser (lua_State *L, void *ud) { | |||
241 | 241 | ||
242 | static int protectedparser (lua_State *L, ZIO *z, int bin) { | 242 | static int protectedparser (lua_State *L, ZIO *z, int bin) { |
243 | struct ParserS p; | 243 | struct ParserS p; |
244 | unsigned long old_blocks; | 244 | mem_int old_blocks; |
245 | int status; | 245 | int status; |
246 | p.z = z; p.bin = bin; | 246 | p.z = z; p.bin = bin; |
247 | luaC_checkGC(L); | 247 | luaC_checkGC(L); |
@@ -249,6 +249,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
249 | status = luaD_runprotected(L, f_parser, &p); | 249 | status = luaD_runprotected(L, f_parser, &p); |
250 | if (status == 0) { | 250 | if (status == 0) { |
251 | /* add new memory to threshold (as it probably will stay) */ | 251 | /* add new memory to threshold (as it probably will stay) */ |
252 | LUA_ASSERT(L->nblocks >= old_blocks, "cannot reduce memory usage here"); | ||
252 | L->GCthreshold += (L->nblocks - old_blocks); | 253 | L->GCthreshold += (L->nblocks - old_blocks); |
253 | } | 254 | } |
254 | else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ | 255 | else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.71 2000/10/05 13:00:17 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.72 2000/10/26 12:47:05 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -229,7 +229,7 @@ static void collecttable (lua_State *L) { | |||
229 | 229 | ||
230 | 230 | ||
231 | static void checktab (lua_State *L, stringtable *tb) { | 231 | static void checktab (lua_State *L, stringtable *tb) { |
232 | if (tb->nuse < (lint32)(tb->size/4) && tb->size > 10) | 232 | if (tb->nuse < (luint32)(tb->size/4) && tb->size > 10) |
233 | luaS_resize(L, tb, tb->size/2); /* table is too big */ | 233 | luaS_resize(L, tb, tb->size/2); /* table is too big */ |
234 | } | 234 | } |
235 | 235 | ||
@@ -286,7 +286,7 @@ static void collectudata (lua_State *L, int all) { | |||
286 | static void checkMbuffer (lua_State *L) { | 286 | static void checkMbuffer (lua_State *L) { |
287 | if (L->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ | 287 | if (L->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ |
288 | size_t newsize = L->Mbuffsize/2; /* still larger than MINBUFFER */ | 288 | size_t newsize = L->Mbuffsize/2; /* still larger than MINBUFFER */ |
289 | L->nblocks += (newsize - L->Mbuffsize)*sizeof(char); | 289 | L->nblocks -= (L->Mbuffsize - newsize)*sizeof(char); |
290 | L->Mbuffsize = newsize; | 290 | L->Mbuffsize = newsize; |
291 | luaM_reallocvector(L, L->Mbuffer, newsize, char); | 291 | luaM_reallocvector(L, L->Mbuffer, newsize, char); |
292 | } | 292 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llimits.h,v 1.18 2000/10/09 13:47:32 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.19 2000/10/26 12:47:05 roberto Exp roberto $ |
3 | ** Limits, basic types, and some other "installation-dependent" definitions | 3 | ** Limits, basic types, and some other "installation-dependent" definitions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -50,7 +50,11 @@ typedef LUA_NUM_TYPE Number; | |||
50 | 50 | ||
51 | 51 | ||
52 | 52 | ||
53 | typedef unsigned long lint32; /* unsigned int with at least 32 bits */ | 53 | typedef unsigned long luint32; /* unsigned int with at least 32 bits */ |
54 | typedef long lint32; /* signed int with at least 32 bits */ | ||
55 | |||
56 | /* an unsigned integer big enough to count the total memory used by Lua */ | ||
57 | typedef unsigned long mem_int; | ||
54 | 58 | ||
55 | 59 | ||
56 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) | 60 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) |
@@ -62,7 +66,7 @@ typedef unsigned long lint32; /* unsigned int with at least 32 bits */ | |||
62 | ** conversion of pointer to int (for hashing only) | 66 | ** conversion of pointer to int (for hashing only) |
63 | ** (the shift removes bits that are usually 0 because of alignment) | 67 | ** (the shift removes bits that are usually 0 because of alignment) |
64 | */ | 68 | */ |
65 | #define IntPoint(p) (((unsigned long)(p)) >> 3) | 69 | #define IntPoint(p) (((luint32)(p)) >> 3) |
66 | 70 | ||
67 | 71 | ||
68 | 72 | ||
@@ -87,7 +91,7 @@ union L_Umaxalign { double d; char *s; long l; }; | |||
87 | ** For a very small machine, you may change that to 2 bytes (and adjust | 91 | ** For a very small machine, you may change that to 2 bytes (and adjust |
88 | ** the following limits accordingly) | 92 | ** the following limits accordingly) |
89 | */ | 93 | */ |
90 | typedef unsigned long Instruction; | 94 | typedef luint32 Instruction; |
91 | 95 | ||
92 | 96 | ||
93 | /* | 97 | /* |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.38 2000/10/26 12:47:05 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.39 2000/10/30 16:29:59 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -41,17 +41,17 @@ | |||
41 | #define MARK 0x55 /* 01010101 (a nice pattern) */ | 41 | #define MARK 0x55 /* 01010101 (a nice pattern) */ |
42 | 42 | ||
43 | 43 | ||
44 | #define blocksize(b) ((unsigned long *)((char *)(b) - HEADER)) | 44 | #define blocksize(b) ((size_t *)((char *)(b) - HEADER)) |
45 | 45 | ||
46 | unsigned long memdebug_numblocks = 0; | 46 | mem_int memdebug_numblocks = 0; |
47 | unsigned long memdebug_total = 0; | 47 | mem_int memdebug_total = 0; |
48 | unsigned long memdebug_maxmem = 0; | 48 | mem_int memdebug_maxmem = 0; |
49 | unsigned long memdebug_memlimit = LONG_MAX; | 49 | mem_int memdebug_memlimit = LONG_MAX; |
50 | 50 | ||
51 | 51 | ||
52 | static void *checkblock (void *block) { | 52 | static void *checkblock (void *block) { |
53 | unsigned long *b = blocksize(block); | 53 | size_t *b = blocksize(block); |
54 | unsigned long size = *b; | 54 | size_t size = *b; |
55 | int i; | 55 | int i; |
56 | for (i=0;i<MARKSIZE;i++) | 56 | for (i=0;i<MARKSIZE;i++) |
57 | assert(*(((char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */ | 57 | assert(*(((char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */ |
@@ -93,7 +93,7 @@ static void *debug_realloc (void *block, size_t size) { | |||
93 | memdebug_total += size; | 93 | memdebug_total += size; |
94 | if (memdebug_total > memdebug_maxmem) memdebug_maxmem = memdebug_total; | 94 | if (memdebug_total > memdebug_maxmem) memdebug_maxmem = memdebug_total; |
95 | memdebug_numblocks++; | 95 | memdebug_numblocks++; |
96 | *(unsigned long *)newblock = size; | 96 | *(size_t *)newblock = size; |
97 | for (i=0;i<MARKSIZE;i++) | 97 | for (i=0;i<MARKSIZE;i++) |
98 | *(newblock+HEADER+size+i) = (char)(MARK+i); | 98 | *(newblock+HEADER+size+i) = (char)(MARK+i); |
99 | return newblock+HEADER; | 99 | return newblock+HEADER; |
@@ -131,7 +131,7 @@ void *luaM_growaux (lua_State *L, void *block, size_t nelems, | |||
131 | /* | 131 | /* |
132 | ** generic allocation routine. | 132 | ** generic allocation routine. |
133 | */ | 133 | */ |
134 | void *luaM_realloc (lua_State *L, void *block, lint32 size) { | 134 | void *luaM_realloc (lua_State *L, void *block, luint32 size) { |
135 | if (size == 0) { | 135 | if (size == 0) { |
136 | free(block); /* block may be NULL; that is OK for free */ | 136 | free(block); /* block may be NULL; that is OK for free */ |
137 | return NULL; | 137 | return NULL; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.h,v 1.15 2000/08/07 18:39:16 roberto Exp roberto $ | 2 | ** $Id: lmem.h,v 1.16 2000/10/30 16:29:59 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -13,7 +13,7 @@ | |||
13 | #include "llimits.h" | 13 | #include "llimits.h" |
14 | #include "lua.h" | 14 | #include "lua.h" |
15 | 15 | ||
16 | void *luaM_realloc (lua_State *L, void *oldblock, lint32 size); | 16 | void *luaM_realloc (lua_State *L, void *oldblock, luint32 size); |
17 | void *luaM_growaux (lua_State *L, void *block, size_t nelems, | 17 | void *luaM_growaux (lua_State *L, void *block, size_t nelems, |
18 | int inc, size_t size, const char *errormsg, | 18 | int inc, size_t size, const char *errormsg, |
19 | size_t limit); | 19 | size_t limit); |
@@ -21,20 +21,20 @@ void *luaM_growaux (lua_State *L, void *block, size_t nelems, | |||
21 | #define luaM_free(L, b) luaM_realloc(L, (b), 0) | 21 | #define luaM_free(L, b) luaM_realloc(L, (b), 0) |
22 | #define luaM_malloc(L, t) luaM_realloc(L, NULL, (t)) | 22 | #define luaM_malloc(L, t) luaM_realloc(L, NULL, (t)) |
23 | #define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t))) | 23 | #define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t))) |
24 | #define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, (n)*(lint32)sizeof(t))) | 24 | #define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, (n)*(luint32)sizeof(t))) |
25 | 25 | ||
26 | #define luaM_growvector(L, v,nelems,inc,t,e,l) \ | 26 | #define luaM_growvector(L, v,nelems,inc,t,e,l) \ |
27 | ((v)=(t *)luaM_growaux(L, v,nelems,inc,sizeof(t),e,l)) | 27 | ((v)=(t *)luaM_growaux(L, v,nelems,inc,sizeof(t),e,l)) |
28 | 28 | ||
29 | #define luaM_reallocvector(L, v,n,t) \ | 29 | #define luaM_reallocvector(L, v,n,t) \ |
30 | ((v)=(t *)luaM_realloc(L, v,(n)*(lint32)sizeof(t))) | 30 | ((v)=(t *)luaM_realloc(L, v,(n)*(luint32)sizeof(t))) |
31 | 31 | ||
32 | 32 | ||
33 | #ifdef LUA_DEBUG | 33 | #ifdef LUA_DEBUG |
34 | extern unsigned long memdebug_numblocks; | 34 | extern mem_int memdebug_numblocks; |
35 | extern unsigned long memdebug_total; | 35 | extern mem_int memdebug_total; |
36 | extern unsigned long memdebug_maxmem; | 36 | extern mem_int memdebug_maxmem; |
37 | extern unsigned long memdebug_memlimit; | 37 | extern mem_int memdebug_memlimit; |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | 40 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.54 2000/10/10 19:53:20 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.55 2000/10/20 16:36:32 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -30,8 +30,8 @@ const char *const luaO_typenames[] = { | |||
30 | /* | 30 | /* |
31 | ** returns smaller power of 2 larger than `n' (minimum is MINPOWER2) | 31 | ** returns smaller power of 2 larger than `n' (minimum is MINPOWER2) |
32 | */ | 32 | */ |
33 | lint32 luaO_power2 (lint32 n) { | 33 | luint32 luaO_power2 (luint32 n) { |
34 | lint32 p = MINPOWER2; | 34 | luint32 p = MINPOWER2; |
35 | while (p<=n) p<<=1; | 35 | while (p<=n) p<<=1; |
36 | return p; | 36 | return p; |
37 | } | 37 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.81 2000/10/30 16:29:59 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.82 2000/10/30 17:49:19 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 | */ |
@@ -82,7 +82,7 @@ typedef struct lua_TObject { | |||
82 | typedef struct TString { | 82 | typedef struct TString { |
83 | union { | 83 | union { |
84 | struct { /* for strings */ | 84 | struct { /* for strings */ |
85 | unsigned long hash; | 85 | luint32 hash; |
86 | int constindex; /* hint to reuse constants */ | 86 | int constindex; /* hint to reuse constants */ |
87 | } s; | 87 | } s; |
88 | struct { /* for userdata */ | 88 | struct { /* for userdata */ |
@@ -191,7 +191,7 @@ extern const char *const luaO_typenames[]; | |||
191 | #define luaO_typename(o) (luaO_typenames[ttype(o)]) | 191 | #define luaO_typename(o) (luaO_typenames[ttype(o)]) |
192 | 192 | ||
193 | 193 | ||
194 | lint32 luaO_power2 (lint32 n); | 194 | luint32 luaO_power2 (luint32 n); |
195 | char *luaO_openspace (lua_State *L, size_t n); | 195 | char *luaO_openspace (lua_State *L, size_t n); |
196 | 196 | ||
197 | int luaO_equalObj (const TObject *t1, const TObject *t2); | 197 | int luaO_equalObj (const TObject *t1, const TObject *t2); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 1.40 2000/09/29 12:42:13 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.41 2000/10/05 13:00:17 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -37,7 +37,7 @@ struct TM; /* defined in ltm.h */ | |||
37 | 37 | ||
38 | typedef struct stringtable { | 38 | typedef struct stringtable { |
39 | int size; | 39 | int size; |
40 | lint32 nuse; /* number of elements */ | 40 | luint32 nuse; /* number of elements */ |
41 | TString **hash; | 41 | TString **hash; |
42 | } stringtable; | 42 | } stringtable; |
43 | 43 | ||
@@ -65,8 +65,8 @@ struct lua_State { | |||
65 | struct Ref *refArray; /* locked objects */ | 65 | struct Ref *refArray; /* locked objects */ |
66 | int refSize; /* size of refArray */ | 66 | int refSize; /* size of refArray */ |
67 | int refFree; /* list of free positions in refArray */ | 67 | int refFree; /* list of free positions in refArray */ |
68 | unsigned long GCthreshold; | 68 | mem_int GCthreshold; |
69 | unsigned long nblocks; /* number of `bytes' currently allocated */ | 69 | mem_int nblocks; /* number of `bytes' currently allocated */ |
70 | lua_Hook callhook; | 70 | lua_Hook callhook; |
71 | lua_Hook linehook; | 71 | lua_Hook linehook; |
72 | int allowhooks; | 72 | int allowhooks; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.44 2000/10/26 12:47:05 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.45 2000/10/30 17:49:19 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 | */ |
@@ -44,8 +44,8 @@ void luaS_freeall (lua_State *L) { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | 46 | ||
47 | static unsigned long hash_s (const char *s, size_t l) { | 47 | static luint32 hash_s (const char *s, size_t l) { |
48 | unsigned long h = l; /* seed */ | 48 | luint32 h = l; /* seed */ |
49 | size_t step = (l>>5)|1; /* if string is too long, don't hash all its chars */ | 49 | size_t step = (l>>5)|1; /* if string is too long, don't hash all its chars */ |
50 | for (; l>=step; l-=step) | 50 | for (; l>=step; l-=step) |
51 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++)); | 51 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++)); |
@@ -62,7 +62,7 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) { | |||
62 | TString *p = tb->hash[i]; | 62 | TString *p = tb->hash[i]; |
63 | while (p) { /* for each node in the list */ | 63 | while (p) { /* for each node in the list */ |
64 | TString *next = p->nexthash; /* save next */ | 64 | TString *next = p->nexthash; /* save next */ |
65 | unsigned long h = (tb == &L->strt) ? p->u.s.hash : IntPoint(p->u.d.value); | 65 | luint32 h = (tb == &L->strt) ? p->u.s.hash : IntPoint(p->u.d.value); |
66 | int h1 = h&(newsize-1); /* new position */ | 66 | int h1 = h&(newsize-1); /* new position */ |
67 | LUA_ASSERT(h%newsize == (h&(newsize-1)), | 67 | LUA_ASSERT(h%newsize == (h&(newsize-1)), |
68 | "a&(x-1) == a%x, for x power of 2"); | 68 | "a&(x-1) == a%x, for x power of 2"); |
@@ -72,7 +72,10 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) { | |||
72 | } | 72 | } |
73 | } | 73 | } |
74 | luaM_free(L, tb->hash); | 74 | luaM_free(L, tb->hash); |
75 | L->nblocks += (newsize - tb->size)*sizeof(TString *); | 75 | if (newsize > tb->size) /* avoid "unsigned negative" values */ |
76 | L->nblocks += (newsize - tb->size)*sizeof(TString *); | ||
77 | else | ||
78 | L->nblocks -= (tb->size - newsize)*sizeof(TString *); | ||
76 | tb->size = newsize; | 79 | tb->size = newsize; |
77 | tb->hash = newhash; | 80 | tb->hash = newhash; |
78 | } | 81 | } |
@@ -82,14 +85,14 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) { | |||
82 | ts->nexthash = tb->hash[h]; /* chain new entry */ | 85 | ts->nexthash = tb->hash[h]; /* chain new entry */ |
83 | tb->hash[h] = ts; | 86 | tb->hash[h] = ts; |
84 | tb->nuse++; | 87 | tb->nuse++; |
85 | if (tb->nuse > (lint32)tb->size && tb->size < MAX_INT/2) /* too crowded? */ | 88 | if (tb->nuse > (luint32)tb->size && tb->size < MAX_INT/2) /* too crowded? */ |
86 | luaS_resize(L, tb, tb->size*2); | 89 | luaS_resize(L, tb, tb->size*2); |
87 | } | 90 | } |
88 | 91 | ||
89 | 92 | ||
90 | 93 | ||
91 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | 94 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
92 | unsigned long h = hash_s(str, l); | 95 | luint32 h = hash_s(str, l); |
93 | int h1 = h & (L->strt.size-1); | 96 | int h1 = h & (L->strt.size-1); |
94 | TString *ts; | 97 | TString *ts; |
95 | for (ts = L->strt.hash[h1]; ts; ts = ts->nexthash) { | 98 | for (ts = L->strt.hash[h1]; ts; ts = ts->nexthash) { |
@@ -113,7 +116,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
113 | 116 | ||
114 | TString *luaS_newudata (lua_State *L, size_t s, void *udata) { | 117 | TString *luaS_newudata (lua_State *L, size_t s, void *udata) { |
115 | union L_UTString *uts = (union L_UTString *)luaM_malloc(L, | 118 | union L_UTString *uts = (union L_UTString *)luaM_malloc(L, |
116 | (lint32)sizeof(union L_UTString)+s); | 119 | (luint32)sizeof(union L_UTString)+s); |
117 | TString *ts = &uts->ts; | 120 | TString *ts = &uts->ts; |
118 | ts->marked = 0; | 121 | ts->marked = 0; |
119 | ts->nexthash = NULL; | 122 | ts->nexthash = NULL; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.h,v 1.23 2000/10/26 12:47:05 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.24 2000/10/30 17:49:19 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 | */ |
@@ -20,8 +20,8 @@ | |||
20 | #define RESERVEDMARK 3 | 20 | #define RESERVEDMARK 3 |
21 | 21 | ||
22 | 22 | ||
23 | #define sizestring(l) ((long)sizeof(TString) + \ | 23 | #define sizestring(l) ((lint32)sizeof(TString) + \ |
24 | ((long)(l+1)-TSPACK)*(long)sizeof(char)) | 24 | ((lint32)(l+1)-TSPACK)*(lint32)sizeof(char)) |
25 | 25 | ||
26 | 26 | ||
27 | void luaS_init (lua_State *L); | 27 | void luaS_init (lua_State *L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.56 2000/10/27 16:15:53 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.57 2000/11/23 13:49:35 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -17,6 +17,8 @@ | |||
17 | #include "lualib.h" | 17 | #include "lualib.h" |
18 | 18 | ||
19 | 19 | ||
20 | typedef long sint32; /* a "signed" version for size_t */ | ||
21 | |||
20 | 22 | ||
21 | static int str_len (lua_State *L) { | 23 | static int str_len (lua_State *L) { |
22 | size_t l; | 24 | size_t l; |
@@ -26,19 +28,19 @@ static int str_len (lua_State *L) { | |||
26 | } | 28 | } |
27 | 29 | ||
28 | 30 | ||
29 | static long posrelat (long pos, size_t len) { | 31 | static sint32 posrelat (sint32 pos, size_t len) { |
30 | /* relative string position: negative means back from end */ | 32 | /* relative string position: negative means back from end */ |
31 | return (pos>=0) ? pos : (long)len+pos+1; | 33 | return (pos>=0) ? pos : (sint32)len+pos+1; |
32 | } | 34 | } |
33 | 35 | ||
34 | 36 | ||
35 | static int str_sub (lua_State *L) { | 37 | static int str_sub (lua_State *L) { |
36 | size_t l; | 38 | size_t l; |
37 | const char *s = luaL_check_lstr(L, 1, &l); | 39 | const char *s = luaL_check_lstr(L, 1, &l); |
38 | long start = posrelat(luaL_check_long(L, 2), l); | 40 | sint32 start = posrelat(luaL_check_long(L, 2), l); |
39 | long end = posrelat(luaL_opt_long(L, 3, -1), l); | 41 | sint32 end = posrelat(luaL_opt_long(L, 3, -1), l); |
40 | if (start < 1) start = 1; | 42 | if (start < 1) start = 1; |
41 | if (end > (long)l) end = l; | 43 | if (end > (sint32)l) end = l; |
42 | if (start <= end) | 44 | if (start <= end) |
43 | lua_pushlstring(L, s+start-1, end-start+1); | 45 | lua_pushlstring(L, s+start-1, end-start+1); |
44 | else lua_pushstring(L, ""); | 46 | else lua_pushstring(L, ""); |
@@ -87,7 +89,7 @@ static int str_rep (lua_State *L) { | |||
87 | static int str_byte (lua_State *L) { | 89 | static int str_byte (lua_State *L) { |
88 | size_t l; | 90 | size_t l; |
89 | const char *s = luaL_check_lstr(L, 1, &l); | 91 | const char *s = luaL_check_lstr(L, 1, &l); |
90 | long pos = posrelat(luaL_opt_long(L, 2, 1), l); | 92 | sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); |
91 | luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, "out of range"); | 93 | luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, "out of range"); |
92 | lua_pushnumber(L, (unsigned char)s[pos-1]); | 94 | lua_pushnumber(L, (unsigned char)s[pos-1]); |
93 | return 1; | 95 | return 1; |
@@ -126,7 +128,7 @@ typedef struct MatchState { | |||
126 | int level; /* total number of captures (finished or unfinished) */ | 128 | int level; /* total number of captures (finished or unfinished) */ |
127 | struct { | 129 | struct { |
128 | const char *init; | 130 | const char *init; |
129 | long len; /* -1 signals unfinished capture */ | 131 | sint32 len; /* -1 signals unfinished capture */ |
130 | } capture[MAX_CAPTURES]; | 132 | } capture[MAX_CAPTURES]; |
131 | lua_State *L; | 133 | lua_State *L; |
132 | } MatchState; | 134 | } MatchState; |
@@ -251,7 +253,7 @@ static const char *matchbalance (MatchState *ms, const char *s, const char *p) { | |||
251 | 253 | ||
252 | static const char *max_expand (MatchState *ms, const char *s, const char *p, | 254 | static const char *max_expand (MatchState *ms, const char *s, const char *p, |
253 | const char *ep) { | 255 | const char *ep) { |
254 | long i = 0; /* counts maximum expand for item */ | 256 | sint32 i = 0; /* counts maximum expand for item */ |
255 | while ((s+i)<ms->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep)) | 257 | while ((s+i)<ms->src_end && luaI_singlematch((unsigned char)*(s+i), p, ep)) |
256 | i++; | 258 | i++; |
257 | /* keeps trying to match with the maximum repetitions */ | 259 | /* keeps trying to match with the maximum repetitions */ |
@@ -399,7 +401,7 @@ static int str_find (lua_State *L) { | |||
399 | size_t l1, l2; | 401 | size_t l1, l2; |
400 | const char *s = luaL_check_lstr(L, 1, &l1); | 402 | const char *s = luaL_check_lstr(L, 1, &l1); |
401 | const char *p = luaL_check_lstr(L, 2, &l2); | 403 | const char *p = luaL_check_lstr(L, 2, &l2); |
402 | long init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; | 404 | sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; |
403 | luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range"); | 405 | luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range"); |
404 | if (lua_gettop(L) > 3 || /* extra argument? */ | 406 | if (lua_gettop(L) > 3 || /* extra argument? */ |
405 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ | 407 | strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.57 2000/10/05 12:14:08 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.58 2000/10/26 12:47:05 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -40,10 +40,10 @@ | |||
40 | ** of its hash value) | 40 | ** of its hash value) |
41 | */ | 41 | */ |
42 | Node *luaH_mainposition (const Hash *t, const TObject *key) { | 42 | Node *luaH_mainposition (const Hash *t, const TObject *key) { |
43 | unsigned long h; | 43 | luint32 h; |
44 | switch (ttype(key)) { | 44 | switch (ttype(key)) { |
45 | case LUA_TNUMBER: | 45 | case LUA_TNUMBER: |
46 | h = (unsigned long)(long)nvalue(key); | 46 | h = (luint32)(lint32)nvalue(key); |
47 | break; | 47 | break; |
48 | case LUA_TSTRING: | 48 | case LUA_TSTRING: |
49 | h = tsvalue(key)->u.s.hash; | 49 | h = tsvalue(key)->u.s.hash; |
@@ -82,7 +82,7 @@ static const TObject *luaH_getany (lua_State *L, const Hash *t, | |||
82 | 82 | ||
83 | /* specialized version for numbers */ | 83 | /* specialized version for numbers */ |
84 | const TObject *luaH_getnum (const Hash *t, Number key) { | 84 | const TObject *luaH_getnum (const Hash *t, Number key) { |
85 | Node *n = &t->node[(unsigned long)(long)key&(t->size-1)]; | 85 | Node *n = &t->node[(luint32)(lint32)key&(t->size-1)]; |
86 | do { | 86 | do { |
87 | if (ttype(&n->key) == LUA_TNUMBER && nvalue(&n->key) == key) | 87 | if (ttype(&n->key) == LUA_TNUMBER && nvalue(&n->key) == key) |
88 | return &n->val; | 88 | return &n->val; |
@@ -158,7 +158,7 @@ void luaH_remove (Hash *t, TObject *key) { | |||
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | static void setnodevector (lua_State *L, Hash *t, lint32 size) { | 161 | static void setnodevector (lua_State *L, Hash *t, luint32 size) { |
162 | int i; | 162 | int i; |
163 | if (size > MAX_INT) | 163 | if (size > MAX_INT) |
164 | lua_error(L, "table overflow"); | 164 | lua_error(L, "table overflow"); |
@@ -167,7 +167,10 @@ static void setnodevector (lua_State *L, Hash *t, lint32 size) { | |||
167 | ttype(&t->node[i].key) = ttype(&t->node[i].val) = LUA_TNIL; | 167 | ttype(&t->node[i].key) = ttype(&t->node[i].val) = LUA_TNIL; |
168 | t->node[i].next = NULL; | 168 | t->node[i].next = NULL; |
169 | } | 169 | } |
170 | L->nblocks += gcsize(L, size) - gcsize(L, t->size); | 170 | if ((int)size > t->size) /* avoid "unsigned negative" values */ |
171 | L->nblocks += gcsize(L, size) - gcsize(L, t->size); | ||
172 | else | ||
173 | L->nblocks -= gcsize(L, t->size) - gcsize(L, size); | ||
171 | t->size = size; | 174 | t->size = size; |
172 | t->firstfree = &t->node[size-1]; /* first free position to be used */ | 175 | t->firstfree = &t->node[size-1]; /* first free position to be used */ |
173 | } | 176 | } |
@@ -214,7 +217,7 @@ static void rehash (lua_State *L, Hash *t) { | |||
214 | int i; | 217 | int i; |
215 | LUA_ASSERT(nelems<=oldsize, "wrong count"); | 218 | LUA_ASSERT(nelems<=oldsize, "wrong count"); |
216 | if (nelems >= oldsize-oldsize/4) /* using more than 3/4? */ | 219 | if (nelems >= oldsize-oldsize/4) /* using more than 3/4? */ |
217 | setnodevector(L, t, (lint32)oldsize*2); | 220 | setnodevector(L, t, (luint32)oldsize*2); |
218 | else if (nelems <= oldsize/4 && /* less than 1/4? */ | 221 | else if (nelems <= oldsize/4 && /* less than 1/4? */ |
219 | oldsize > MINPOWER2) | 222 | oldsize > MINPOWER2) |
220 | setnodevector(L, t, oldsize/2); | 223 | setnodevector(L, t, oldsize/2); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.h,v 1.23 2000/06/06 16:31:41 roberto Exp roberto $ | 2 | ** $Id: ltable.h,v 1.24 2000/08/31 14:08:27 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -24,7 +24,7 @@ TObject *luaH_set (lua_State *L, Hash *t, const TObject *key); | |||
24 | Node * luaH_next (lua_State *L, const Hash *t, const TObject *r); | 24 | Node * luaH_next (lua_State *L, const Hash *t, const TObject *r); |
25 | TObject *luaH_setint (lua_State *L, Hash *t, int key); | 25 | TObject *luaH_setint (lua_State *L, Hash *t, int key); |
26 | void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val); | 26 | void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val); |
27 | unsigned long luaH_hash (lua_State *L, const TObject *key); | 27 | luint32 luaH_hash (lua_State *L, const TObject *key); |
28 | const TObject *luaH_getglobal (lua_State *L, const char *name); | 28 | const TObject *luaH_getglobal (lua_State *L, const char *name); |
29 | 29 | ||
30 | /* exported only for debugging */ | 30 | /* exported only for debugging */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.145 2000/10/06 12:45:25 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.146 2000/10/26 12:47:05 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 | */ |
@@ -295,8 +295,8 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
295 | } | 295 | } |
296 | else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ | 296 | else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ |
297 | /* at least two string values; get as many as possible */ | 297 | /* at least two string values; get as many as possible */ |
298 | lint32 tl = (lint32)tsvalue(top-1)->len + | 298 | luint32 tl = (luint32)tsvalue(top-1)->len + |
299 | (lint32)tsvalue(top-2)->len; | 299 | (luint32)tsvalue(top-2)->len; |
300 | char *buffer; | 300 | char *buffer; |
301 | int i; | 301 | int i; |
302 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ | 302 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ |