aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathaniel McCallum <npmccallum@redhat.com>2016-08-30 16:12:22 -0400
committerNathaniel McCallum <npmccallum@redhat.com>2016-08-31 08:57:57 -0400
commit63b9fd055248bcd427fd455ce9623431885b235e (patch)
treed57c41eac5762d4593b8c5a2932d72b181f383e6 /src
parentab1ba6902766615b617f1a01214f20f1ec5907e2 (diff)
downloadjansson-63b9fd055248bcd427fd455ce9623431885b235e.zip
jansson-63b9fd055248bcd427fd455ce9623431885b235e.tar.gz
jansson-63b9fd055248bcd427fd455ce9623431885b235e.tar.bz2
Add support for the cleanup attribute in GCC/Clang
The new json_auto_t macro allows easy declaration of json_t types that automatically decrement at the end of their scope.
Diffstat (limited to 'src')
-rw-r--r--src/jansson.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/jansson.h b/src/jansson.h
index 17a6e7a..b1a040a 100644
--- a/src/jansson.h
+++ b/src/jansson.h
@@ -112,6 +112,19 @@ void json_decref(json_t *json)
json_delete(json);
}
+#if defined(__GNUC__) || defined(__clang__)
+static JSON_INLINE
+void json_decrefp(json_t **json)
+{
+ if(json) {
+ json_decref(*json);
+ *json = NULL;
+ }
+}
+
+#define json_auto_t json_t __attribute__((cleanup(json_decrefp)))
+#endif
+
/* error reporting */