Make HashMap and Json conform to C89.

Clang on OpenBSD didn't catch this, but GCC on Linux did.
This commit is contained in:
Jordan Bancino 2022-07-27 09:47:22 -04:00
parent e232fd683e
commit bc849819d9
4 changed files with 11 additions and 13 deletions

View file

@ -1,12 +1,11 @@
#include <HashMap.h> #include <HashMap.h>
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
typedef struct HashMapBucket typedef struct HashMapBucket
{ {
uint32_t hash; unsigned long hash;
char *key; char *key;
void *value; void *value;
} HashMapBucket; } HashMapBucket;
@ -21,15 +20,15 @@ struct HashMap
size_t iterator; size_t iterator;
}; };
static uint32_t static unsigned long
HashMapHashKey(const char *key) HashMapHashKey(const char *key)
{ {
uint32_t hash = 2166136261u; unsigned long hash = 2166136261u;
size_t i = 0; size_t i = 0;
while (key[i]) while (key[i])
{ {
hash ^= (uint8_t) key[i]; hash ^= (unsigned char) key[i];
hash *= 16777619; hash *= 16777619;
i++; i++;
@ -128,7 +127,7 @@ HashMapCreate(void)
void * void *
HashMapDelete(HashMap * map, const char *key) HashMapDelete(HashMap * map, const char *key)
{ {
uint32_t hash; unsigned long hash;
size_t index; size_t index;
if (!map || !key) if (!map || !key)
@ -182,7 +181,7 @@ HashMapFree(HashMap * map)
void * void *
HashMapGet(HashMap * map, const char *key) HashMapGet(HashMap * map, const char *key)
{ {
uint32_t hash; unsigned long hash;
size_t index; size_t index;
if (!map || !key) if (!map || !key)
@ -262,7 +261,7 @@ HashMapMaxLoadSet(HashMap * map, float load)
void * void *
HashMapSet(HashMap * map, char *key, void *value) HashMapSet(HashMap * map, char *key, void *value)
{ {
uint32_t hash; unsigned long hash;
size_t index; size_t index;
if (!map || !key || !value) if (!map || !key || !value)

View file

@ -12,7 +12,7 @@ struct JsonValue
HashMap *object; HashMap *object;
Array *array; Array *array;
char *string; char *string;
int64_t integer; long integer;
double floating; double floating;
int boolean:1; int boolean:1;
} as; } as;
@ -137,7 +137,7 @@ JsonValueAsString(JsonValue * value)
} }
JsonValue * JsonValue *
JsonValueInteger(int64_t integer) JsonValueInteger(long integer)
{ {
JsonValue *value; JsonValue *value;
@ -427,7 +427,7 @@ JsonEncodeValue(JsonValue * value, FILE * out)
JsonEncodeString(value->as.string, out); JsonEncodeString(value->as.string, out);
break; break;
case JSON_INTEGER: case JSON_INTEGER:
fprintf(out, "%lld", value->as.integer); fprintf(out, "%ld", value->as.integer);
break; break;
case JSON_FLOAT: case JSON_FLOAT:
fprintf(out, "%f", value->as.floating); fprintf(out, "%f", value->as.floating);

View file

@ -6,7 +6,6 @@
#include <Log.h> #include <Log.h>
#include <HashMap.h> #include <HashMap.h>
#include <Config.h> #include <Config.h>
#include <Base64.h>
typedef enum ArgFlag typedef enum ArgFlag
{ {

View file

@ -39,7 +39,7 @@ extern JsonValue *
JsonValueString(char *string); JsonValueString(char *string);
extern JsonValue * extern JsonValue *
JsonValueInteger(int64_t integer); JsonValueInteger(long integer);
extern JsonValue * extern JsonValue *
JsonValueFloat(double floating); JsonValueFloat(double floating);