diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-24 10:54:49 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-24 10:54:49 -0300 |
commit | ef62b340e0a6b7b18931000dcbb19c4703bfe0e8 (patch) | |
tree | d9d995116a8a686b798d1b625b06ead26f28ba58 /lvm.c | |
parent | 5c2dd7a9e0a5b871a71ba66c4683cd88fe4f5aa4 (diff) | |
download | lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.tar.gz lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.tar.bz2 lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.zip |
code cleaner for 16 bits.
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 34 |
1 files changed, 18 insertions, 16 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.106 2000/05/15 19:48:04 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.107 2000/05/22 18:44:46 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 | */ |
@@ -187,7 +187,7 @@ void luaV_setglobal (lua_State *L, TString *s, StkId top) { | |||
187 | const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); | 187 | const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); |
188 | if (ttype(im) == TAG_NIL) { /* is there a tag method? */ | 188 | if (ttype(im) == TAG_NIL) { /* is there a tag method? */ |
189 | if (oldvalue != &luaO_nilobject) | 189 | if (oldvalue != &luaO_nilobject) |
190 | *oldvalue = *(top-1); | 190 | *(TObject *)oldvalue = *(top-1); |
191 | else { | 191 | else { |
192 | TObject key; | 192 | TObject key; |
193 | ttype(&key) = TAG_STRING; | 193 | ttype(&key) = TAG_STRING; |
@@ -239,21 +239,22 @@ static void addK (lua_State *L, StkId top, int k) { | |||
239 | 239 | ||
240 | static int luaV_strcomp (const TString *ls, const TString *rs) { | 240 | static int luaV_strcomp (const TString *ls, const TString *rs) { |
241 | const char *l = ls->str; | 241 | const char *l = ls->str; |
242 | long ll = ls->u.s.len; | 242 | size_t ll = ls->u.s.len; |
243 | const char *r = rs->str; | 243 | const char *r = rs->str; |
244 | long lr = rs->u.s.len; | 244 | size_t lr = rs->u.s.len; |
245 | for (;;) { | 245 | for (;;) { |
246 | long temp = strcoll(l, r); | 246 | int temp = strcoll(l, r); |
247 | if (temp != 0) return temp; | 247 | if (temp != 0) return temp; |
248 | /* strings are equal up to a '\0' */ | 248 | else { /* strings are equal up to a '\0' */ |
249 | temp = strlen(l); /* index of first '\0' in both strings */ | 249 | size_t len = strlen(l); /* index of first '\0' in both strings */ |
250 | if (temp == ll) /* l is finished? */ | 250 | if (len == ll) /* l is finished? */ |
251 | return (temp == lr) ? 0 : -1; /* l is equal or smaller than r */ | 251 | return (len == lr) ? 0 : -1; /* l is equal or smaller than r */ |
252 | else if (temp == lr) /* r is finished? */ | 252 | else if (len == lr) /* r is finished? */ |
253 | return 1; /* l is greater than r (because l is not finished) */ | 253 | return 1; /* l is greater than r (because l is not finished) */ |
254 | /* both strings longer than temp; go on comparing (after the '\0') */ | 254 | /* both strings longer than `len'; go on comparing (after the '\0') */ |
255 | temp++; | 255 | len++; |
256 | l += temp; ll -= temp; r += temp; lr -= temp; | 256 | l += len; ll -= len; r += len; lr -= len; |
257 | } | ||
257 | } | 258 | } |
258 | } | 259 | } |
259 | 260 | ||
@@ -281,17 +282,18 @@ static void strconc (lua_State *L, int total, StkId top) { | |||
281 | call_binTM(L, top, IM_CONCAT, "unexpected type for concatenation"); | 282 | call_binTM(L, top, IM_CONCAT, "unexpected type for concatenation"); |
282 | else if (tsvalue(top-1)->u.s.len > 0) { /* if len=0, do nothing */ | 283 | else if (tsvalue(top-1)->u.s.len > 0) { /* if len=0, do nothing */ |
283 | /* at least two string values; get as many as possible */ | 284 | /* at least two string values; get as many as possible */ |
284 | long tl = tsvalue(top-1)->u.s.len + tsvalue(top-2)->u.s.len; | 285 | lint32 tl = tsvalue(top-1)->u.s.len + tsvalue(top-2)->u.s.len; |
285 | char *buffer; | 286 | char *buffer; |
286 | int i; | 287 | int i; |
287 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ | 288 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ |
288 | tl += tsvalue(top-n-1)->u.s.len; | 289 | tl += tsvalue(top-n-1)->u.s.len; |
289 | n++; | 290 | n++; |
290 | } | 291 | } |
292 | if (tl > MAX_SIZET) lua_error(L, "string size overflow"); | ||
291 | buffer = luaL_openspace(L, tl); | 293 | buffer = luaL_openspace(L, tl); |
292 | tl = 0; | 294 | tl = 0; |
293 | for (i=n; i>0; i--) { /* concat all strings */ | 295 | for (i=n; i>0; i--) { /* concat all strings */ |
294 | long l = tsvalue(top-i)->u.s.len; | 296 | lint32 l = tsvalue(top-i)->u.s.len; |
295 | memcpy(buffer+tl, tsvalue(top-i)->str, l); | 297 | memcpy(buffer+tl, tsvalue(top-i)->str, l); |
296 | tl += l; | 298 | tl += l; |
297 | } | 299 | } |