core: Increase type safety of some local alloc functions

This commit is contained in:
Colin Walters 2012-05-03 13:26:24 -04:00
parent 19571c7652
commit ff3867c052
2 changed files with 15 additions and 10 deletions

View File

@ -45,23 +45,28 @@ ot_local_free (void *loc)
void
ot_local_obj_unref (void *loc)
{
_ot_local_free(GObject, g_object_unref);
GObject **location = (GObject**)loc;
if (location && *location)
g_object_unref (*location);
}
void
ot_local_variant_unref (void *loc)
ot_local_variant_unref (GVariant **loc)
{
_ot_local_free(GVariant, g_variant_unref);
if (loc && *loc)
g_variant_unref (*loc);
}
void
ot_local_ptrarray_unref (void *loc)
ot_local_ptrarray_unref (GPtrArray **loc)
{
_ot_local_free(GPtrArray, g_ptr_array_unref);
if (loc && *loc)
g_ptr_array_unref (*loc);
}
void
ot_local_hashtable_unref (void *loc)
ot_local_hashtable_unref (GHashTable **loc)
{
_ot_local_free(GHashTable, g_hash_table_unref);
if (loc && *loc)
g_hash_table_unref (*loc);
}

View File

@ -29,9 +29,9 @@ G_BEGIN_DECLS
void ot_local_free (void *loc);
void ot_local_obj_unref (void *loc);
void ot_local_variant_unref (void *loc);
void ot_local_ptrarray_unref (void *loc);
void ot_local_hashtable_unref (void *loc);
void ot_local_variant_unref (GVariant **loc);
void ot_local_ptrarray_unref (GPtrArray **loc);
void ot_local_hashtable_unref (GHashTable **loc);
#define ot_lfree __attribute__ ((cleanup(ot_local_free)))
#define ot_lobj __attribute__ ((cleanup(ot_local_obj_unref)))