From bc849819d9882feaa70fe56a725a897c14f295b6 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Wed, 27 Jul 2022 09:47:22 -0400 Subject: [PATCH] Make HashMap and Json conform to C89. Clang on OpenBSD didn't catch this, but GCC on Linux did. --- src/HashMap.c | 15 +++++++-------- src/Json.c | 6 +++--- src/Telodendria.c | 1 - src/include/Json.h | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/HashMap.c b/src/HashMap.c index 087d9dc..d70554b 100644 --- a/src/HashMap.c +++ b/src/HashMap.c @@ -1,12 +1,11 @@ #include -#include #include #include typedef struct HashMapBucket { - uint32_t hash; + unsigned long hash; char *key; void *value; } HashMapBucket; @@ -21,15 +20,15 @@ struct HashMap size_t iterator; }; -static uint32_t +static unsigned long HashMapHashKey(const char *key) { - uint32_t hash = 2166136261u; + unsigned long hash = 2166136261u; size_t i = 0; while (key[i]) { - hash ^= (uint8_t) key[i]; + hash ^= (unsigned char) key[i]; hash *= 16777619; i++; @@ -128,7 +127,7 @@ HashMapCreate(void) void * HashMapDelete(HashMap * map, const char *key) { - uint32_t hash; + unsigned long hash; size_t index; if (!map || !key) @@ -182,7 +181,7 @@ HashMapFree(HashMap * map) void * HashMapGet(HashMap * map, const char *key) { - uint32_t hash; + unsigned long hash; size_t index; if (!map || !key) @@ -262,7 +261,7 @@ HashMapMaxLoadSet(HashMap * map, float load) void * HashMapSet(HashMap * map, char *key, void *value) { - uint32_t hash; + unsigned long hash; size_t index; if (!map || !key || !value) diff --git a/src/Json.c b/src/Json.c index 131a655..f1316f1 100644 --- a/src/Json.c +++ b/src/Json.c @@ -12,7 +12,7 @@ struct JsonValue HashMap *object; Array *array; char *string; - int64_t integer; + long integer; double floating; int boolean:1; } as; @@ -137,7 +137,7 @@ JsonValueAsString(JsonValue * value) } JsonValue * -JsonValueInteger(int64_t integer) +JsonValueInteger(long integer) { JsonValue *value; @@ -427,7 +427,7 @@ JsonEncodeValue(JsonValue * value, FILE * out) JsonEncodeString(value->as.string, out); break; case JSON_INTEGER: - fprintf(out, "%lld", value->as.integer); + fprintf(out, "%ld", value->as.integer); break; case JSON_FLOAT: fprintf(out, "%f", value->as.floating); diff --git a/src/Telodendria.c b/src/Telodendria.c index 783ca2d..f119682 100644 --- a/src/Telodendria.c +++ b/src/Telodendria.c @@ -6,7 +6,6 @@ #include #include #include -#include typedef enum ArgFlag { diff --git a/src/include/Json.h b/src/include/Json.h index a6d50df..129bd41 100644 --- a/src/include/Json.h +++ b/src/include/Json.h @@ -39,7 +39,7 @@ extern JsonValue * JsonValueString(char *string); extern JsonValue * - JsonValueInteger(int64_t integer); + JsonValueInteger(long integer); extern JsonValue * JsonValueFloat(double floating);