[ostree] core: Ad ot_clear_gvariant(), use it
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: Ad ot_clear_gvariant(), use it
- Date: Fri, 25 Nov 2011 17:03:35 +0000 (UTC)
commit 3c025e526f5a501414235c4dd5aa29162c1b6251
Author: Colin Walters <walters verbum org>
Date: Tue Nov 22 10:20:10 2011 -0500
core: Ad ot_clear_gvariant(), use it
This saves us a conditional.
src/daemon/ot-daemon.c | 3 +-
src/libostree/ostree-core.c | 39 +++++----------
src/libostree/ostree-repo-file.c | 92 ++++++++++++++-----------------------
src/libostree/ostree-repo.c | 34 +++++---------
src/libotutil/ot-variant-utils.c | 3 +-
src/libotutil/ot-variant-utils.h | 6 ++
src/ostree/ot-builtin-compose.c | 3 +-
src/ostree/ot-builtin-fsck.c | 6 +--
src/ostree/ot-builtin-log.c | 9 +--
src/ostree/ot-builtin-pull.c | 12 ++---
src/ostree/ot-builtin-rev-parse.c | 3 +-
src/ostree/ot-builtin-show.c | 18 ++-----
12 files changed, 85 insertions(+), 143 deletions(-)
---
diff --git a/src/daemon/ot-daemon.c b/src/daemon/ot-daemon.c
index d7793b7..7044880 100644
--- a/src/daemon/ot-daemon.c
+++ b/src/daemon/ot-daemon.c
@@ -113,8 +113,7 @@ op_return (OstreeDaemon *self,
ret = TRUE;
operation_free (op);
- if (args)
- g_variant_unref (args);
+ ot_clear_gvariant (&args);
return ret;
}
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index c7a1cb1..943c17e 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -205,10 +205,8 @@ checksum_directory (GFile *f,
out:
if (ret_checksum)
g_checksum_free (ret_checksum);
- if (dirmeta)
- g_variant_unref (dirmeta);
- if (packed)
- g_variant_unref (packed);
+ ot_clear_gvariant (&dirmeta);
+ ot_clear_gvariant (&packed);
return ret;
}
@@ -305,8 +303,7 @@ checksum_nondirectory (GFile *f,
out:
g_clear_object (&input);
g_free (basename);
- if (xattrs)
- g_variant_unref (xattrs);
+ ot_clear_gvariant (&xattrs);
if (content_sha256)
g_checksum_free (content_sha256);
return ret;
@@ -375,10 +372,8 @@ ostree_get_directory_metadata (GFile *dir,
*out_metadata = ret_metadata;
ret_metadata = NULL;
out:
- if (ret_metadata)
- g_variant_unref (ret_metadata);
- if (xattrs)
- g_variant_unref (xattrs);
+ ot_clear_gvariant (&ret_metadata);
+ ot_clear_gvariant (&xattrs);
return ret;
}
@@ -408,8 +403,7 @@ ostree_set_xattrs (GFile *f,
value_data = g_variant_get_fixed_array (value, &value_len, 1);
loop_err = lsetxattr (path, (char*)name, (char*)value_data, value_len, XATTR_REPLACE) < 0;
-
- g_variant_unref (value);
+ ot_clear_gvariant (&value);
if (loop_err)
{
ot_util_set_error_from_errno (error, errno);
@@ -453,10 +447,8 @@ ostree_parse_metadata_file (GFile *file,
*out_variant = ot_util_variant_take_ref (ret_variant);
ret_variant = NULL;
out:
- if (ret_variant)
- g_variant_unref (ret_variant);
- if (container != NULL)
- g_variant_unref (container);
+ ot_clear_gvariant (&ret_variant);
+ ot_clear_gvariant (&container);
return ret;
}
@@ -628,12 +620,10 @@ ostree_pack_object (GOutputStream *output,
out:
g_clear_object (&finfo);
g_clear_object (&instream);
- if (xattrs)
- g_variant_unref (xattrs);
+ ot_clear_gvariant (&xattrs);
if (pack_builder_initialized)
g_variant_builder_clear (&pack_builder);
- if (pack_variant)
- g_variant_unref (pack_variant);
+ ot_clear_gvariant (&pack_variant);
return ret;
}
@@ -770,8 +760,7 @@ ostree_parse_packed_file (GFile *file,
in = NULL;
out:
g_clear_object (&in);
- if (ret_metadata)
- g_variant_unref (ret_metadata);
+ ot_clear_gvariant (&ret_metadata);
return ret;
}
@@ -906,10 +895,8 @@ unpack_file (GFile *file,
g_checksum_free (ret_checksum);
g_clear_object (&in);
g_clear_object (&out);
- if (metadata)
- g_variant_unref (metadata);
- if (xattrs)
- g_variant_unref (xattrs);
+ ot_clear_gvariant (&metadata);
+ ot_clear_gvariant (&xattrs);
return ret;
}
diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c
index c4ff123..2f3106c 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -62,10 +62,8 @@ ostree_repo_file_finalize (GObject *object)
self = OSTREE_REPO_FILE (object);
- if (self->tree_contents)
- g_variant_unref (self->tree_contents);
- if (self->tree_metadata)
- g_variant_unref (self->tree_metadata);
+ ot_clear_gvariant (&self->tree_contents);
+ ot_clear_gvariant (&self->tree_metadata);
g_free (self->tree_contents_checksum);
g_free (self->tree_metadata_checksum);
g_free (self->commit);
@@ -194,12 +192,9 @@ do_resolve_commit (OstreeRepoFile *self,
root_contents = NULL;
out:
- if (commit)
- g_variant_unref (commit);
- if (root_metadata)
- g_variant_unref (root_metadata);
- if (root_contents)
- g_variant_unref (root_contents);
+ ot_clear_gvariant (&commit);
+ ot_clear_gvariant (&root_metadata);
+ ot_clear_gvariant (&root_contents);
return ret;
}
@@ -231,7 +226,7 @@ do_resolve_nonroot (OstreeRepoFile *self,
files_variant = g_variant_get_child_value (self->parent->tree_contents, 2);
self->index = g_variant_n_children (files_variant) + i;
- g_variant_unref (files_variant);
+ ot_clear_gvariant (&files_variant);
g_variant_get_child (container, i, "(&s&s&s)",
&name, &content_checksum, &metadata_checksum);
@@ -259,12 +254,9 @@ do_resolve_nonroot (OstreeRepoFile *self,
ret = TRUE;
out:
- if (container)
- g_variant_unref (container);
- if (tree_metadata)
- g_variant_unref (tree_metadata);
- if (tree_contents)
- g_variant_unref (tree_contents);
+ ot_clear_gvariant (&container);
+ ot_clear_gvariant (&tree_metadata);
+ ot_clear_gvariant (&tree_contents);
return ret;
}
@@ -330,10 +322,8 @@ _ostree_repo_file_get_xattrs (OstreeRepoFile *self,
*out_xattrs = ret_xattrs;
ret_xattrs = NULL;
out:
- if (ret_xattrs)
- g_variant_unref (ret_xattrs);
- if (metadata)
- g_variant_unref (metadata);
+ ot_clear_gvariant (&ret_xattrs);
+ ot_clear_gvariant (&metadata);
g_clear_object (&input);
g_clear_object (&local_file);
return ret;
@@ -356,8 +346,7 @@ _ostree_repo_file_tree_set_metadata (OstreeRepoFile *self,
const char *checksum,
GVariant *metadata)
{
- if (self->tree_metadata)
- g_variant_unref (self->tree_metadata);
+ ot_clear_gvariant (&self->tree_metadata);
self->tree_metadata = g_variant_ref (metadata);
g_free (self->tree_metadata_checksum);
self->tree_metadata_checksum = g_strdup (checksum);
@@ -436,9 +425,8 @@ _ostree_repo_file_get_checksum (OstreeRepoFile *self)
g_variant_get_child (files_variant, n,
"(@s&s)", NULL, &checksum);
}
-
- g_variant_unref (files_variant);
- g_variant_unref (dirs_variant);
+ ot_clear_gvariant (&files_variant);
+ ot_clear_gvariant (&dirs_variant);
return checksum;
}
@@ -854,8 +842,7 @@ query_child_info_file_archive (OstreeRepo *repo,
ret = TRUE;
out:
g_free (buf);
- if (metadata)
- g_variant_unref (metadata);
+ ot_clear_gvariant (&metadata);
g_clear_object (&local_file);
g_clear_object (&input);
return ret;
@@ -909,8 +896,7 @@ query_child_info_dir (OstreeRepo *repo,
ret = TRUE;
out:
- if (metadata)
- g_variant_unref (metadata);
+ ot_clear_gvariant (&metadata);
return ret;
}
@@ -944,11 +930,11 @@ bsearch_in_file_variant (GVariant *variant,
n = m - 1;
else
{
- g_variant_unref (child);
+ ot_clear_gvariant (&child);
*out_pos = m;
return TRUE;
}
- g_variant_unref (child);
+ ot_clear_gvariant (&child);
}
*out_pos = m;
@@ -972,7 +958,7 @@ remove_variant_child (GVariant *variant,
{
if (i != n)
g_variant_builder_add_value (&builder, child);
- g_variant_unref (child);
+ ot_clear_gvariant (&child);
}
g_variant_iter_free (iter);
@@ -998,7 +984,7 @@ insert_variant_child (GVariant *variant,
if (i == n)
g_variant_builder_add_value (&builder, item);
g_variant_builder_add_value (&builder, child);
- g_variant_unref (child);
+ ot_clear_gvariant (&child);
}
g_variant_iter_free (iter);
@@ -1034,17 +1020,13 @@ tree_replace_contents (OstreeRepoFile *self,
tmp_dirs = g_variant_get_child_value (self->tree_contents, 3);
}
- if (self->tree_contents)
- g_variant_unref (self->tree_contents);
+ ot_clear_gvariant (&self->tree_contents);
self->tree_contents = g_variant_new ("(u a{sv}@a(ss)@a(sss))", version, metadata,
new_files ? new_files : tmp_files,
new_dirs ? new_dirs : tmp_dirs);
- g_variant_unref (metadata);
- if (tmp_files)
- g_variant_unref (tmp_files);
- if (tmp_dirs)
- g_variant_unref (tmp_dirs);
+ ot_clear_gvariant (&tmp_files);
+ ot_clear_gvariant (&tmp_dirs);
}
void
@@ -1074,8 +1056,8 @@ _ostree_repo_file_tree_remove_child (OstreeRepoFile *self,
tree_replace_contents (self, new_files_variant, new_dirs_variant);
- g_variant_unref (files_variant);
- g_variant_unref (dirs_variant);
+ ot_clear_gvariant (&files_variant);
+ ot_clear_gvariant (&dirs_variant);
}
void
@@ -1095,9 +1077,9 @@ _ostree_repo_file_tree_add_file (OstreeRepoFile *self,
g_variant_new ("(ss)", name, checksum));
g_variant_ref_sink (new_files_variant);
tree_replace_contents (self, new_files_variant, NULL);
- g_variant_unref (new_files_variant);
+ ot_clear_gvariant (&new_files_variant);
}
- g_variant_unref (files_variant);
+ ot_clear_gvariant (&files_variant);
}
void
@@ -1119,9 +1101,9 @@ _ostree_repo_file_tree_add_dir (OstreeRepoFile *self,
metadata_checksum));
g_variant_ref_sink (new_dirs_variant);
tree_replace_contents (self, NULL, new_dirs_variant);
- g_variant_unref (new_dirs_variant);
+ ot_clear_gvariant (&new_dirs_variant);
}
- g_variant_unref (dirs_variant);
+ ot_clear_gvariant (&dirs_variant);
}
int
@@ -1163,12 +1145,9 @@ _ostree_repo_file_tree_find_child (OstreeRepoFile *self,
*out_container = ret_container;
ret_container = NULL;
}
- if (ret_container)
- g_variant_unref (ret_container);
- if (files_variant)
- g_variant_unref (files_variant);
- if (dirs_variant)
- g_variant_unref (dirs_variant);
+ ot_clear_gvariant (&ret_container);
+ ot_clear_gvariant (&files_variant);
+ ot_clear_gvariant (&dirs_variant);
return i;
}
@@ -1266,10 +1245,9 @@ _ostree_repo_file_tree_query_child (OstreeRepoFile *self,
g_clear_object (&ret_info);
if (matcher)
g_file_attribute_matcher_unref (matcher);
- if (tree_child_metadata)
- g_variant_unref (tree_child_metadata);
- g_variant_unref (files_variant);
- g_variant_unref (dirs_variant);
+ ot_clear_gvariant (&tree_child_metadata);
+ ot_clear_gvariant (&files_variant);
+ ot_clear_gvariant (&dirs_variant);
return ret;
}
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 6a5f035..545591d 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -360,8 +360,7 @@ ostree_repo_resolve_rev (OstreeRepo *self,
ret_rev = NULL;
ret = TRUE;
out:
- if (commit)
- g_variant_unref (commit);
+ ot_clear_gvariant (&commit);
g_free (tmp);
g_free (tmp2);
g_clear_object (&child);
@@ -629,8 +628,7 @@ write_gvariant_to_tmp (OstreeRepo *self,
close (fd);
if (checksum)
g_checksum_free (checksum);
- if (serialized != NULL)
- g_variant_unref (serialized);
+ ot_clear_gvariant (&serialized);
g_free (dest_name);
g_clear_object (&stream);
return ret;
@@ -694,8 +692,7 @@ ostree_repo_load_variant_checked (OstreeRepo *self,
*out_variant = ret_variant;
ret_variant = NULL;
out:
- if (ret_variant)
- g_variant_unref (ret_variant);
+ ot_clear_gvariant (&ret_variant);
return ret;
}
@@ -737,8 +734,7 @@ import_directory_meta (OstreeRepo *self,
g_clear_object (&f_info);
if (ret_checksum)
g_checksum_free (ret_checksum);
- if (dirmeta != NULL)
- g_variant_unref (dirmeta);
+ ot_clear_gvariant (&dirmeta);
return ret;
}
@@ -973,7 +969,7 @@ parsed_directory_data_free (ParsedDirectoryData *pdata)
return;
parsed_tree_data_free (pdata->tree_data);
g_free (pdata->metadata_sha256);
- g_variant_unref (pdata->meta_data);
+ ot_clear_gvariant (&pdata->meta_data);
g_free (pdata);
}
@@ -1100,8 +1096,7 @@ import_parsed_tree (OstreeRepo *self,
g_variant_builder_clear (&files_builder);
g_variant_builder_clear (&dirs_builder);
}
- if (serialized_tree)
- g_variant_unref (serialized_tree);
+ ot_clear_gvariant (&serialized_tree);
return ret;
}
@@ -1164,7 +1159,7 @@ add_one_directory_to_tree_and_import (OstreeRepo *self,
if (dir_value)
{
- g_variant_unref (dir_value->meta_data);
+ ot_clear_gvariant (&dir_value->meta_data);
dir_value->meta_data = dirmeta;
}
else
@@ -1398,8 +1393,7 @@ commit_parsed_tree (OstreeRepo *self,
out:
if (root_checksum)
g_checksum_free (root_checksum);
- if (commit)
- g_variant_unref (commit);
+ ot_clear_gvariant (&commit);
if (now)
g_date_time_unref (now);
return ret;
@@ -1429,8 +1423,7 @@ import_root (OstreeRepo *self,
*out_root = ret_root;
ret_root = NULL;
out:
- if (root_metadata)
- g_variant_unref (root_metadata);
+ ot_clear_gvariant (&root_metadata);
if (root_meta_checksum)
g_checksum_free (root_meta_checksum);
parsed_directory_data_free (ret_root);
@@ -1514,8 +1507,7 @@ ostree_repo_commit_from_filelist_fd (OstreeRepo *self,
if (ret_commit_checksum)
g_checksum_free (ret_commit_checksum);
g_free (current_head);
- if (root_metadata)
- g_variant_unref (root_metadata);
+ ot_clear_gvariant (&root_metadata);
if (root_meta_checksum)
g_checksum_free (root_meta_checksum);
g_clear_object (&datain);
@@ -1686,8 +1678,7 @@ ostree_repo_load_variant (OstreeRepo *self,
*out_variant = ret_variant;
ret_variant = NULL;
out:
- if (ret_variant)
- g_variant_unref (ret_variant);
+ ot_clear_gvariant (&ret_variant);
g_clear_object (&f);
return ret;
}
@@ -1736,8 +1727,7 @@ checkout_one_directory (OstreeRepo *self,
out:
g_clear_object (&dest_file);
g_free (dest_path);
- if (xattr_variant)
- g_variant_unref (xattr_variant);
+ ot_clear_gvariant (&xattr_variant);
return ret;
}
diff --git a/src/libotutil/ot-variant-utils.c b/src/libotutil/ot-variant-utils.c
index 026275b..5b8bbf2 100644
--- a/src/libotutil/ot-variant-utils.c
+++ b/src/libotutil/ot-variant-utils.c
@@ -117,8 +117,7 @@ ot_util_variant_map (GFile *src,
*out_variant = ret_variant;
ret_variant = NULL;
out:
- if (ret_variant)
- g_variant_unref (ret_variant);
+ ot_clear_gvariant (&ret_variant);
if (mfile)
g_mapped_file_unref (mfile);
return ret;
diff --git a/src/libotutil/ot-variant-utils.h b/src/libotutil/ot-variant-utils.h
index 57ce663..69f3111 100644
--- a/src/libotutil/ot-variant-utils.h
+++ b/src/libotutil/ot-variant-utils.h
@@ -27,6 +27,12 @@
G_BEGIN_DECLS
+#define ot_clear_gvariant(a_v) do { \
+ if (*a_v) \
+ g_variant_unref (*a_v); \
+ *a_v = NULL; \
+ } while (0);
+
GHashTable *ot_util_variant_asv_to_hash_table (GVariant *variant);
GVariant * ot_util_variant_take_ref (GVariant *variant);
diff --git a/src/ostree/ot-builtin-compose.c b/src/ostree/ot-builtin-compose.c
index f22662d..8e7f285 100644
--- a/src/ostree/ot-builtin-compose.c
+++ b/src/ostree/ot-builtin-compose.c
@@ -198,8 +198,7 @@ ostree_builtin_compose (int argc, char **argv, const char *repo_path, GError **e
g_variant_builder_clear (&commit_metadata_builder);
if (context)
g_option_context_free (context);
- if (commit_metadata)
- g_variant_unref (commit_metadata);
+ ot_clear_gvariant (&commit_metadata);
g_clear_object (&repo);
g_clear_object (&checkout);
g_clear_object (&destf);
diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c
index c9593bb..1cbd93e 100644
--- a/src/ostree/ot-builtin-fsck.c
+++ b/src/ostree/ot-builtin-fsck.c
@@ -103,10 +103,8 @@ checksum_packed_file (OtFsckData *data,
g_checksum_free (ret_checksum);
g_free (metadata_buf);
g_clear_object (&in);
- if (metadata)
- g_variant_unref (metadata);
- if (xattrs)
- g_variant_unref (xattrs);
+ ot_clear_gvariant (&metadata);
+ ot_clear_gvariant (&xattrs);
return ret;
}
diff --git a/src/ostree/ot-builtin-log.c b/src/ostree/ot-builtin-log.c
index fe3723e..41a1ae5 100644
--- a/src/ostree/ot-builtin-log.c
+++ b/src/ostree/ot-builtin-log.c
@@ -85,8 +85,7 @@ ostree_builtin_log (int argc, char **argv, const char *repo_path, GError **error
GVariant *commit_metadata = NULL;
char *formatted_metadata = NULL;
- if (commit)
- g_variant_unref (commit);
+ ot_clear_gvariant (&commit);
if (!ostree_repo_load_variant (repo, resolved_rev, &type, &commit, error))
goto out;
@@ -101,8 +100,7 @@ ostree_builtin_log (int argc, char **argv, const char *repo_path, GError **error
g_date_time_unref (time_obj);
time_obj = NULL;
- formatted_metadata = g_variant_print (commit_metadata, TRUE);
- g_variant_unref (commit_metadata);
+ ot_clear_gvariant (&commit_metadata);
formatted = g_strdup_printf ("commit %s\nSubject: %s\nDate: %s\nMetadata: %s\n\n",
resolved_rev, subject, formatted_date, formatted_metadata);
g_free (formatted_metadata);
@@ -147,8 +145,7 @@ ostree_builtin_log (int argc, char **argv, const char *repo_path, GError **error
g_free (resolved_rev);
if (context)
g_option_context_free (context);
- if (commit)
- g_variant_unref (commit);
+ ot_clear_gvariant (&commit);
g_clear_object (&repo);
return ret;
}
diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c
index 10c987b..012c094 100644
--- a/src/ostree/ot-builtin-pull.c
+++ b/src/ostree/ot-builtin-pull.c
@@ -220,12 +220,9 @@ store_tree_recurse (OstreeRepo *repo,
ret = TRUE;
out:
- if (tree)
- g_variant_unref (tree);
- if (files_variant)
- g_variant_unref (files_variant);
- if (dirs_variant)
- g_variant_unref (dirs_variant);
+ ot_clear_gvariant (&tree);
+ ot_clear_gvariant (&files_variant);
+ ot_clear_gvariant (&dirs_variant);
return ret;
}
@@ -274,8 +271,7 @@ store_commit_recurse (OstreeRepo *repo,
ret = TRUE;
out:
- if (commit)
- g_variant_unref (commit);
+ ot_clear_gvariant (&commit);
return ret;
}
diff --git a/src/ostree/ot-builtin-rev-parse.c b/src/ostree/ot-builtin-rev-parse.c
index 6868c10..02dc0d7 100644
--- a/src/ostree/ot-builtin-rev-parse.c
+++ b/src/ostree/ot-builtin-rev-parse.c
@@ -70,8 +70,7 @@ ostree_builtin_rev_parse (int argc, char **argv, const char *repo_path, GError *
if (context)
g_option_context_free (context);
g_clear_object (&repo);
- if (variant)
- g_variant_unref (variant);
+ ot_clear_gvariant (&variant);
g_free (formatted_variant);
return ret;
}
diff --git a/src/ostree/ot-builtin-show.c b/src/ostree/ot-builtin-show.c
index ae6bd81..c524c7a 100644
--- a/src/ostree/ot-builtin-show.c
+++ b/src/ostree/ot-builtin-show.c
@@ -56,8 +56,7 @@ print_variant (GVariant *variant)
g_print ("%s\n", formatted_variant);
g_free (formatted_variant);
- if (byteswapped)
- g_variant_unref (byteswapped);
+ ot_clear_gvariant (&byteswapped);
}
static gboolean
@@ -78,8 +77,7 @@ do_print_variant_generic (const GVariantType *type,
ret = TRUE;
out:
- if (variant)
- g_variant_unref (variant);
+ ot_clear_gvariant (&variant);
g_clear_object (&f);
return ret;
}
@@ -101,8 +99,7 @@ show_repo_meta (OstreeRepo *repo,
ret = TRUE;
out:
- if (variant)
- g_variant_unref (variant);
+ ot_clear_gvariant (&variant);
return ret;
}
@@ -127,8 +124,7 @@ do_print_packfile (OstreeRepo *repo,
out:
g_clear_object (&file);
g_clear_object (&content);
- if (variant)
- g_variant_unref (variant);
+ ot_clear_gvariant (&variant);
return ret;
}
@@ -171,12 +167,10 @@ do_print_compose (OstreeRepo *repo,
ret = TRUE;
out:
- if (variant)
- g_variant_unref (variant);
+ ot_clear_gvariant (&variant);
if (viter)
g_variant_iter_free (viter);
- if (metadata)
- g_variant_unref (metadata);
+ ot_clear_gvariant (&metadata);
if (metadata_hash)
g_hash_table_destroy (metadata_hash);
return ret;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]