From 286823227c8c06e729dd939ec53b124c5c9afbc4 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Sat, 6 Feb 2010 21:08:56 +0200 Subject: [PATCH 1/3] Make int32_t available on all systems Use AC_TYPE_INT32_T and include inttypes.h (if it exists) instead of stdint.h for maximum portability. --- configure.ac | 1 + src/dump.c | 1 - src/load.c | 1 - src/utf.h | 9 +++++++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 95a207e..6bc9064 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,7 @@ AC_PROG_LIBTOOL # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_INT32_T # Checks for library functions. diff --git a/src/dump.c b/src/dump.c index e8ae440..bc06dfd 100644 --- a/src/dump.c +++ b/src/dump.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include diff --git a/src/load.c b/src/load.c index bcc7aa7..baf3183 100644 --- a/src/load.c +++ b/src/load.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include "jansson_private.h" diff --git a/src/utf.h b/src/utf.h index 95abdc9..d0ae6e9 100644 --- a/src/utf.h +++ b/src/utf.h @@ -8,6 +8,15 @@ #ifndef UTF_H #define UTF_H +#include + +#ifdef HAVE_INTTYPES_H +/* inttypes.h includes stdint.h in a standard environment, so there's +no need to include stdint.h separately. If inttypes.h doesn't define +int32_t, it's defined in config.h. */ +#include +#endif + int utf8_encode(int codepoint, char *buffer, int *size); int utf8_check_first(char byte); From a2a9107600da8ed0302e414fef8b9e70233e71ca Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 18 Mar 2010 07:18:43 +0200 Subject: [PATCH 2/3] Don't include stdint.h anywhere This should have fixed by commit 28682322, but there was one #include left in utf.c. It now includes utf.h instead of stdint.h. --- src/utf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utf.c b/src/utf.c index 9f4cb93..92484d0 100644 --- a/src/utf.c +++ b/src/utf.c @@ -6,7 +6,7 @@ */ #include -#include +#include "utf.h" int utf8_encode(int32_t codepoint, char *buffer, int *size) { From f284e3c069abcdfc1145e939b0c284910c274d17 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Tue, 23 Mar 2010 08:08:57 +0200 Subject: [PATCH 3/3] Fix reference counting on true, false and null Initialize their reference counts to (unsigned int)-1 to disable reference counting on them. It already was meant to work like this, but the reference counts were just initialized to 1 instead of -1. Thanks to Andrew Thompson for reporting this issue. --- src/value.c | 6 +++--- test/suites/api/test_simple.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/value.c b/src/value.c index 345ff8e..3fa7ee3 100644 --- a/src/value.c +++ b/src/value.c @@ -784,7 +784,7 @@ json_t *json_true(void) { static json_t the_true = { .type = JSON_TRUE, - .refcount = (unsigned int)1 + .refcount = (unsigned int)-1 }; return &the_true; } @@ -794,7 +794,7 @@ json_t *json_false(void) { static json_t the_false = { .type = JSON_FALSE, - .refcount = (unsigned int)1 + .refcount = (unsigned int)-1 }; return &the_false; } @@ -804,7 +804,7 @@ json_t *json_null(void) { static json_t the_null = { .type = JSON_NULL, - .refcount = (unsigned int)1 + .refcount = (unsigned int)-1 }; return &the_null; } diff --git a/test/suites/api/test_simple.c b/test/suites/api/test_simple.c index 45f22c7..1769c65 100644 --- a/test/suites/api/test_simple.c +++ b/test/suites/api/test_simple.c @@ -150,5 +150,36 @@ int main() fail("json_null failed"); json_decref(value); + /* Test reference counting on singletons (true, false, null) */ + value = json_true(); + if(value->refcount != (unsigned int)-1) + fail("refcounting true works incorrectly"); + json_decref(value); + if(value->refcount != (unsigned int)-1) + fail("refcounting true works incorrectly"); + json_incref(value); + if(value->refcount != (unsigned int)-1) + fail("refcounting true works incorrectly"); + + value = json_false(); + if(value->refcount != (unsigned int)-1) + fail("refcounting false works incorrectly"); + json_decref(value); + if(value->refcount != (unsigned int)-1) + fail("refcounting false works incorrectly"); + json_incref(value); + if(value->refcount != (unsigned int)-1) + fail("refcounting false works incorrectly"); + + value = json_null(); + if(value->refcount != (unsigned int)-1) + fail("refcounting null works incorrectly"); + json_decref(value); + if(value->refcount != (unsigned int)-1) + fail("refcounting null works incorrectly"); + json_incref(value); + if(value->refcount != (unsigned int)-1) + fail("refcounting null works incorrectly"); + return 0; }