diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-03-09 11:10:04 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-03-09 11:10:04 -0300 |
| commit | 1de2f31694ddbc86b18e491c8aedc91791f512e2 (patch) | |
| tree | 01fa1b5fe0cce50c062f8ed07f98741b339bbb66 | |
| parent | 02bab9fc258fe1cbc6088b1bd61193499d058eff (diff) | |
| download | lua-1de2f31694ddbc86b18e491c8aedc91791f512e2.tar.gz lua-1de2f31694ddbc86b18e491c8aedc91791f512e2.tar.bz2 lua-1de2f31694ddbc86b18e491c8aedc91791f512e2.zip | |
Corrected support for 16-bit systems
We still need access to a 16-bit system to correctly test
these changes.
| -rw-r--r-- | ldo.c | 14 | ||||
| -rw-r--r-- | lopcodes.h | 2 | ||||
| -rw-r--r-- | ltable.c | 2 |
3 files changed, 8 insertions, 10 deletions
| @@ -299,17 +299,13 @@ static int stackinuse (lua_State *L) { | |||
| 299 | */ | 299 | */ |
| 300 | void luaD_shrinkstack (lua_State *L) { | 300 | void luaD_shrinkstack (lua_State *L) { |
| 301 | int inuse = stackinuse(L); | 301 | int inuse = stackinuse(L); |
| 302 | int nsize = inuse * 2; /* proposed new size */ | 302 | int max = (inuse > LUAI_MAXSTACK / 3) ? LUAI_MAXSTACK : inuse * 3; |
| 303 | int max = inuse * 3; /* maximum "reasonable" size */ | ||
| 304 | if (max > LUAI_MAXSTACK) { | ||
| 305 | max = LUAI_MAXSTACK; /* respect stack limit */ | ||
| 306 | if (nsize > LUAI_MAXSTACK) | ||
| 307 | nsize = LUAI_MAXSTACK; | ||
| 308 | } | ||
| 309 | /* if thread is currently not handling a stack overflow and its | 303 | /* if thread is currently not handling a stack overflow and its |
| 310 | size is larger than maximum "reasonable" size, shrink it */ | 304 | size is larger than maximum "reasonable" size, shrink it */ |
| 311 | if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) | 305 | if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) { |
| 306 | int nsize = (inuse > LUAI_MAXSTACK / 2) ? LUAI_MAXSTACK : inuse * 2; | ||
| 312 | luaD_reallocstack(L, nsize, 0); /* ok if that fails */ | 307 | luaD_reallocstack(L, nsize, 0); /* ok if that fails */ |
| 308 | } | ||
| 313 | else /* don't change stack */ | 309 | else /* don't change stack */ |
| 314 | condmovestack(L,{},{}); /* (change only for debugging) */ | 310 | condmovestack(L,{},{}); /* (change only for debugging) */ |
| 315 | luaE_shrinkCI(L); /* shrink CI list */ | 311 | luaE_shrinkCI(L); /* shrink CI list */ |
| @@ -629,7 +625,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { | |||
| 629 | ** check the stack before doing anything else. 'luaD_precall' already | 625 | ** check the stack before doing anything else. 'luaD_precall' already |
| 630 | ** does that. | 626 | ** does that. |
| 631 | */ | 627 | */ |
| 632 | l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) { | 628 | l_sinline void ccall (lua_State *L, StkId func, int nResults, l_uint32 inc) { |
| 633 | CallInfo *ci; | 629 | CallInfo *ci; |
| 634 | L->nCcalls += inc; | 630 | L->nCcalls += inc; |
| 635 | if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) { | 631 | if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) { |
| @@ -21,7 +21,7 @@ iABC C(8) | B(8) |k| A(8) | Op(7) | | |||
| 21 | iABx Bx(17) | A(8) | Op(7) | | 21 | iABx Bx(17) | A(8) | Op(7) | |
| 22 | iAsBx sBx (signed)(17) | A(8) | Op(7) | | 22 | iAsBx sBx (signed)(17) | A(8) | Op(7) | |
| 23 | iAx Ax(25) | Op(7) | | 23 | iAx Ax(25) | Op(7) | |
| 24 | isJ sJ(25) | Op(7) | | 24 | isJ sJ (signed)(25) | Op(7) | |
| 25 | 25 | ||
| 26 | A signed argument is represented in excess K: the represented value is | 26 | A signed argument is represented in excess K: the represented value is |
| 27 | the written unsigned value minus K, where K is half the maximum for the | 27 | the written unsigned value minus K, where K is half the maximum for the |
| @@ -257,10 +257,12 @@ LUAI_FUNC unsigned int luaH_realasize (const Table *t) { | |||
| 257 | size |= (size >> 2); | 257 | size |= (size >> 2); |
| 258 | size |= (size >> 4); | 258 | size |= (size >> 4); |
| 259 | size |= (size >> 8); | 259 | size |= (size >> 8); |
| 260 | #if (UINT_MAX >> 14) > 3 /* unsigned int has more than 16 bits */ | ||
| 260 | size |= (size >> 16); | 261 | size |= (size >> 16); |
| 261 | #if (UINT_MAX >> 30) > 3 | 262 | #if (UINT_MAX >> 30) > 3 |
| 262 | size |= (size >> 32); /* unsigned int has more than 32 bits */ | 263 | size |= (size >> 32); /* unsigned int has more than 32 bits */ |
| 263 | #endif | 264 | #endif |
| 265 | #endif | ||
| 264 | size++; | 266 | size++; |
| 265 | lua_assert(ispow2(size) && size/2 < t->alimit && t->alimit < size); | 267 | lua_assert(ispow2(size) && size/2 < t->alimit && t->alimit < size); |
| 266 | return size; | 268 | return size; |
