diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-02-02 13:37:11 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-02-02 13:37:11 -0300 |
commit | c888ae0aea030491f90b749260a156ce15635681 (patch) | |
tree | 0020da1138ef004e62a25789b458fa5072185326 | |
parent | d69789da1ccfa4db7c241de6b471d6b729f1561e (diff) | |
download | lua-github-c888ae0aea030491f90b749260a156ce15635681.tar.gz |
Small changes in hash of pointers
When converting from pointer to integer, use 'uintptr_t' if available;
otherwise try 'uintmax_t', and use 'size_t' as last resource.
-rw-r--r-- | llimits.h | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -71,11 +71,24 @@ typedef signed char ls_byte; /* -** conversion of pointer to unsigned integer: -** this is for hashing only; there is no problem if the integer -** cannot hold the whole pointer value +** 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.) */ -#define point2uint(p) ((unsigned int)((size_t)(p) & UINT_MAX)) +#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 199901L +#include <stdint.h> +#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 largerst available integer */ +#endif +#else /* C89 option */ +#define L_P2I size_t +#endif + +#define point2uint(p) ((unsigned int)((L_P2I)(p) & UINT_MAX)) |