From: Heng Li Date: Sun, 30 Nov 2014 01:44:23 +0000 (-0500) Subject: get rid of stdint.h for portability X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=e7de1ac7bad35a9189f59e2e494335eb3521ecd1;p=klib.git get rid of stdint.h for portability --- diff --git a/kson.c b/kson.c index c43b073..98ee974 100644 --- a/kson.c +++ b/kson.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "kson.h" @@ -14,7 +15,7 @@ kson_node_t *kson_parse_core(const char *json, long *_n, int *error, long *parse long *stack = 0, top = 0, max = 0, n_a = 0, m_a = 0, i, j; kson_node_t *a = 0, *u; const char *p, *q; - intptr_t *tmp; + size_t *tmp; #define __push_back(y) do { \ if (top == max) { \ @@ -34,6 +35,7 @@ kson_node_t *kson_parse_core(const char *json, long *_n, int *error, long *parse *(z) = &a[n_a++]; \ } while (0) + assert(sizeof(size_t) == sizeof(kson_node_t*)); *error = KSON_OK; for (p = json; *p; ++p) { while (*p && isspace(*p)) ++p; @@ -58,7 +60,7 @@ kson_node_t *kson_parse_core(const char *json, long *_n, int *error, long *parse u->key = u->v.str; u->n = top - 1 - start; u->v.child = (kson_node_t**)malloc(u->n * sizeof(kson_node_t*)); - tmp = (intptr_t*)u->v.child; + tmp = (size_t*)u->v.child; for (i = start + 1; i < top; ++i) tmp[i - start - 1] = stack[i]; u->type = *p == ']'? KSON_TYPE_BRACKET : KSON_TYPE_BRACE; @@ -98,7 +100,7 @@ kson_node_t *kson_parse_core(const char *json, long *_n, int *error, long *parse if (top != 1) *error = KSON_ERR_EXTRA_LEFT; for (i = 0; i < n_a; ++i) - for (j = 0, u = &a[i], tmp = (intptr_t*)u->v.child; j < (long)u->n; ++j) + for (j = 0, u = &a[i], tmp = (size_t*)u->v.child; j < (long)u->n; ++j) u->v.child[j] = &a[tmp[j]]; free(stack); diff --git a/kson.h b/kson.h index 64756c9..e31f5fe 100644 --- a/kson.h +++ b/kson.h @@ -1,8 +1,6 @@ #ifndef KSON_H #define KSON_H -#include - #define KSON_TYPE_NO_QUOTE 1 #define KSON_TYPE_SGL_QUOTE 2 #define KSON_TYPE_DBL_QUOTE 3 @@ -15,7 +13,7 @@ #define KSON_ERR_NO_KEY 3 typedef struct kson_node_s { - uint64_t type:3, n:61; + unsigned long long type:3, n:61; char *key; union { struct kson_node_s **child;