projects/aports·blob master · refs

84 lines · 2.7 KiB

1Patch from: https://github.com/LuaJIT/LuaJIT/issues/384
2
3diff -ur LuaBitOp-1.0.2/bit.c LuaBitOp-1.0.3/bit.c
4--- LuaBitOp-1.0.2/bit.c 2012-05-08 15:15:00.000000000 -0400
5+++ LuaBitOp-1.0.3/bit.c 2018-01-20 21:41:00.037749052 -0500
6@@ -26,7 +26,7 @@
7 ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
8 */
9
10-#define LUA_BITOP_VERSION "1.0.2"
11+#define LUA_BITOP_VERSION "1.0.3"
12
13 #define LUA_LIB
14 #include "lua.h"
15@@ -46,7 +46,7 @@
16
17 typedef union {
18 lua_Number n;
19-#ifdef LUA_NUMBER_DOUBLE
20+#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE)
21 uint64_t b;
22 #else
23 UBits b;
24@@ -63,24 +63,25 @@
25 #else
26 bn.n = luaL_checknumber(L, idx);
27 #endif
28-#if defined(LUA_NUMBER_DOUBLE)
29+#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE)
30 bn.n += 6755399441055744.0; /* 2^52+2^51 */
31 #ifdef SWAPPED_DOUBLE
32 b = (UBits)(bn.b >> 32);
33 #else
34 b = (UBits)bn.b;
35 #endif
36-#elif defined(LUA_NUMBER_INT) || defined(LUA_NUMBER_LONG) || \
37- defined(LUA_NUMBER_LONGLONG) || defined(LUA_NUMBER_LONG_LONG) || \
38- defined(LUA_NUMBER_LLONG)
39+#elif defined(LUA_NUMBER_INT) || defined(LUA_INT_INT) || \
40+ defined(LUA_NUMBER_LONG) || defined(LUA_INT_LONG) || \
41+ defined(LUA_NUMBER_LONGLONG) || defined(LUA_INT_LONGLONG) || \
42+ defined(LUA_NUMBER_LONG_LONG) || defined(LUA_NUMBER_LLONG)
43 if (sizeof(UBits) == sizeof(lua_Number))
44 b = bn.b;
45 else
46 b = (UBits)(SBits)bn.n;
47-#elif defined(LUA_NUMBER_FLOAT)
48+#elif defined(LUA_NUMBER_FLOAT) || defined(LUA_FLOAT_FLOAT)
49 #error "A 'float' lua_Number type is incompatible with this library"
50 #else
51-#error "Unknown number type, check LUA_NUMBER_* in luaconf.h"
52+#error "Unknown number type, check LUA_NUMBER_*, LUA_FLOAT_*, LUA_INT_* in luaconf.h"
53 #endif
54 #if LUA_VERSION_NUM < 502
55 if (b == 0 && !lua_isnumber(L, idx)) {
56@@ -91,7 +92,11 @@
57 }
58
59 /* Return bit type. */
60+#if LUA_VERSION_NUM < 503
61 #define BRET(b) lua_pushnumber(L, (lua_Number)(SBits)(b)); return 1;
62+#else
63+#define BRET(b) lua_pushinteger(L, (lua_Integer)(SBits)(b)); return 1;
64+#endif
65
66 static int bit_tobit(lua_State *L) { BRET(barg(L, 1)) }
67 static int bit_bnot(lua_State *L) { BRET(~barg(L, 1)) }
68@@ -163,11 +168,15 @@
69 LUALIB_API int luaopen_bit(lua_State *L)
70 {
71 UBits b;
72+#if LUA_VERSION_NUM < 503
73 lua_pushnumber(L, (lua_Number)1437217655L);
74+#else
75+ lua_pushinteger(L, (lua_Integer)1437217655L);
76+#endif
77 b = barg(L, -1);
78 if (b != (UBits)1437217655L || BAD_SAR) { /* Perform a simple self-test. */
79 const char *msg = "compiled with incompatible luaconf.h";
80-#ifdef LUA_NUMBER_DOUBLE
81+#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_FLOAT_DOUBLE)
82 #ifdef _WIN32
83 if (b == (UBits)1610612736L)
84 msg = "use D3DCREATE_FPU_PRESERVE with DirectX";