|
20 | 20 | /* |
21 | 21 | ** 'l_mem' is a signed integer big enough to count the total memory |
22 | 22 | ** used by Lua. (It is signed due to the use of debt in several |
23 | | -** computations.) Usually, 'ptrdiff_t' should work, but we use 'long' |
24 | | -** for 16-bit machines. |
| 23 | +** computations.) 'lu_mem' is a corresponding unsigned type. Usually, |
| 24 | +** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines. |
25 | 25 | */ |
26 | 26 | #if defined(LUAI_MEM) /* { external definitions? */ |
27 | 27 | typedef LUAI_MEM l_mem; |
@@ -59,13 +59,6 @@ typedef lu_byte TStatus; |
59 | 59 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ |
60 | 60 | : cast_sizet(LUA_MAXINTEGER)) |
61 | 61 |
|
62 | | -/* |
63 | | -** floor of the log2 of the maximum signed value for integral type 't'. |
64 | | -** (That is, maximum 'n' such that '2^n' fits in the given signed type.) |
65 | | -*/ |
66 | | -#define log2maxs(t) (l_numbits(t) - 2) |
67 | | - |
68 | | - |
69 | 62 | /* |
70 | 63 | ** test whether an unsigned value is a power of 2 (or zero) |
71 | 64 | */ |
@@ -287,6 +280,55 @@ typedef unsigned long l_uint32; |
287 | 280 | #endif |
288 | 281 |
|
289 | 282 |
|
| 283 | + |
| 284 | +/* |
| 285 | +** lua_numbertointeger converts a float number with an integral value |
| 286 | +** to an integer, or returns 0 if the float is not within the range of |
| 287 | +** a lua_Integer. (The range comparisons are tricky because of |
| 288 | +** rounding. The tests here assume a two-complement representation, |
| 289 | +** where MININTEGER always has an exact representation as a float; |
| 290 | +** MAXINTEGER may not have one, and therefore its conversion to float |
| 291 | +** may have an ill-defined value.) |
| 292 | +*/ |
| 293 | +#define lua_numbertointeger(n,p) \ |
| 294 | + ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \ |
| 295 | + (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \ |
| 296 | + (*(p) = (LUA_INTEGER)(n), 1)) |
| 297 | + |
| 298 | + |
| 299 | + |
| 300 | +/* |
| 301 | +** LUAI_FUNC is a mark for all extern functions that are not to be |
| 302 | +** exported to outside modules. |
| 303 | +** LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables, |
| 304 | +** none of which to be exported to outside modules (LUAI_DDEF for |
| 305 | +** definitions and LUAI_DDEC for declarations). |
| 306 | +** Elf and MACH/gcc (versions 3.2 and later) mark them as "hidden" to |
| 307 | +** optimize access when Lua is compiled as a shared library. Not all elf |
| 308 | +** targets support this attribute. Unfortunately, gcc does not offer |
| 309 | +** a way to check whether the target offers that support, and those |
| 310 | +** without support give a warning about it. To avoid these warnings, |
| 311 | +** change to the default definition. |
| 312 | +*/ |
| 313 | +#if !defined(LUAI_FUNC) |
| 314 | + |
| 315 | +#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ |
| 316 | + (defined(__ELF__) || defined(__MACH__)) |
| 317 | +#define LUAI_FUNC __attribute__((visibility("internal"))) extern |
| 318 | +#else |
| 319 | +#define LUAI_FUNC extern |
| 320 | +#endif |
| 321 | + |
| 322 | +#define LUAI_DDEC(dec) LUAI_FUNC dec |
| 323 | +#define LUAI_DDEF /* empty */ |
| 324 | + |
| 325 | +#endif |
| 326 | + |
| 327 | + |
| 328 | +/* Give these macros simpler names for internal use */ |
| 329 | +#define l_likely(x) luai_likely(x) |
| 330 | +#define l_unlikely(x) luai_unlikely(x) |
| 331 | + |
290 | 332 | /* |
291 | 333 | ** {================================================================== |
292 | 334 | ** "Abstraction Layer" for basic report of messages and errors |
|
0 commit comments