From 156d88a02090b59d618d59801b35a6d29ba2bd15 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 4 May 2018 16:59:43 -0700 Subject: [PATCH] Switched hash to be stored in an 'int' instead of 'unsigned long long', so that it interacts consistenly with rawgeti and rawseti in Lua 5.1 api. --- limmutable.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/limmutable.c b/limmutable.c index e0675e2..833b526 100644 --- a/limmutable.c +++ b/limmutable.c @@ -52,7 +52,7 @@ static int WEAK_VALUE_METATABLE; static int SHARED_CLASS_METATABLE; typedef struct { - unsigned long long hash; + int hash; size_t len; } immutable_info_t; @@ -84,7 +84,7 @@ static int Lcreate_instance(lua_State *L) } // Compute the hash: - unsigned long long hash = 0x9a937c4d; // Seed + unsigned long long ull_hash = 0x9a937c4d; // Seed for (lua_Integer i=1; i <=(lua_Integer)n; i++) { unsigned long long item_hash; int type = n > n_args ? LUA_TNIL : lua_type(L, 1+i); @@ -128,8 +128,9 @@ static int Lcreate_instance(lua_State *L) default: item_hash = 0; } - hash = (1000003 * hash) ^ item_hash; + ull_hash = (1000003 * ull_hash) ^ item_hash; } + int hash = (int)ull_hash; lua_getfield(L, 1, "__instances"); @@ -356,7 +357,7 @@ static int Lindex(lua_State *L) lua_rawgeti(L, -1, info->hash); // Stack: [mt, indices, i, buckets, bucket] if (lua_isnil(L, -1)) { - luaL_error(L, "Failed to find hash bucket for hash: %p", (void*)info->hash); + luaL_error(L, "Failed to find hash bucket for hash: %d", info->hash); } lua_pushvalue(L, 1); // Stack: [mt, indices, i, buckets, bucket, inst_udata] @@ -593,7 +594,7 @@ static int Ltable(lua_State *L) lua_rawgeti(L, -1, info->hash); // Stack: [mt, buckets, bucket] if (lua_isnil(L, -1)) { - luaL_error(L, "Failed to find hash bucket for hash: %p", (void*)info->hash); + luaL_error(L, "Failed to find hash bucket for hash: %d", info->hash); } lua_pushvalue(L, 1); // Stack: [mt, buckets, bucket, inst_udata]