diff --git a/src/blua/llimits.h b/src/blua/llimits.h index d3e6ad98b..e35931ab0 100644 --- a/src/blua/llimits.h +++ b/src/blua/llimits.h @@ -41,6 +41,25 @@ typedef unsigned char lu_byte; */ #define IntPoint(p) ((unsigned int)(lu_mem)(p)) +/* +** conversion of pointer to unsigned integer: this is for hashing only; +** there is no problem if the integer cannot hold the whole pointer +** value. (In strict ISO C this may cause undefined behavior, but no +** actual machine seems to bother.) +*/ +#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 199901L +#include +#if defined(UINTPTR_MAX) /* even in C99 this type is optional */ +#define L_P2I uintptr_t +#else /* no 'intptr'? */ +#define L_P2I uintmax_t /* use the largest available integer */ +#endif +#else /* C89 option */ +#define L_P2I size_t +#endif + +#define point2uint(p) ((unsigned int)((L_P2I)(p) & UINT_MAX)) /* type to ensure maximum alignment */ diff --git a/src/blua/lstring.c b/src/blua/lstring.c index 83a0a3721..860347134 100644 --- a/src/blua/lstring.c +++ b/src/blua/lstring.c @@ -191,7 +191,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { ** check hits. */ TString *luaS_new (lua_State *L, const char *str) { - unsigned int i = IntPoint(str) % STRCACHE_N; /* hash */ + unsigned int i = point2uint(str) % STRCACHE_N; /* hash */ int j; TString **p = G(L)->strcache[i]; for (j = 0; j < STRCACHE_M; j++) {