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.
This commit is contained in:
Nathaniel McCallum
2016-08-30 16:12:22 -04:00
parent ab1ba69027
commit 63b9fd0552
3 changed files with 44 additions and 0 deletions

View File

@@ -224,4 +224,17 @@ static void run_tests()
json_incref(value);
if(value->refcount != (size_t)-1)
fail("refcounting null works incorrectly");
#ifdef json_auto_t
value = json_string("foo");
{
json_auto_t *test = json_incref(value);
/* Use test so GCC doesn't complain it is unused. */
if(!json_is_string(test))
fail("value type check failed");
}
if(value->refcount != 1)
fail("automatic decrement failed");
json_decref(value);
#endif
}