From 37cfc912c1f384d177162f8aa706452754d2c6ab Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Sun, 23 Jun 2013 14:23:07 +0100 Subject: [PATCH] Remove #includes from jv.h --- builtin.c | 1 + jq_test.c | 4 ++-- jv.c | 7 ++++++- jv.h | 17 +++++------------ jv_aux.c | 1 + jv_parse.c | 1 + jv_print.c | 1 + lexer.l | 1 + parser.y | 1 + 9 files changed, 19 insertions(+), 15 deletions(-) diff --git a/builtin.c b/builtin.c index 826d8c92..7ef64d5a 100644 --- a/builtin.c +++ b/builtin.c @@ -1,5 +1,6 @@ #include #include +#include #include "builtin.h" #include "compile.h" #include "jq_parser.h" diff --git a/jq_test.c b/jq_test.c index 9e39594f..f10a258a 100644 --- a/jq_test.c +++ b/jq_test.c @@ -125,9 +125,9 @@ static void jv_test() { jv_free(a2); - assert(a.val.nontrivial.ptr->count == 1); + assert(jv_get_refcnt(a) == 1); a = jv_array_append(a, jv_copy(a)); - assert(a.val.nontrivial.ptr->count == 1); + assert(jv_get_refcnt(a) == 1); assert(jv_array_length(jv_copy(a)) == 2); assert(jv_number_value(jv_array_get(jv_copy(a), 0)) == 42); diff --git a/jv.c b/jv.c index 9316aec1..46f7dbf0 100644 --- a/jv.c +++ b/jv.c @@ -14,6 +14,11 @@ * Internal refcounting helpers */ +typedef struct jv_refcnt { + size_t count; +} jv_refcnt; + + static void jvp_refcnt_init(jv_nontrivial* c) { c->ptr->count = 1; } @@ -548,7 +553,7 @@ int jv_string_length_codepoints(jv j) { return len; } -uint32_t jv_string_hash(jv j) { +unsigned long jv_string_hash(jv j) { assert(jv_get_kind(j) == JV_KIND_STRING); uint32_t hash = jvp_string_hash(jvp_string_ptr(&j.val.nontrivial)); jv_free(j); diff --git a/jv.h b/jv.h index 420b9bd9..a9010211 100644 --- a/jv.h +++ b/jv.h @@ -1,12 +1,6 @@ #ifndef JV_H #define JV_H -#include -#include -#include - - - typedef enum { JV_KIND_INVALID, JV_KIND_NULL, @@ -18,12 +12,9 @@ typedef enum { JV_KIND_OBJECT } jv_kind; -typedef struct { - size_t count; -} jv_refcnt; - +struct jv_refcnt; typedef struct{ - jv_refcnt* ptr; + struct jv_refcnt* ptr; int i[2]; } jv_nontrivial; @@ -47,6 +38,8 @@ static int jv_is_valid(jv x) { return jv_get_kind(x) != JV_KIND_INVALID; } jv jv_copy(jv); void jv_free(jv); +int jv_get_refcnt(jv); + int jv_equal(jv, jv); int jv_contains(jv, jv); @@ -84,7 +77,7 @@ jv jv_string(const char*); jv jv_string_sized(const char*, int); int jv_string_length_bytes(jv); int jv_string_length_codepoints(jv); -uint32_t jv_string_hash(jv); +unsigned long jv_string_hash(jv); const char* jv_string_value(jv); jv jv_string_concat(jv, jv); jv jv_string_fmt(const char*, ...); diff --git a/jv_aux.c b/jv_aux.c index eb4ded03..b73c9057 100644 --- a/jv_aux.c +++ b/jv_aux.c @@ -1,5 +1,6 @@ #include #include +#include #include "jv_alloc.h" static int parse_slice(jv array, jv slice, int* pstart, int* pend) { diff --git a/jv_parse.c b/jv_parse.c index 4418cb08..cc1e7b96 100644 --- a/jv_parse.c +++ b/jv_parse.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "jv.h" #include "jv_dtoa.h" #include "jv_unicode.h" diff --git a/jv_print.c b/jv_print.c index 890de040..da90abfb 100644 --- a/jv_print.c +++ b/jv_print.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "jv_dtoa.h" #include "jv_unicode.h" diff --git a/lexer.l b/lexer.l index 96c0efc4..e8d73d6c 100644 --- a/lexer.l +++ b/lexer.l @@ -1,4 +1,5 @@ %{ +#include #include "jv_alloc.h" #include "compile.h" diff --git a/parser.y b/parser.y index 4ec10383..c8713de4 100644 --- a/parser.y +++ b/parser.y @@ -1,6 +1,7 @@ %{ #include #include +#include #include "compile.h" #include "jv_alloc.h" #define YYMALLOC jv_mem_alloc