[ostree] core: New ot_transfer_out_value() macro
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: New ot_transfer_out_value() macro
- Date: Fri, 2 Dec 2011 23:18:17 +0000 (UTC)
commit 0003e101f61d2ff7283ee980ccae1cd98acb07d8
Author: Colin Walters <walters verbum org>
Date: Fri Dec 2 18:17:06 2011 -0500
core: New ot_transfer_out_value() macro
This makes out values considerably less typing.
src/libostree/ostree-core.c | 77 +++++++++-------------------------
src/libostree/ostree-repo-file.c | 9 +---
src/libostree/ostree-repo.c | 87 ++++++++++---------------------------
src/libotutil/ot-gio-utils.c | 6 +--
src/libotutil/ot-unix-utils.c | 5 +-
src/libotutil/ot-variant-utils.c | 3 +-
src/libotutil/otutil.h | 8 ++++
7 files changed, 59 insertions(+), 136 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 1daf291..881ef04 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -204,8 +204,7 @@ checksum_directory (GFile *f,
g_variant_get_size (packed));
ret = TRUE;
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
ot_clear_checksum (&ret_checksum);
ot_clear_gvariant (&dirmeta);
@@ -302,13 +301,14 @@ checksum_nondirectory (GFile *f,
g_checksum_update (content_and_meta_sha256, (guint8*)g_variant_get_data (xattrs), g_variant_get_size (xattrs));
}
- *out_checksum = content_and_meta_sha256;
+ ot_transfer_out_value(out_checksum, content_and_meta_sha256);
ret = TRUE;
out:
g_clear_object (&input);
g_free (basename);
ot_clear_gvariant (&xattrs);
ot_clear_checksum (&content_sha256);
+ ot_clear_checksum (&content_and_meta_sha256);
return ret;
}
@@ -344,10 +344,10 @@ ostree_checksum_file (GFile *f,
}
ret = TRUE;
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
g_clear_object (&file_info);
+ ot_clear_checksum(&ret_checksum);
return ret;
}
@@ -507,11 +507,12 @@ ostree_parse_metadata_file (GFile *file,
ot_gfile_get_path_cached (file), ret_type);
goto out;
}
+ ot_util_variant_take_ref (ret_variant);
ret = TRUE;
- *out_type = ret_type;
- *out_variant = ot_util_variant_take_ref (ret_variant);
- ret_variant = NULL;
+ if (out_type)
+ *out_type = ret_type;
+ ot_transfer_out_value(out_variant, ret_variant);
out:
ot_clear_gvariant (&ret_variant);
ot_clear_gvariant (&container);
@@ -667,11 +668,7 @@ ostree_pack_file_for_input (GOutputStream *output,
}
ret = TRUE;
- if (out_checksum)
- {
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
- }
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
if (pack_builder_initialized)
g_variant_builder_clear (&pack_builder);
@@ -745,11 +742,7 @@ unpack_meta (GFile *file,
goto out;
ret = TRUE;
- if (out_checksum)
- {
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
- }
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
ot_clear_checksum (&ret_checksum);
g_clear_object (&in);
@@ -876,21 +869,9 @@ ostree_parse_packed_file (GFile *file,
}
ret = TRUE;
- if (out_file_info)
- {
- *out_file_info = ret_file_info;
- ret_file_info = NULL;
- }
- if (out_xattrs)
- {
- *out_xattrs = ret_xattrs;
- ret_xattrs = NULL;
- }
- if (out_content)
- {
- *out_content = (GInputStream*)in;
- in = NULL;
- }
+ ot_transfer_out_value(out_file_info, ret_file_info);
+ ot_transfer_out_value(out_xattrs, ret_xattrs);
+ ot_transfer_out_value(out_content, in);
out:
g_clear_object (&ret_file_info);
ot_clear_gvariant (&ret_xattrs);
@@ -1028,11 +1009,7 @@ ostree_create_file_from_input (GFile *dest_file,
}
ret = TRUE;
- if (out_checksum)
- {
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
- }
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
if (!ret)
(void) unlink (dest_path);
@@ -1146,16 +1123,8 @@ ostree_create_temp_file_from_input (GFile *dir,
}
ret = TRUE;
- if (out_checksum)
- {
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
- }
- if (out_file)
- {
- *out_file = possible_file;
- possible_file = NULL;
- }
+ ot_transfer_out_value(out_checksum, ret_checksum);
+ ot_transfer_out_value(out_file, possible_file);
out:
if (rand)
g_rand_free (rand);
@@ -1190,10 +1159,8 @@ ostree_create_temp_regular_file (GFile *dir,
goto out;
ret = TRUE;
- *out_file = ret_file;
- ret_file = NULL;
- *out_stream = ret_stream;
- ret_stream = NULL;
+ ot_transfer_out_value(out_file, ret_file);
+ ot_transfer_out_value(out_stream, ret_stream);
out:
g_clear_object (&ret_file);
g_clear_object (&ret_stream);
@@ -1224,11 +1191,7 @@ unpack_file (GFile *file,
goto out;
ret = TRUE;
- if (out_checksum)
- {
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
- }
+ ot_transfer_out_value (out_checksum, ret_checksum);
out:
g_clear_object (&finfo);
ot_clear_gvariant (&xattrs);
diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c
index 97996ac..927e6ad 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -327,8 +327,7 @@ _ostree_repo_file_get_xattrs (OstreeRepoFile *self,
}
ret = TRUE;
- *out_xattrs = ret_xattrs;
- ret_xattrs = NULL;
+ ot_transfer_out_value(out_xattrs, ret_xattrs);
out:
ot_clear_gvariant (&ret_xattrs);
g_clear_object (&local_file);
@@ -740,8 +739,7 @@ query_child_info_dir (OstreeRepo *repo,
}
ret = TRUE;
- *out_info = ret_info;
- ret_info = NULL;
+ ot_transfer_out_value(out_info, ret_info);
out:
g_clear_object (&ret_info);
ot_clear_gvariant (&metadata);
@@ -1089,8 +1087,7 @@ _ostree_repo_file_tree_query_child (OstreeRepoFile *self,
}
ret = TRUE;
- *out_info = ret_info;
- ret_info = NULL;
+ ot_transfer_out_value(out_info, ret_info);
out:
g_clear_object (&ret_info);
g_clear_object (&local_child);
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 0e01469..3d3cfbe 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -239,8 +239,7 @@ parse_rev_file (OstreeRepo *self,
goto out;
}
- *sha256 = rev;
- rev = NULL;
+ ot_transfer_out_value(sha256, rev);
ret = TRUE;
out:
g_free (rev);
@@ -356,8 +355,7 @@ ostree_repo_resolve_rev (OstreeRepo *self,
}
}
- *sha256 = ret_rev;
- ret_rev = NULL;
+ ot_transfer_out_value(sha256, ret_rev);
ret = TRUE;
out:
ot_clear_gvariant (&commit);
@@ -608,16 +606,8 @@ stage_and_checksum (OstreeRepo *self,
g_clear_object (&tmp_f);
ret = TRUE;
- if (out_tmpname)
- {
- *out_tmpname = ret_tmpname;
- ret_tmpname = NULL;
- }
- if (out_checksum)
- {
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
- }
+ ot_transfer_out_value(out_tmpname, ret_tmpname);
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
if (tmp_f)
(void) unlink (ot_gfile_get_path_cached (tmp_f));
@@ -652,16 +642,8 @@ write_gvariant_to_tmp (OstreeRepo *self,
goto out;
ret = TRUE;
- if (out_tmpname)
- {
- *out_tmpname = ret_tmpname;
- ret_tmpname = NULL;
- }
- if (out_checksum)
- {
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
- }
+ ot_transfer_out_value(out_tmpname, ret_tmpname);
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
g_clear_object (&ret_tmpname);
ot_clear_checksum (&ret_checksum);
@@ -691,8 +673,7 @@ import_gvariant_object (OstreeRepo *self,
goto out;
ret = TRUE;
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
(void) unlink (ot_gfile_get_path_cached (tmp_path));
g_clear_object (&tmp_path);
@@ -723,8 +704,7 @@ ostree_repo_load_variant_checked (OstreeRepo *self,
}
ret = TRUE;
- *out_variant = ret_variant;
- ret_variant = NULL;
+ ot_transfer_out_value(out_variant, ret_variant);
out:
ot_clear_gvariant (&ret_variant);
return ret;
@@ -749,11 +729,7 @@ import_directory_meta (OstreeRepo *self,
goto out;
ret = TRUE;
- if (out_checksum)
- {
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
- }
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
ot_clear_checksum (&ret_checksum);
ot_clear_gvariant (&dirmeta);
@@ -797,8 +773,7 @@ prepare_dir_for_checksum_get_object_path (OstreeRepo *self,
goto out;
ret = TRUE;
- *out_file = ret_file;
- ret_file = NULL;
+ ot_transfer_out_value(out_file, ret_file);
out:
g_clear_object (&checksum_dir);
g_clear_object (&ret_file);
@@ -996,8 +971,7 @@ ostree_repo_store_file (OstreeRepo *self,
}
ret = TRUE;
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
if (temp_file)
(void) unlink (ot_gfile_get_path_cached (temp_file));
@@ -1129,11 +1103,7 @@ import_commit (OstreeRepo *self,
goto out;
ret = TRUE;
- if (out_commit)
- {
- *out_commit = ret_commit;
- ret_commit = NULL;
- }
+ ot_transfer_out_value(out_commit, ret_commit);
out:
ot_clear_checksum (&ret_commit);
ot_clear_gvariant (&commit);
@@ -1304,10 +1274,8 @@ import_directory_recurse (OstreeRepo *self,
cancellable, error))
goto out;
- *out_metadata_checksum = ret_metadata_checksum;
- ret_metadata_checksum = NULL;
- *out_contents_checksum = ret_contents_checksum;
- ret_contents_checksum = NULL;
+ ot_transfer_out_value(out_metadata_checksum, ret_metadata_checksum);
+ ot_transfer_out_value(out_contents_checksum, ret_contents_checksum);
ret = TRUE;
out:
g_clear_object (&dir_enum);
@@ -1371,8 +1339,7 @@ ostree_repo_commit (OstreeRepo *self,
goto out;
ret = TRUE;
- *out_commit = ret_commit_checksum;
- ret_commit_checksum = NULL;
+ ot_transfer_out_value(out_commit, ret_commit_checksum);
out:
ot_clear_checksum (&ret_commit_checksum);
g_free (current_head);
@@ -1538,9 +1505,9 @@ ostree_repo_load_variant (OstreeRepo *self,
goto out;
ret = TRUE;
- *out_type = ret_type;
- *out_variant = ret_variant;
- ret_variant = NULL;
+ if (out_type)
+ *out_type = ret_type;
+ ot_transfer_out_value(out_variant, ret_variant);
out:
ot_clear_gvariant (&ret_variant);
g_clear_object (&f);
@@ -1749,8 +1716,7 @@ get_file_checksum (GFile *f,
}
ret = TRUE;
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
ot_clear_checksum (&tmp_checksum);
return ret;
@@ -1824,8 +1790,7 @@ diff_files (GFile *a,
}
ret = TRUE;
- *out_item = ret_item;
- ret_item = NULL;
+ ot_transfer_out_value(out_item, ret_item);
out:
if (ret_item)
ostree_repo_diff_item_unref (ret_item);
@@ -2059,8 +2024,7 @@ ostree_repo_read_commit (OstreeRepo *self,
goto out;
ret = TRUE;
- *out_root = ret_root;
- ret_root = NULL;
+ ot_transfer_out_value(out_root, ret_root);
out:
g_free (resolved_rev);
g_clear_object (&ret_root);
@@ -2090,12 +2054,9 @@ ostree_repo_diff (OstreeRepo *self,
goto out;
ret = TRUE;
- *out_modified = ret_modified;
- ret_modified = NULL;
- *out_removed = ret_removed;
- ret_removed = NULL;
- *out_added = ret_added;
- ret_added = NULL;
+ ot_transfer_out_value(out_modified, ret_modified);
+ ot_transfer_out_value(out_removed, ret_removed);
+ ot_transfer_out_value(out_added, ret_added);
out:
if (ret_modified)
g_ptr_array_free (ret_modified, TRUE);
diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c
index cff9944..1700fcd 100644
--- a/src/libotutil/ot-gio-utils.c
+++ b/src/libotutil/ot-gio-utils.c
@@ -186,11 +186,7 @@ ot_gio_splice_and_checksum (GOutputStream *out,
}
ret = TRUE;
- if (out_checksum)
- {
- *out_checksum = ret_checksum;
- ret_checksum = NULL;
- }
+ ot_transfer_out_value(out_checksum, ret_checksum);
out:
ot_clear_checksum (&ret_checksum);
return ret;
diff --git a/src/libotutil/ot-unix-utils.c b/src/libotutil/ot-unix-utils.c
index 7b709ff..444f620 100644
--- a/src/libotutil/ot-unix-utils.c
+++ b/src/libotutil/ot-unix-utils.c
@@ -22,7 +22,7 @@
#include "config.h"
-#include "ot-unix-utils.h"
+#include "otutil.h"
#include <gio/gio.h>
#include <gio/gunixoutputstream.h>
@@ -67,8 +67,7 @@ ot_util_spawn_pager (GOutputStream **out_stream,
ret_stream = (GOutputStream*)g_unix_output_stream_new (stdin_fd, TRUE);
}
- *out_stream = ret_stream;
- ret_stream = NULL;
+ ot_transfer_out_value(out_stream, ret_stream);
ret = TRUE;
out:
g_clear_object (&ret_stream);
diff --git a/src/libotutil/ot-variant-utils.c b/src/libotutil/ot-variant-utils.c
index 5b8bbf2..cd9ba36 100644
--- a/src/libotutil/ot-variant-utils.c
+++ b/src/libotutil/ot-variant-utils.c
@@ -114,8 +114,7 @@ ot_util_variant_map (GFile *src,
g_variant_ref_sink (ret_variant);
ret = TRUE;
- *out_variant = ret_variant;
- ret_variant = NULL;
+ ot_transfer_out_value(out_variant, ret_variant);
out:
ot_clear_gvariant (&ret_variant);
if (mfile)
diff --git a/src/libotutil/otutil.h b/src/libotutil/otutil.h
index a48408f..6e31f0e 100644
--- a/src/libotutil/otutil.h
+++ b/src/libotutil/otutil.h
@@ -32,6 +32,14 @@
} \
} G_STMT_END;
+#define ot_transfer_out_value(outp, srcp) G_STMT_START { \
+ if (outp) \
+ { \
+ *outp = srcp; \
+ srcp = NULL; \
+ } \
+ } G_STMT_END;
+
#include <ot-gio-utils.h>
#include <ot-glib-compat.h>
#include <ot-opt-utils.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]