Browse Source

Always include <stdint.h>, unless HASH_NO_STDINT is defined by the user.

See 762026ce and b1d8ab07 for previous attempts (circa 2014-2015)
to detect whether it's OK to use <stdint.h>; and see #211 for
how that logic is still incomplete.

Rather than continue down this path, how about we just say that
your system should either be C99 (it's the year 2020!), or you
should provide your own "polyfill" version of <stdint.h> in the
normal search path, or you should `-DHASH_NO_STDINT` and figure
out the details yourself (e.g. by providing the necessary typedefs
above where you `#include <uthash.h>`).

Also support `-DHASH_DEFINE_OWN_STDINT` for this next release,
so that there's an easy backward-compatibility mode. I plan to
rip out that mode in the release after next, though.
Arthur O'Dwyer 4 years ago
parent
commit
15ad04278f
1 changed files with 10 additions and 17 deletions
  1. 10 17
      src/uthash.h

+ 10 - 17
src/uthash.h

@@ -30,6 +30,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <stddef.h>   /* ptrdiff_t */
 #include <stddef.h>   /* ptrdiff_t */
 #include <stdlib.h>   /* exit */
 #include <stdlib.h>   /* exit */
 
 
+#if defined(HASH_DEFINE_OWN_STDINT) && HASH_DEFINE_OWN_STDINT
+/* This codepath is provided for backward compatibility, but I plan to remove it. */
+#warning "HASH_DEFINE_OWN_STDINT is deprecated; please use HASH_NO_STDINT instead"
+typedef unsigned int uint32_t;
+typedef unsigned char uint8_t;
+#elif defined(HASH_NO_STDINT) && HASH_NO_STDINT
+#else
+#include <stdint.h>   /* uint8_t, uint32_t */
+#endif
+
 /* These macros use decltype or the earlier __typeof GNU extension.
 /* These macros use decltype or the earlier __typeof GNU extension.
    As decltype is only available in newer compilers (VS2010 or gcc 4.3+
    As decltype is only available in newer compilers (VS2010 or gcc 4.3+
    when compiling c++ source) this code uses whatever method is needed
    when compiling c++ source) this code uses whatever method is needed
@@ -62,23 +72,6 @@ do {
 } while (0)
 } while (0)
 #endif
 #endif
 
 
-/* a number of the hash function use uint32_t which isn't defined on Pre VS2010 */
-#if defined(_WIN32)
-#if defined(_MSC_VER) && _MSC_VER >= 1600
-#include <stdint.h>
-#elif defined(__WATCOMC__) || defined(__MINGW32__) || defined(__CYGWIN__)
-#include <stdint.h>
-#else
-typedef unsigned int uint32_t;
-typedef unsigned char uint8_t;
-#endif
-#elif defined(__GNUC__) && !defined(__VXWORKS__)
-#include <stdint.h>
-#else
-typedef unsigned int uint32_t;
-typedef unsigned char uint8_t;
-#endif
-
 #ifndef uthash_malloc
 #ifndef uthash_malloc
 #define uthash_malloc(sz) malloc(sz)      /* malloc fcn                      */
 #define uthash_malloc(sz) malloc(sz)      /* malloc fcn                      */
 #endif
 #endif