]> git.kaiwu.me - klib.git/commitdiff
get rid of stdint.h for portability
authorHeng Li <lh3@me.com>
Sun, 30 Nov 2014 01:44:23 +0000 (20:44 -0500)
committerHeng Li <lh3@me.com>
Sun, 30 Nov 2014 01:44:23 +0000 (20:44 -0500)
kson.c
kson.h

diff --git a/kson.c b/kson.c
index c43b07354bfb649b2ad10236b3904e50ab2189b0..98ee974d1d73659dcf4ea71bb20d6f690350ac20 100644 (file)
--- a/kson.c
+++ b/kson.c
@@ -1,6 +1,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <assert.h>
 #include <ctype.h>
 #include <stdio.h>
 #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 64756c902f9d2bcf2eaceabadb732d5355869181..e31f5fe81d6374c78e81621b4164e4dabfdf6591 100644 (file)
--- a/kson.h
+++ b/kson.h
@@ -1,8 +1,6 @@
 #ifndef KSON_H
 #define KSON_H
 
-#include <stdint.h>
-
 #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;