diff options
-rw-r--r-- | llimits.h | 4 | ||||
-rw-r--r-- | lmathlib.c | 8 | ||||
-rw-r--r-- | lopcodes.h | 16 | ||||
-rw-r--r-- | ltable.c | 4 | ||||
-rw-r--r-- | luaconf.h | 3 | ||||
-rw-r--r-- | lutf8lib.c | 2 |
6 files changed, 19 insertions, 18 deletions
@@ -15,10 +15,6 @@ | |||
15 | #include "lua.h" | 15 | #include "lua.h" |
16 | 16 | ||
17 | 17 | ||
18 | /* minimum number of bits in an integer */ | ||
19 | #define LUAI_BITSINT (LUAI_IS32INT ? 32 : 16) | ||
20 | |||
21 | |||
22 | /* | 18 | /* |
23 | ** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count | 19 | ** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count |
24 | ** the total memory used by Lua (in bytes). Usually, 'size_t' and | 20 | ** the total memory used by Lua (in bytes). Usually, 'size_t' and |
@@ -266,7 +266,7 @@ static int math_type (lua_State *L) { | |||
266 | 266 | ||
267 | /* try to find an integer type with at least 64 bits */ | 267 | /* try to find an integer type with at least 64 bits */ |
268 | 268 | ||
269 | #if (LONG_MAX >> 31 >> 31) >= 1 | 269 | #if (ULONG_MAX >> 31 >> 31) >= 3 |
270 | 270 | ||
271 | /* 'long' has at least 64 bits */ | 271 | /* 'long' has at least 64 bits */ |
272 | #define Rand64 unsigned long | 272 | #define Rand64 unsigned long |
@@ -276,7 +276,7 @@ static int math_type (lua_State *L) { | |||
276 | /* there is a 'long long' type (which must have at least 64 bits) */ | 276 | /* there is a 'long long' type (which must have at least 64 bits) */ |
277 | #define Rand64 unsigned long long | 277 | #define Rand64 unsigned long long |
278 | 278 | ||
279 | #elif (LUA_MAXINTEGER >> 31 >> 31) >= 1 | 279 | #elif (LUA_MAXINTEGER >> 30 >> 30) >= 7 |
280 | 280 | ||
281 | /* 'lua_Integer' has at least 64 bits */ | 281 | /* 'lua_Integer' has at least 64 bits */ |
282 | #define Rand64 lua_Unsigned | 282 | #define Rand64 lua_Unsigned |
@@ -347,7 +347,7 @@ static lua_Number I2d (Rand64 x) { | |||
347 | #else /* no 'Rand64' }{ */ | 347 | #else /* no 'Rand64' }{ */ |
348 | 348 | ||
349 | /* get an integer with at least 32 bits */ | 349 | /* get an integer with at least 32 bits */ |
350 | #if (INT_MAX >> 30) >= 1 | 350 | #if LUAI_IS32INT |
351 | typedef unsigned int lu_int32; | 351 | typedef unsigned int lu_int32; |
352 | #else | 352 | #else |
353 | typedef unsigned long lu_int32; | 353 | typedef unsigned long lu_int32; |
@@ -538,7 +538,7 @@ static lua_Unsigned project (lua_Unsigned ran, lua_Unsigned n, | |||
538 | lim |= (lim >> 4); | 538 | lim |= (lim >> 4); |
539 | lim |= (lim >> 8); | 539 | lim |= (lim >> 8); |
540 | lim |= (lim >> 16); | 540 | lim |= (lim >> 16); |
541 | #if (LUA_MAXINTEGER >> 30 >> 1) > 0 | 541 | #if (LUA_MAXINTEGER >> 30) >= 3 |
542 | lim |= (lim >> 32); /* integer type has more than 32 bits */ | 542 | lim |= (lim >> 32); /* integer type has more than 32 bits */ |
543 | #endif | 543 | #endif |
544 | } | 544 | } |
@@ -57,12 +57,18 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */ | |||
57 | 57 | ||
58 | #define POS_sJ POS_A | 58 | #define POS_sJ POS_A |
59 | 59 | ||
60 | |||
60 | /* | 61 | /* |
61 | ** limits for opcode arguments. | 62 | ** limits for opcode arguments. |
62 | ** we use (signed) int to manipulate most arguments, | 63 | ** we use (signed) 'int' to manipulate most arguments, |
63 | ** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) | 64 | ** so they must fit in ints. |
64 | */ | 65 | */ |
65 | #if SIZE_Bx < LUAI_BITSINT-1 | 66 | |
67 | /* Check whether type 'int' has at least 'b' bits ('b' < 32) */ | ||
68 | #define L_INTHASBITS(b) ((UINT_MAX >> ((b) - 1)) >= 1) | ||
69 | |||
70 | |||
71 | #if L_INTHASBITS(SIZE_Bx) | ||
66 | #define MAXARG_Bx ((1<<SIZE_Bx)-1) | 72 | #define MAXARG_Bx ((1<<SIZE_Bx)-1) |
67 | #else | 73 | #else |
68 | #define MAXARG_Bx MAX_INT | 74 | #define MAXARG_Bx MAX_INT |
@@ -71,13 +77,13 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */ | |||
71 | #define OFFSET_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */ | 77 | #define OFFSET_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */ |
72 | 78 | ||
73 | 79 | ||
74 | #if SIZE_Ax < LUAI_BITSINT-1 | 80 | #if L_INTHASBITS(SIZE_Ax) |
75 | #define MAXARG_Ax ((1<<SIZE_Ax)-1) | 81 | #define MAXARG_Ax ((1<<SIZE_Ax)-1) |
76 | #else | 82 | #else |
77 | #define MAXARG_Ax MAX_INT | 83 | #define MAXARG_Ax MAX_INT |
78 | #endif | 84 | #endif |
79 | 85 | ||
80 | #if SIZE_sJ < LUAI_BITSINT-1 | 86 | #if L_INTHASBITS(SIZE_sJ) |
81 | #define MAXARG_sJ ((1 << SIZE_sJ) - 1) | 87 | #define MAXARG_sJ ((1 << SIZE_sJ) - 1) |
82 | #else | 88 | #else |
83 | #define MAXARG_sJ MAX_INT | 89 | #define MAXARG_sJ MAX_INT |
@@ -214,8 +214,8 @@ LUAI_FUNC unsigned int luaH_realasize (const Table *t) { | |||
214 | size |= (size >> 4); | 214 | size |= (size >> 4); |
215 | size |= (size >> 8); | 215 | size |= (size >> 8); |
216 | size |= (size >> 16); | 216 | size |= (size >> 16); |
217 | #if (INT_MAX >> 30 >> 1) > 0 | 217 | #if (UINT_MAX >> 30) > 3 |
218 | size |= (size >> 32); /* int has more than 32 bits */ | 218 | size |= (size >> 32); /* unsigned int has more than 32 bits */ |
219 | #endif | 219 | #endif |
220 | size++; | 220 | size++; |
221 | lua_assert(ispow2(size) && size/2 < t->alimit && t->alimit < size); | 221 | lua_assert(ispow2(size) && size/2 < t->alimit && t->alimit < size); |
@@ -87,9 +87,8 @@ | |||
87 | 87 | ||
88 | /* | 88 | /* |
89 | @@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits. | 89 | @@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits. |
90 | ** (the use of two shifts avoids undefined shifts) | ||
91 | */ | 90 | */ |
92 | #define LUAI_IS32INT (((UINT_MAX >> 15) >> 15) >= 3) | 91 | #define LUAI_IS32INT ((UINT_MAX >> 30) >= 3) |
93 | 92 | ||
94 | /* }================================================================== */ | 93 | /* }================================================================== */ |
95 | 94 | ||
@@ -28,7 +28,7 @@ | |||
28 | /* | 28 | /* |
29 | ** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits. | 29 | ** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits. |
30 | */ | 30 | */ |
31 | #if ((UINT_MAX >> 15) >> 15) >= 1 | 31 | #if (UINT_MAX >> 30) >= 1 |
32 | typedef unsigned int utfint; | 32 | typedef unsigned int utfint; |
33 | #else | 33 | #else |
34 | typedef unsigned long utfint; | 34 | typedef unsigned long utfint; |