From nobody Fri May 10 02:39:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1653911488; cv=none; d=zohomail.com; s=zohoarc; b=XHAvbRZWC8vLY54hvaDpCOv62U3F13jVwbf90S+SE1F3pZvIYdsjDvgmihVegXosoCVW57kycg9oPpdrIF4rrkI5KEYNNPk0v2xxp8KgECexzncqAzIrd+98MxvxD4Znq6qttPzAq0gm68XY/7/JGbQaCTY4NJZjzr+UuAkrE5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653911488; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=hj6U9hvFS2/Qatlk1O/a6v4gkevQ6FbuHBqkNwY7fTA=; b=ISvlg3o5rNMA31PDkh8d7aycBmT/q2qfPBrYWFEdRev+afnni3qXRBTlGZKlgLwpx6qAhx7RzDXtZXaeDN2tZ1TrqHuLMuF6BXAgnNxaaN87DvUAqqxB5hvmNiZisPrtTrVYZmVmyIKs0IqzXouDkrGwYJggepXp3hXXx8kSAQw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 165391148867995.09714180760807; Mon, 30 May 2022 04:51:28 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-235-uyEUSUdtMr-c_6ObgrZkIw-1; Mon, 30 May 2022 07:51:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6A83F802803; Mon, 30 May 2022 11:51:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 567B0C27E92; Mon, 30 May 2022 11:51:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F23CA1947040; Mon, 30 May 2022 11:51:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4C3D519466DF for ; Mon, 30 May 2022 11:51:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3B2E78287E; Mon, 30 May 2022 11:51:19 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id B557D1131A for ; Mon, 30 May 2022 11:51:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653911487; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=hj6U9hvFS2/Qatlk1O/a6v4gkevQ6FbuHBqkNwY7fTA=; b=JXiPOTddtPJbMV4Dcb5lNP8cC6h4Ek8Joa7vpLhQKSbrYnbr82nfD3xTCmdew6KmD9O4Ct puT5DrZJ+N4whATz2RfWE3D5/Qv/7yCIe9/dudxuerrwwQ86WAFkvODYUOsFElbqKLT+8Y xT8poocalxLIbmSdcO13DvjxVLY/SIA= X-MC-Unique: uyEUSUdtMr-c_6ObgrZkIw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH] glibcompat: Provide proper override for 'g_hash_table_steal_extended' Date: Mon, 30 May 2022 13:51:17 +0200 Message-Id: <50a6a70e7e399e1dff560984afcb5d734047d80c.1653911477.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1653911490290100001 Content-Type: text/plain; charset="utf-8" We've emulated the function in virHashSteal, with a note pointing to use the proper version. Move the code to glibcomapt.c and make it such that builds using newer glib already use the new function. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/glibcompat.c | 20 ++++++++++++++++++++ src/util/glibcompat.h | 8 ++++++++ src/util/virhash.c | 11 +++-------- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/util/glibcompat.c b/src/util/glibcompat.c index eb6dcc0111..fdc32af5e2 100644 --- a/src/util/glibcompat.c +++ b/src/util/glibcompat.c @@ -64,6 +64,7 @@ #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #undef g_canonicalize_filename +#undef g_hash_table_steal_extended #undef g_fsync #undef g_strdup_printf #undef g_strdup_vprintf @@ -173,6 +174,25 @@ vir_g_canonicalize_filename(const gchar *filename, } +gboolean +vir_g_hash_table_steal_extended(GHashTable *hash_table, + gconstpointer lookup_key, + gpointer *stolen_key, + gpointer *stolen_value) +{ +#if GLIB_CHECK_VERSION(2, 58, 0) + return g_hash_table_steal_extended(hash_table, lookup_key, stolen_key,= stolen_value); +#else /* ! GLIB_CHECK_VERSION(2, 58, 0) */ + if (!(g_hash_table_lookup_extended(hash_table, lookup_key, stolen_key,= stolen_value))) + return FALSE; + + g_hash_table_steal(hash_table, lookup_key); + + return TRUE; +#endif /* ! GLIB_CHECK_VERSION(2, 58, 0) */ +} + + /* Drop when min glib >=3D 2.63.0 */ gint vir_g_fsync(gint fd) diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index 697687b967..1f3a6f728f 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -70,6 +70,14 @@ gchar * vir_g_canonicalize_filename(const gchar *filename, const gchar *relative_to); + +gboolean +vir_g_hash_table_steal_extended(GHashTable *hash_table, + gconstpointer lookup_key, + gpointer *stolen_key, + gpointer *stolen_value); +#define g_hash_table_steal_extended vir_g_hash_table_steal_extended + gint vir_g_fsync(gint fd); char *vir_g_strdup_printf(const char *msg, ...) G_GNUC_PRINTF(1, 2); diff --git a/src/util/virhash.c b/src/util/virhash.c index a89b2d662e..c72c248186 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -242,24 +242,19 @@ virHashHasEntry(GHashTable *table, * Find the userdata specified by @name * and remove it from the hash without freeing it. * - * Deprecated: consider using g_hash_table_steal_extended once we upgrade = to - * glib 2.58 + * Deprecated: consider using g_hash_table_steal_extended instead * * Returns a pointer to the userdata */ void *virHashSteal(GHashTable *table, const char *name) { - g_autofree void *orig_name =3D NULL; + g_autofree void *orig_name =3D NULL; /* the original key needs to be f= reed */ void *val =3D NULL; if (!table || !name) return NULL; - /* we can replace this by g_hash_table_steal_extended with glib 2.58 */ - if (!(g_hash_table_lookup_extended(table, name, &orig_name, &val))) - return NULL; - - g_hash_table_steal(table, name); + g_hash_table_steal_extended(table, name, &orig_name, &val); return val; } --=20 2.35.3