From 29dbeee72fd807c937b9b209ca07f1fe26eef9e4 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 19 Dec 2020 15:29:13 +0000 Subject: [PATCH] More C++ porting, round 6 Port rojig-build and rpm-util to C++. Prep for using https://cxx.rs/ --- Makefile-libpriv.am | 4 +- Makefile-rpm-ostree.am | 2 +- ... => rpmostree-ex-builtin-commit2rojig.cxx} | 0 ...ojig-build.c => rpmostree-rojig-build.cxx} | 78 ++++++------ ...tree-rpm-util.c => rpmostree-rpm-util.cxx} | 111 +++++++++--------- 5 files changed, 95 insertions(+), 100 deletions(-) rename src/app/{rpmostree-ex-builtin-commit2rojig.c => rpmostree-ex-builtin-commit2rojig.cxx} (100%) rename src/libpriv/{rpmostree-rojig-build.c => rpmostree-rojig-build.cxx} (94%) rename src/libpriv/{rpmostree-rpm-util.c => rpmostree-rpm-util.cxx} (92%) diff --git a/Makefile-libpriv.am b/Makefile-libpriv.am index 774b85c6..40afcf1d 100644 --- a/Makefile-libpriv.am +++ b/Makefile-libpriv.am @@ -40,7 +40,7 @@ librpmostreepriv_sources = \ src/libpriv/rpmostree-scripts.h \ src/libpriv/rpmostree-refsack.h \ src/libpriv/rpmostree-refsack.cxx \ - src/libpriv/rpmostree-rpm-util.c \ + src/libpriv/rpmostree-rpm-util.cxx \ src/libpriv/rpmostree-rpm-util.h \ src/libpriv/rpmostree-importer.c \ src/libpriv/rpmostree-importer.h \ @@ -60,7 +60,7 @@ librpmostreepriv_sources = \ if BUILDOPT_ROJIG librpmostreepriv_sources += \ - src/libpriv/rpmostree-rojig-build.c \ + src/libpriv/rpmostree-rojig-build.cxx \ src/libpriv/rpmostree-rojig-build.h \ src/libpriv/rpmostree-rojig-assembler.c \ src/libpriv/rpmostree-rojig-assembler.h \ diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am index cfbcf58d..25c324c3 100644 --- a/Makefile-rpm-ostree.am +++ b/Makefile-rpm-ostree.am @@ -66,7 +66,7 @@ rpm_ostree_SOURCES = src/app/main.cxx \ if BUILDOPT_ROJIG rpm_ostree_SOURCES += \ - src/app/rpmostree-ex-builtin-commit2rojig.c \ + src/app/rpmostree-ex-builtin-commit2rojig.cxx \ src/app/rpmostree-ex-builtin-rojig2commit.c \ src/app/rpmostree-compose-builtin-rojig.c \ $(NULL) diff --git a/src/app/rpmostree-ex-builtin-commit2rojig.c b/src/app/rpmostree-ex-builtin-commit2rojig.cxx similarity index 100% rename from src/app/rpmostree-ex-builtin-commit2rojig.c rename to src/app/rpmostree-ex-builtin-commit2rojig.cxx diff --git a/src/libpriv/rpmostree-rojig-build.c b/src/libpriv/rpmostree-rojig-build.cxx similarity index 94% rename from src/libpriv/rpmostree-rojig-build.c rename to src/libpriv/rpmostree-rojig-build.cxx index a3346417..9d494b58 100644 --- a/src/libpriv/rpmostree-rojig-build.c +++ b/src/libpriv/rpmostree-rojig-build.cxx @@ -87,7 +87,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(RpmOstreeCommit2RojigContext, rpm_ostree_commit2ro static void add_objid (GHashTable *object_to_objid, const char *checksum, const char *objid) { - GHashTable *objids = g_hash_table_lookup (object_to_objid, checksum); + auto objids = static_cast(g_hash_table_lookup (object_to_objid, checksum)); if (!objids) { objids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); @@ -176,7 +176,7 @@ build_objid_map_for_tree (RpmOstreeCommit2RojigContext *self, } else { - const char *existing_path = g_hash_table_lookup (build->seen_objid_to_path, bn); + auto existing_path = static_cast(g_hash_table_lookup (build->seen_objid_to_path, bn)); if (!existing_path) { g_hash_table_insert (build->seen_objid_to_path, g_strdup (bn), g_strdup (path)); @@ -185,7 +185,7 @@ build_objid_map_for_tree (RpmOstreeCommit2RojigContext *self, } else { - const char *previous_obj = g_hash_table_lookup (build->seen_path_to_object, existing_path); + auto previous_obj = static_cast(g_hash_table_lookup (build->seen_path_to_object, existing_path)); g_assert (previous_obj); /* Replace the previous basename with a full path */ add_objid (object_to_objid, previous_obj, existing_path); @@ -252,7 +252,7 @@ contentonly_hash_for_object (OstreeRepo *repo, if (size > 0) { gsize bufsize = MIN (size, 128 * 1024); - g_autofree char *buf = g_malloc (bufsize); + g_autofree char *buf = (char*)g_malloc (bufsize); gsize bytes_read; do { @@ -312,7 +312,7 @@ write_one_new_object (OstreeRepo *repo, return FALSE; g_autoptr(GOutputStream) ostream = g_unix_output_stream_new (tmpf.fd, FALSE); - if (g_output_stream_splice (ostream, istream, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, + if (g_output_stream_splice (ostream, istream, (GOutputStreamSpliceFlags)(G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET), cancellable, error) < 0) return FALSE; if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_NOREPLACE, tmp_dfd, @@ -343,7 +343,7 @@ write_content_identical_set (OstreeRepo *repo, g_autoptr(GVariantBuilder) builder = g_variant_builder_new (RPMOSTREE_ROJIG_NEW_CONTENTIDENT_VARIANT_FORMAT); for (guint i = 0; i < identicals->len; i++) { - const char *checksum = identicals->pdata[i]; + auto checksum = static_cast(identicals->pdata[i]); g_autoptr(GFileInfo) finfo = NULL; g_autoptr(GVariant) xattrs = NULL; if (!ostree_repo_load_file (repo, checksum, NULL, &finfo, &xattrs, @@ -359,14 +359,14 @@ write_content_identical_set (OstreeRepo *repo, g_autoptr(GVariant) meta = g_variant_ref_sink (g_variant_builder_end (builder)); g_autofree char *meta_path = g_strconcat (subdir, "/01meta", NULL); if (!glnx_file_replace_contents_at (tmp_dfd, meta_path, - g_variant_get_data (meta), + (const guint8*)g_variant_get_data (meta), g_variant_get_size (meta), GLNX_FILE_REPLACE_NODATASYNC, cancellable, error)) return FALSE; /* Write the content */ - const char *checksum = identicals->pdata[0]; + auto checksum = static_cast(identicals->pdata[0]); g_autoptr(GInputStream) istream = NULL; if (!ostree_repo_load_file (repo, checksum, &istream, NULL, NULL, cancellable, error)) @@ -377,7 +377,7 @@ write_content_identical_set (OstreeRepo *repo, &tmpf, error)) return FALSE; g_autoptr(GOutputStream) ostream = g_unix_output_stream_new (tmpf.fd, FALSE); - if (g_output_stream_splice (ostream, istream, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, + if (g_output_stream_splice (ostream, istream, (GOutputStreamSpliceFlags)(G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET), cancellable, error) < 0) return FALSE; if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_NOREPLACE, tmp_dfd, @@ -418,7 +418,7 @@ xattr_chunk_hash (const void *vp) g_variant_get_child (v, i, "(^&ay@ay)", &name, &value); - value_data = g_variant_get_fixed_array (value, &value_len, 1); + value_data = (const guint8*)g_variant_get_fixed_array (value, &value_len, 1); h += g_str_hash (name); h += bufhash (value_data, value_len); @@ -540,10 +540,10 @@ build_objid_map_for_package (RpmOstreeCommit2RojigContext *self, /* Add object → pkgobjid to the global map */ g_hash_table_iter_steal (&it); PkgObjid *pkgobjid = g_new (PkgObjid, 1); - pkgobjid->pkg = g_object_ref (pkg); - pkgobjid->objids = g_steal_pointer (&objid_set); + pkgobjid->pkg = (DnfPackage*)g_object_ref (pkg); + pkgobjid->objids = util::move_nullify (objid_set); - g_hash_table_insert (self->content_object_to_pkg_objid, g_steal_pointer (&checksum), pkgobjid); + g_hash_table_insert (self->content_object_to_pkg_objid, util::move_nullify (checksum), pkgobjid); } } @@ -573,7 +573,7 @@ generate_spec (RpmOstreeCommit2RojigContext *self, /* Look for the magic comment */ const char *meta = strstr (spec_contents, "\n" RPMOSTREE_ROJIG_SPEC_META_MAGIC); if (!meta) - return glnx_null_throw (error, "Missing magic '%s' in %s", RPMOSTREE_ROJIG_SPEC_META_MAGIC, spec_path); + return (char*)glnx_null_throw (error, "Missing magic '%s' in %s", RPMOSTREE_ROJIG_SPEC_META_MAGIC, spec_path); /* Generate a replacement in memory */ g_autoptr(GString) replacement = g_string_new (""); @@ -596,7 +596,7 @@ generate_spec (RpmOstreeCommit2RojigContext *self, */ for (guint i = 0; i < rojig_packages->len; i++) { - DnfPackage *pkg = rojig_packages->pdata[i]; + auto pkg = static_cast(rojig_packages->pdata[i]); if (g_str_equal (dnf_package_get_arch (pkg), "noarch")) { g_string_append_printf (replacement, "Requires: %s = %s\n", @@ -616,17 +616,17 @@ generate_spec (RpmOstreeCommit2RojigContext *self, g_autofree char *tmppath = g_strdup ("/tmp/rpmostree-rojig-spec.XXXXXX"); glnx_autofd int fd = g_mkstemp_full (tmppath, O_WRONLY | O_CLOEXEC, 0644); if (glnx_loop_write (fd, replacement->str, replacement->len) < 0) - return glnx_null_throw_errno_prefix (error, "write"); + return (char*)glnx_null_throw_errno_prefix (error, "write"); - return g_steal_pointer (&tmppath); + return util::move_nullify (tmppath); } static int compare_pkgs (gconstpointer ap, gconstpointer bp) { - DnfPackage **a = (gpointer)ap; - DnfPackage **b = (gpointer)bp; + auto a = (DnfPackage**)(gpointer)ap; + auto b = (DnfPackage**)(gpointer)bp; return dnf_package_cmp (*a, *b); } @@ -667,7 +667,7 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, return FALSE; g_autofree char *commit_path = g_strconcat (commit_dir, "/", commit+2, NULL); if (!glnx_file_replace_contents_at (oirpm_tmpd.fd, commit_path, - g_variant_get_data (commit_obj), + (const guint8*)g_variant_get_data (commit_obj), g_variant_get_size (commit_obj), GLNX_FILE_REPLACE_NODATASYNC, cancellable, error)) @@ -679,7 +679,7 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, g_autofree char *commit_metapath = g_strconcat (RPMOSTREE_ROJIG_COMMIT_DIR, "/meta", NULL); if (commit_detached_meta) { - buf = g_variant_get_data (commit_detached_meta); + buf = (const guint8*)g_variant_get_data (commit_detached_meta); buflen = g_variant_get_size (commit_detached_meta); } if (!glnx_file_replace_contents_at (oirpm_tmpd.fd, commit_metapath, @@ -736,7 +736,7 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, g_assert_cmpint (identicals->len, >=, 1); if (identicals->len == 1) { - const char *checksum = identicals->pdata[0]; + auto checksum = static_cast(identicals->pdata[0]); if (!write_one_new_object (self->repo, oirpm_tmpd.fd, OSTREE_OBJECT_TYPE_FILE, checksum, cancellable, error)) @@ -758,7 +758,7 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, g_assert_cmpint (identicals->len, >=, 1); if (identicals->len == 1) { - const char *checksum = identicals->pdata[0]; + auto checksum = static_cast(identicals->pdata[0]); if (!write_one_new_object (self->repo, oirpm_tmpd.fd, OSTREE_OBJECT_TYPE_FILE, checksum, cancellable, error)) @@ -796,7 +796,7 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, /* Is this content object associated with a package? If not, it was * already processed. */ - PkgObjid *pkgobjid = g_hash_table_lookup (self->content_object_to_pkg_objid, checksum); + auto pkgobjid = (PkgObjid *)g_hash_table_lookup (self->content_object_to_pkg_objid, checksum); if (!pkgobjid) { g_hash_table_iter_remove (&it); @@ -821,7 +821,7 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, if (!g_hash_table_lookup_extended (xattr_table_hash, xattrs, NULL, &xattr_idx_p)) { g_variant_builder_add (xattr_table_builder, "@a(ayay)", xattrs); - g_hash_table_insert (xattr_table_hash, g_steal_pointer (&xattrs), + g_hash_table_insert (xattr_table_hash, util::move_nullify (xattrs), GUINT_TO_POINTER (global_xattr_idx)); this_xattr_idx = global_xattr_idx; /* Increment this for the next loop */ @@ -833,8 +833,8 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, } /* Add this to our map of pkg → [objidxattrs] */ - DnfPackage *pkg = pkgobjid->pkg; - GPtrArray *pkg_objidxattrs = g_hash_table_lookup (pkg_to_objidxattrs, pkg); + auto pkg = (DnfPackage *)pkgobjid->pkg; + auto pkg_objidxattrs = (GPtrArray *)g_hash_table_lookup (pkg_to_objidxattrs, pkg); if (!pkg_objidxattrs) { pkg_objidxattrs = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); @@ -859,8 +859,8 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, */ for (guint i = 0; i < pkglist->len; i++) { - DnfPackage *pkg = pkglist->pdata[i]; - GPtrArray *pkg_objidxattrs = g_hash_table_lookup (pkg_to_objidxattrs, pkg); + auto pkg = (DnfPackage *)pkglist->pdata[i]; + auto pkg_objidxattrs = (GPtrArray *)g_hash_table_lookup (pkg_to_objidxattrs, pkg); if (!pkg_objidxattrs) { pkg_objidxattrs = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); @@ -875,7 +875,7 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, return FALSE; { g_autoptr(GVariant) xattr_table = g_variant_ref_sink (g_variant_builder_end (xattr_table_builder)); if (!glnx_file_replace_contents_at (oirpm_tmpd.fd, RPMOSTREE_ROJIG_XATTRS_TABLE, - g_variant_get_data (xattr_table), + (const guint8*)g_variant_get_data (xattr_table), g_variant_get_size (xattr_table), GLNX_FILE_REPLACE_NODATASYNC, cancellable, error)) @@ -921,7 +921,7 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, for (guint i = 0; i < objidxattrs->len; i++) { - GVariant *objidxattr = objidxattrs->pdata[i]; + auto objidxattr = static_cast(objidxattrs->pdata[i]); g_variant_builder_add (objid_xattr_builder, "@(su)", objidxattr); } g_variant_builder_close (objid_xattr_builder); @@ -929,8 +929,8 @@ write_commit2rojig (RpmOstreeCommit2RojigContext *self, g_autofree char *path = g_strconcat (RPMOSTREE_ROJIG_XATTRS_PKG_DIR, "/", nevra, NULL); /* The "unused set" will have empty maps for xattrs */ - const guint8 *buf = g_variant_get_data (objid_xattrs_final) ?: ""; - if (!glnx_file_replace_contents_at (oirpm_tmpd.fd, path, buf, + auto buf = (const guint8 *)g_variant_get_data (objid_xattrs_final) ?: (const guint8*)""; + if (!glnx_file_replace_contents_at (oirpm_tmpd.fd, path, static_cast(buf), g_variant_get_size (objid_xattrs_final), GLNX_FILE_REPLACE_NODATASYNC, cancellable, error)) @@ -1081,7 +1081,7 @@ impl_commit2rojig (RpmOstreeCommit2RojigContext *self, for (guint i = 0; i < pkglist->len; i++) { - DnfPackage *pkg = pkglist->pdata[i]; + auto pkg = (DnfPackage *)pkglist->pdata[i]; if (!build_objid_map_for_package (self, pkg, cancellable, error)) return FALSE; } @@ -1110,7 +1110,7 @@ impl_commit2rojig (RpmOstreeCommit2RojigContext *self, return FALSE; const gboolean is_big = objsize >= BIG_OBJ_SIZE; - PkgObjid *pkgobjid = g_hash_table_lookup (self->content_object_to_pkg_objid, checksum); + auto pkgobjid = (PkgObjid *)g_hash_table_lookup (self->content_object_to_pkg_objid, checksum); if (!pkgobjid) g_hash_table_add (is_big ? new_reachable_big : new_reachable_small, g_strdup (checksum)); else @@ -1133,7 +1133,7 @@ impl_commit2rojig (RpmOstreeCommit2RojigContext *self, g_print ("Packages without content:\n"); for (guint i = 0; i < pkglist->len; i++) { - DnfPackage *pkg = pkglist->pdata[i]; + auto pkg = (DnfPackage *)pkglist->pdata[i]; if (!g_hash_table_contains (pkgs_with_content, pkg)) { g_autofree char *tmpfiles_d_path = g_strconcat ("usr/lib/tmpfiles.d/pkg-", @@ -1213,7 +1213,7 @@ impl_commit2rojig (RpmOstreeCommit2RojigContext *self, #endif /* OK, see if it duplicates another *new* object */ - GPtrArray *identicals = g_hash_table_lookup (new_big_content_identical, obj_contenthash); + auto identicals = (GPtrArray *)g_hash_table_lookup (new_big_content_identical, obj_contenthash); if (!identicals) { identicals = g_ptr_array_new_with_free_func (g_free); @@ -1258,8 +1258,8 @@ rpmostree_commit2rojig (OstreeRepo *repo, { g_autoptr(RpmOstreeCommit2RojigContext) self = g_new0 (RpmOstreeCommit2RojigContext, 1); - self->repo = g_object_ref (repo); - self->pkgcache_repo = g_object_ref (pkgcache_repo); + self->repo = (OstreeRepo*)g_object_ref (repo); + self->pkgcache_repo = (OstreeRepo*)g_object_ref (pkgcache_repo); self->commit_content_objects = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); self->content_object_to_pkg_objid = g_hash_table_new_full (g_str_hash, g_str_equal, diff --git a/src/libpriv/rpmostree-rpm-util.c b/src/libpriv/rpmostree-rpm-util.cxx similarity index 92% rename from src/libpriv/rpmostree-rpm-util.c rename to src/libpriv/rpmostree-rpm-util.cxx index 0669a0c8..a37d86e0 100644 --- a/src/libpriv/rpmostree-rpm-util.c +++ b/src/libpriv/rpmostree-rpm-util.cxx @@ -141,30 +141,30 @@ rpmostree_header_custom_nevra_strdup (Header h, RpmOstreePkgNevraFlags flags) static char * pkg_nevra_strdup (Header h1) { - return rpmostree_header_custom_nevra_strdup (h1, PKG_NEVRA_FLAGS_NAME | + return rpmostree_header_custom_nevra_strdup (h1, (RpmOstreePkgNevraFlags)(PKG_NEVRA_FLAGS_NAME | PKG_NEVRA_FLAGS_EVR | - PKG_NEVRA_FLAGS_ARCH); + PKG_NEVRA_FLAGS_ARCH)); } static char * pkg_na_strdup (Header h1) { - return rpmostree_header_custom_nevra_strdup (h1, PKG_NEVRA_FLAGS_NAME | - PKG_NEVRA_FLAGS_ARCH); + return rpmostree_header_custom_nevra_strdup (h1, (RpmOstreePkgNevraFlags)(PKG_NEVRA_FLAGS_NAME | + PKG_NEVRA_FLAGS_ARCH)); } static char * pkg_nvr_strdup (Header h1) { - return rpmostree_header_custom_nevra_strdup (h1, PKG_NEVRA_FLAGS_NAME | - PKG_NEVRA_FLAGS_VERSION_RELEASE); + return rpmostree_header_custom_nevra_strdup (h1, (RpmOstreePkgNevraFlags)(PKG_NEVRA_FLAGS_NAME | + PKG_NEVRA_FLAGS_VERSION_RELEASE)); } static char * pkg_evra_strdup (Header h1) { - return rpmostree_header_custom_nevra_strdup (h1, PKG_NEVRA_FLAGS_EPOCH_VERSION_RELEASE | - PKG_NEVRA_FLAGS_ARCH); + return rpmostree_header_custom_nevra_strdup (h1, (RpmOstreePkgNevraFlags)(PKG_NEVRA_FLAGS_EPOCH_VERSION_RELEASE | + PKG_NEVRA_FLAGS_ARCH)); } static void @@ -198,7 +198,7 @@ pat_fnmatch_prefix (const GPtrArray *patterns) for (num = 0; num < patterns->len; num++) { - const char *pat = patterns->pdata[num]; + auto pat = static_cast(patterns->pdata[num]); gsize prefix = 0; while (*pat) @@ -240,7 +240,7 @@ pat_fnmatch_match (Header pkg, const char *name, for (num = 0; num < patterns->len; num++) { - const char *pattern = patterns->pdata[num]; + auto pattern = static_cast(patterns->pdata[num]); if (patprefixlen && !CASENCMP_EQ (name, pattern, patprefixlen)) continue; @@ -266,19 +266,17 @@ pat_fnmatch_match (Header pkg, const char *name, static void header_free_p (gpointer data) { - headerFree (data); + headerFree (static_cast
(data)); } static int header_cmp_p (gconstpointer gph1, gconstpointer gph2) { - const Header *ph1 = gph1; - const Header *ph2 = gph2; - Header h1 = *ph1; - Header h2 = *ph2; - int cmp = header_name_cmp (h1, h2); + auto h1 = (Header *)gph1; + auto h2 = (Header *)gph2; + int cmp = header_name_cmp (*h1, *h2); if (!cmp) - cmp = rpmVersionCompare (h1, h2); + cmp = rpmVersionCompare (*h1, *h2); return cmp; } @@ -311,7 +309,7 @@ rpmhdrs_new (RpmOstreeRefTs *refts, const GPtrArray *patterns) g_ptr_array_sort (hs, header_cmp_p); - ret = g_malloc0 (sizeof (struct RpmHeaders)); + ret = (struct RpmHeaders*)g_malloc0 (sizeof (struct RpmHeaders)); ret->refts = rpmostree_refts_ref (refts); ret->hs = hs; @@ -335,7 +333,7 @@ rpmhdrs_free (struct RpmHeaders *hdrs) static struct RpmHeadersDiff * rpmhdrs_diff_new (void) { - struct RpmHeadersDiff *ret = g_malloc0(sizeof (struct RpmHeadersDiff)); + auto ret = static_cast(g_malloc0(sizeof (struct RpmHeadersDiff))); ret->hs_add = g_ptr_array_new (); ret->hs_del = g_ptr_array_new (); @@ -366,7 +364,7 @@ rpmhdrs_diff (struct RpmHeaders *l1, while (n1 < l1->hs->len) { - Header h1 = l1->hs->pdata[n1]; + auto h1 = static_cast
(l1->hs->pdata[n1]); if (n2 >= l2->hs->len) { g_ptr_array_add (ret->hs_del, h1); @@ -374,7 +372,7 @@ rpmhdrs_diff (struct RpmHeaders *l1, } else { - Header h2 = l2->hs->pdata[n2]; + auto h2 = static_cast
(l2->hs->pdata[n2]); int cmp = header_name_cmp (h1, h2); if (cmp > 0) @@ -402,7 +400,7 @@ rpmhdrs_diff (struct RpmHeaders *l1, while (n2 < l2->hs->len) { - Header h2 = l2->hs->pdata[n2]; + auto h2 = static_cast
(l2->hs->pdata[n2]); g_ptr_array_add (ret->hs_add, h2); ++n2; @@ -418,7 +416,7 @@ rpmhdrs_list (struct RpmHeaders *l1) while (num < l1->hs->len) { - Header h1 = l1->hs->pdata[num++]; + auto h1 = static_cast
(l1->hs->pdata[num++]); g_print (" "); pkg_print (h1); } @@ -436,7 +434,7 @@ rpmhdrs_rpmdbv (struct RpmHeaders *l1, while (num < l1->hs->len) { - Header pkg = l1->hs->pdata[num++]; + auto pkg = static_cast
(l1->hs->pdata[num++]); g_autofree char *envra = pkg_envra_strdup (pkg); g_checksum_update (checksum, (guint8*)envra, strlen(envra)); @@ -476,16 +474,13 @@ _gptr_array_reverse (GPtrArray *data) static int _rpmhdrs_diff_cmp_end (const GPtrArray *hs1, const GPtrArray *hs2) { - Header h1 = NULL; - Header h2 = NULL; - if (!hs2->len) return -1; if (!hs1->len) return 1; - h1 = hs1->pdata[hs1->len - 1]; - h2 = hs2->pdata[hs2->len - 1]; + auto h1 = static_cast
(hs1->pdata[hs1->len - 1]); + auto h2 = static_cast
(hs2->pdata[hs2->len - 1]); return header_name_cmp (h1, h2); } @@ -505,8 +500,8 @@ rpmhdrs_diff_prnt_block (gboolean changelogs, struct RpmHeadersDiff *diff) const char *next_srpm = NULL; for (num = 0; num < diff->hs_mod_new->len; ++num) { - Header ho = diff->hs_mod_old->pdata[num]; - Header hn = diff->hs_mod_new->pdata[num]; + auto ho = static_cast
(diff->hs_mod_old->pdata[num]); + auto hn = static_cast
(diff->hs_mod_new->pdata[num]); struct rpmtd_s ochanges_date_s; _cleanup_rpmtddata_ rpmtd ochanges_date = NULL; struct rpmtd_s ochanges_name_s; @@ -549,7 +544,7 @@ rpmhdrs_diff_prnt_block (gboolean changelogs, struct RpmHeadersDiff *diff) next_srpm = NULL; else { - Header next_ho = diff->hs_mod_old->pdata[num+1]; + auto next_ho = static_cast
(diff->hs_mod_old->pdata[num+1]); next_srpm = headerGetString(next_ho, RPMTAG_SOURCERPM); } if (g_strcmp0 (current_srpm, next_srpm) == 0) @@ -636,8 +631,8 @@ rpmhdrs_diff_prnt_block (gboolean changelogs, struct RpmHeadersDiff *diff) done = FALSE; for (num = 0; num < diff->hs_mod_new->len; ++num) { - Header ho = diff->hs_mod_old->pdata[num]; - Header hn = diff->hs_mod_new->pdata[num]; + auto ho = static_cast
(diff->hs_mod_old->pdata[num]); + auto hn = static_cast
(diff->hs_mod_new->pdata[num]); g_assert (!header_name_cmp (ho, hn)); if (rpmVersionCompare (ho, hn) < 0) @@ -660,7 +655,7 @@ rpmhdrs_diff_prnt_block (gboolean changelogs, struct RpmHeadersDiff *diff) for (num = 0; num < diff->hs_del->len; ++num) { - Header hd = diff->hs_del->pdata[num]; + auto hd = static_cast
(diff->hs_del->pdata[num]); g_print (" "); pkg_print (hd); @@ -673,7 +668,7 @@ rpmhdrs_diff_prnt_block (gboolean changelogs, struct RpmHeadersDiff *diff) for (num = 0; num < diff->hs_add->len; ++num) { - Header ha = diff->hs_add->pdata[num]; + auto ha = static_cast
(diff->hs_add->pdata[num]); g_print (" "); pkg_print (ha); @@ -700,19 +695,19 @@ rpmhdrs_diff_prnt_diff (struct RpmHeadersDiff *diff) if (_rpmhdrs_diff_cmp_end (diff->hs_mod_old, diff->hs_del) < 0) if (_rpmhdrs_diff_cmp_end (diff->hs_mod_old, diff->hs_add) < 0) { /* mod is first */ - Header hm = diff->hs_mod_old->pdata[diff->hs_mod_old->len-1]; + auto hm = static_cast
(diff->hs_mod_old->pdata[diff->hs_mod_old->len-1]); g_print ("!"); pkg_print (hm); g_ptr_array_remove_index(diff->hs_mod_old, diff->hs_mod_old->len-1); g_print ("="); - hm = diff->hs_mod_new->pdata[diff->hs_mod_new->len-1]; + hm = static_cast
(diff->hs_mod_new->pdata[diff->hs_mod_new->len-1]); pkg_print (hm); g_ptr_array_remove_index(diff->hs_mod_new, diff->hs_mod_new->len-1); } else { /* add is first */ - Header ha = diff->hs_add->pdata[diff->hs_add->len-1]; + auto ha = static_cast
(diff->hs_add->pdata[diff->hs_add->len-1]); g_print ("+"); pkg_print (ha); @@ -721,7 +716,7 @@ rpmhdrs_diff_prnt_diff (struct RpmHeadersDiff *diff) else if (_rpmhdrs_diff_cmp_end (diff->hs_del, diff->hs_add) < 0) { /* del is first */ - Header hd = diff->hs_del->pdata[diff->hs_del->len-1]; + auto hd = static_cast
(diff->hs_del->pdata[diff->hs_del->len-1]); g_print ("-"); pkg_print (hd); @@ -729,7 +724,7 @@ rpmhdrs_diff_prnt_diff (struct RpmHeadersDiff *diff) } else { /* add is first */ - Header ha = diff->hs_add->pdata[diff->hs_add->len-1]; + auto ha = static_cast
(diff->hs_add->pdata[diff->hs_add->len-1]); g_print ("+"); pkg_print (ha); @@ -754,9 +749,9 @@ rpmrev_new (OstreeRepo *repo, const char *rev, if (!rpmostree_get_refts_for_commit (repo, commit, &refts, cancellable, error)) return NULL; - RpmRevisionData *rpmrev = g_malloc0 (sizeof(struct RpmRevisionData)); - rpmrev->refts = g_steal_pointer (&refts); - rpmrev->commit = g_steal_pointer (&commit); + auto rpmrev = static_cast(g_malloc0 (sizeof(struct RpmRevisionData))); + rpmrev->refts = util::move_nullify (refts); + rpmrev->commit = util::move_nullify (commit); rpmrev->rpmdb = rpmhdrs_new (rpmrev->refts, patterns); return rpmrev; } @@ -808,7 +803,7 @@ checkout_only_rpmdb (OstreeRepo *repo, return FALSE; /* Check out the database (via copy) */ - OstreeRepoCheckoutAtOptions checkout_options = { 0, }; + OstreeRepoCheckoutAtOptions checkout_options = { (OstreeRepoCheckoutMode)0, }; checkout_options.mode = OSTREE_REPO_CHECKOUT_MODE_USER; const char *subpath = glnx_strjoina ("/", rpmdb); checkout_options.subpath = subpath; @@ -846,7 +841,7 @@ get_sack_for_root (int dfd, if (!dnf_sack_load_system_repo (sack, NULL, 0, error)) return FALSE; - *out_sack = g_steal_pointer (&sack); + *out_sack = util::move_nullify (sack); return TRUE; } @@ -1012,7 +1007,7 @@ print_pkglist (GPtrArray *pkglist) for (guint i = 0; i < pkglist->len; i++) { - DnfPackage *pkg = pkglist->pdata[i]; + auto pkg = static_cast(pkglist->pdata[i]); rpmostree_output_message (" %s (%s)", dnf_package_get_nevra (pkg), dnf_package_get_reponame (pkg)); } @@ -1170,7 +1165,7 @@ rpmostree_get_matching_packages (DnfSack *sack, hy_selector_free (selector); hy_subject_free (subject); - return g_steal_pointer (&matches); + return util::move_nullify (matches); } gboolean @@ -1197,11 +1192,11 @@ rpmostree_sack_get_by_pkgname (DnfSack *sack, if (pkgs->len > 1) return glnx_throw (error, "Multiple packages match \"%s\"", pkgname); else if (pkgs->len == 1) - ret_pkg = g_object_ref (pkgs->pdata[0]); + ret_pkg = (DnfPackage*)g_object_ref (pkgs->pdata[0]); else /* for obviousness */ ret_pkg = NULL; - *out_pkg = g_steal_pointer (&ret_pkg); + *out_pkg = util::move_nullify (ret_pkg); return TRUE; } @@ -1218,7 +1213,7 @@ rpmostree_sack_get_sorted_packages (DnfSack *sack) { g_autoptr(GPtrArray) pkglist = rpmostree_sack_get_packages (sack); g_ptr_array_sort (pkglist, (GCompareFunc)rpmostree_pkg_array_compare); - return g_steal_pointer (&pkglist); + return util::move_nullify (pkglist); } GVariant * @@ -1233,7 +1228,7 @@ rpmostree_variant_pkgs_from_sack (RpmOstreeRefSack *refsack) const guint n = pkglist->len; for (guint i = 0; i < n; i++) { - DnfPackage *pkg = pkglist->pdata[i]; + auto pkg = static_cast(pkglist->pdata[i]); /* put epoch as a string so we're indifferent to endianness -- also note that unlike * librpm, libdnf doesn't care about unset vs 0 epoch and neither do we */ @@ -1283,15 +1278,15 @@ rpmostree_decompose_nevra (const char *nevra, return glnx_throw (error, "Failed to decompose NEVRA string '%s'", nevra); if (out_name) - *out_name = g_steal_pointer (&name); + *out_name = util::move_nullify (name); if (out_epoch) *out_epoch = epoch; /* note widening */ if (out_version) - *out_version = g_steal_pointer (&version); + *out_version = util::move_nullify (version); if (out_release) - *out_release = g_steal_pointer (&release); + *out_release = util::move_nullify (release); if (out_arch) - *out_arch = g_steal_pointer (&arch); + *out_arch = util::move_nullify (arch); return TRUE; } @@ -1471,9 +1466,9 @@ rpmostree_get_enabled_rpmmd_repos (DnfContext *dnfctx, for (guint i = 0; i < repos->len; i++) { - DnfRepo *repo = repos->pdata[i]; + auto repo = static_cast(repos->pdata[i]); if (dnf_repo_get_enabled (repo) & enablement) g_ptr_array_add (ret, repo); } - return g_steal_pointer (&ret); + return util::move_nullify (ret); }