Improve full-lightuserdata check on 32-bit platforms.

On 32-bit platforms, full-lightuserdata is always supported since their pointer fits entirely in 2^48 limitation that LuaJIT had in older version.

Also suppress warning about key > 0x20000000000000ULL is always false on enet.cpp when compiling on 32-bit platforms.
This commit is contained in:
Miku AuahDark
2023-05-23 11:12:34 +08:00
parent f7432bd2d4
commit 4cd0bc0de4
2 changed files with 14 additions and 3 deletions
+4
View File
@@ -106,6 +106,10 @@ static bool luax_isfulllightuserdatasupported(lua_State *L)
static bool checked = false;
static bool supported = false;
if (sizeof(void*) == 4)
// 32-bit platforms always supports full-lightuserdata.
return true;
if (!checked)
{
lua_pushcclosure(L, [](lua_State *L) -> int
+10 -3
View File
@@ -123,6 +123,10 @@ static bool supports_full_lightuserdata(lua_State *L)
static bool checked = false;
static bool supported = false;
if (sizeof(void*) == 4)
// 32-bit platforms always supports full-lightuserdata.
return true;
if (!checked)
{
lua_pushcclosure(L, [](lua_State* L) -> int
@@ -168,13 +172,16 @@ static uintptr_t compute_peer_key(lua_State *L, ENetPeer *peer)
static void push_peer_key(lua_State *L, uintptr_t key)
{
// If full 64-bit lightuserdata is supported, always use that. Otherwise,
// if the key is smaller than 2^53 (which is integer precision for double
// datatype), then push number. Otherwise, throw error.
// If full 64-bit lightuserdata is supported (or it's 32-bit platform),
// always use that. Otherwise, if the key is smaller than 2^53 (which is
// integer precision for double datatype) on 64-bit platform, then push
// number. Otherwise, throw error.
if (supports_full_lightuserdata(L))
lua_pushlightuserdata(L, (void*) key);
#if UINTPTR_MAX == 0xffffffffffffffff
else if (key > 0x20000000000000ULL) // 2^53
luaL_error(L, "Cannot push enet peer to Lua: pointer value %p is too large", key);
#endif
else
lua_pushnumber(L, (lua_Number) key);
}