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.
static inline json_t *json_incref(json_t *json)
{
static inline json_t *json_incref(json_t *json)
{
+ if(json && json->refcount != (unsigned int)-1)
++json->refcount;
return json;
}
++json->refcount;
return json;
}
static inline void json_decref(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)
{
static json_t the_true = {
.type = JSON_TRUE,
{
static json_t the_true = {
.type = JSON_TRUE,
+ .refcount = (unsigned int)1
- return json_incref(&the_true);
{
static json_t the_false = {
.type = JSON_FALSE,
{
static json_t the_false = {
.type = JSON_FALSE,
+ .refcount = (unsigned int)1
- return json_incref(&the_false);
{
static json_t the_null = {
.type = JSON_NULL,
{
static json_t the_null = {
.type = JSON_NULL,
+ .refcount = (unsigned int)1
- return json_incref(&the_null);