diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2015-11-07 17:38:22 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2016-03-01 14:53:02 +0000 |
commit | 1de237a502ceee96df7091c2df4492b8bc08b2c5 (patch) | |
tree | c9f51fdc9c370b57abe75e97200b3747a5f326bb /json-glib/json-types-private.h | |
parent | 58f479b60eb2db4c73605d469d68a8ffd8679327 (diff) | |
download | json-glib-1de237a502ceee96df7091c2df4492b8bc08b2c5.tar.gz |
node: Add json_node_ref() and json_node_unref()
Add reference counting semantics to JsonNode, in addition to the
existing init/unset and alloc/free semantics.
json_node_free() must only be used with nodes allocated using
json_node_alloc(). json_node_unref() may be used with all nodes (if
correctly paired; it may be paired with json_node_alloc()).
It is not valid to call json_node_free() on a node whose reference count
is not 1.
https://bugzilla.gnome.org/show_bug.cgi?id=756121
Diffstat (limited to 'json-glib/json-types-private.h')
-rw-r--r-- | json-glib/json-types-private.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/json-glib/json-types-private.h b/json-glib/json-types-private.h index 34a3160..8934e9a 100644 --- a/json-glib/json-types-private.h +++ b/json-glib/json-types-private.h @@ -28,6 +28,12 @@ G_BEGIN_DECLS +#define JSON_NODE_IS_VALID(n) \ + ((n) != NULL && \ + (n)->type >= JSON_NODE_OBJECT && \ + (n)->type <= JSON_NODE_NULL && \ + (n)->ref_count >= 1) + typedef struct _JsonValue JsonValue; typedef enum { @@ -43,7 +49,10 @@ struct _JsonNode { /*< private >*/ JsonNodeType type; + + volatile gint ref_count; gboolean immutable : 1; + gboolean allocated : 1; union { JsonObject *object; @@ -54,8 +63,8 @@ struct _JsonNode JsonNode *parent; }; -#define JSON_VALUE_INIT { JSON_VALUE_INVALID, 1, { 0 } } -#define JSON_VALUE_INIT_TYPE(t) { (t), 1, { 0 } } +#define JSON_VALUE_INIT { JSON_VALUE_INVALID, 1, FALSE, { 0 }, NULL } +#define JSON_VALUE_INIT_TYPE(t) { (t), 1, FALSE, { 0 }, NULL } #define JSON_VALUE_IS_VALID(v) ((v) != NULL && (v)->type != JSON_VALUE_INVALID) #define JSON_VALUE_HOLDS(v,t) ((v) != NULL && (v)->type == (t)) #define JSON_VALUE_HOLDS_INT(v) (JSON_VALUE_HOLDS((v), JSON_VALUE_INT)) |