From 7ee974e91c05d334b3a186937916bc843c537b8e Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Mon, 7 Sep 2009 21:40:14 +0300 Subject: [PATCH] Don't perform reference counting on true, false and null This makes their constructors thread safe. A special reference count -1 is used to test whether to perform reference counting on a value or not. --- src/jansson.h | 4 ++-- src/value.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/jansson.h b/src/jansson.h index 3aa10de..2e8582b 100644 --- a/src/jansson.h +++ b/src/jansson.h @@ -54,7 +54,7 @@ json_t *json_null(void); static inline json_t *json_incref(json_t *json) { - if(json) + if(json && json->refcount != (unsigned int)-1) ++json->refcount; return json; } @@ -64,7 +64,7 @@ void json_delete(json_t *json); static inline void json_decref(json_t *json) { - if(json && --json->refcount == 0) + if(json && json->refcount != (unsigned int)-1 && --json->refcount == 0) json_delete(json); } diff --git a/src/value.c b/src/value.c index c84bfd3..29f787c 100644 --- a/src/value.c +++ b/src/value.c @@ -431,9 +431,9 @@ json_t *json_true(void) { static json_t the_true = { .type = JSON_TRUE, - .refcount = 1 + .refcount = (unsigned int)1 }; - return json_incref(&the_true); + return &the_true; } @@ -441,9 +441,9 @@ json_t *json_false(void) { static json_t the_false = { .type = JSON_FALSE, - .refcount = 1 + .refcount = (unsigned int)1 }; - return json_incref(&the_false); + return &the_false; } @@ -451,9 +451,9 @@ json_t *json_null(void) { static json_t the_null = { .type = JSON_NULL, - .refcount = 1 + .refcount = (unsigned int)1 }; - return json_incref(&the_null); + return &the_null; } -- 2.7.4