From nobody Mon Feb 9 07:38:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1603359433; cv=none; d=zohomail.com; s=zohoarc; b=ZjU9LQ/uTz0kA+f+PgZoXBhywG7qtgOTUZXPw/aovtHOg93v8j2NBJRNUqrTwCXWF/c1nDpewPTtGOQ+zUEX4KVjz8MCw9Bt6Guo3gxwzDK0m17hm6Uj1tEYCa4xZ+AG9LAIlUYEj50rwnRusKGMUxNPAEjZlYFh1gHqpbvCnyQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603359433; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vpt3DY23b1rQllZbwQusdUvsMc/HpSwNPU54fpfK4cI=; b=eg0OZ6+KfQCcOY69VQnP2/Rl9GzoocwaEofOCj45zl9CfojmoeQsqJfl8A8413DtSlP/MfEaT5ZLDFGNYb3cvPXzDKivfVMZE+zUKptKTNMJMIYNfdJHcTrR43ZsswT7t5EAr1o7IA1OgFqE/RZ0kkj6Kb/mmStl30tyHUBQvk4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603359433071962.087911031176; Thu, 22 Oct 2020 02:37:13 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-5Dz5yaXINWqH1_K9Uf4QTw-1; Thu, 22 Oct 2020 05:35:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 00FF65F9D6; Thu, 22 Oct 2020 09:35:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3F8A6EF6B; Thu, 22 Oct 2020 09:35:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A001844A43; Thu, 22 Oct 2020 09:35:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09M9ZVqE024608 for ; Thu, 22 Oct 2020 05:35:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id C29B15B4A8; Thu, 22 Oct 2020 09:35:31 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24E925B4C2 for ; Thu, 22 Oct 2020 09:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603359432; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=vpt3DY23b1rQllZbwQusdUvsMc/HpSwNPU54fpfK4cI=; b=PwtdKAY3P9htbOvltp0/FUSP+K85EPwsOcXyt6yL1XM2ENivcn6nTvd3QDhoZgQKo/Lxe2 k+LA7JYaa0F2a2SGV7ai/uHPpbqkZgxVVH5SeU0RZgtEgF/rzmLOvscwfsiWWTBmocHQCm WNJJT8Mjx4iNghVc0eIF6w9UvAkELsI= X-MC-Unique: 5Dz5yaXINWqH1_K9Uf4QTw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/15] util: virhash: Remove key handling callbacks Date: Thu, 22 Oct 2020 11:35:05 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" Since we use virHashTable for string-keyed values only, we can remove all the callbacks which allowed universal keys. Code which wishes to use non-string keys should use glib's GHashTable. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/util/virhash.c | 68 +++++++--------------------------------------- src/util/virhash.h | 54 ------------------------------------ 2 files changed, 10 insertions(+), 112 deletions(-) diff --git a/src/util/virhash.c b/src/util/virhash.c index f386839d6b..7a20b28379 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -56,11 +56,6 @@ struct _virHashTable { size_t size; size_t nbElems; virHashDataFree dataFree; - virHashKeyCode keyCode; - virHashKeyEqual keyEqual; - virHashKeyCopy keyCopy; - virHashKeyPrintHuman keyPrint; - virHashKeyFree keyFree; }; struct _virHashAtomic { @@ -81,40 +76,10 @@ static int virHashAtomicOnceInit(void) VIR_ONCE_GLOBAL_INIT(virHashAtomic); - -static uint32_t virHashStrCode(const char *name, uint32_t seed) -{ - return virHashCodeGen(name, strlen(name), seed); -} - -static bool virHashStrEqual(const char *namea, const char *nameb) -{ - return STREQ(namea, nameb); -} - -static char *virHashStrCopy(const char *name) -{ - return g_strdup(name); -} - - -static char * -virHashStrPrintHuman(const char *name) -{ - return g_strdup(name); -} - - -static void virHashStrFree(char *name) -{ - VIR_FREE(name); -} - - static size_t virHashComputeKey(const virHashTable *table, const char *name) { - uint32_t value =3D table->keyCode(name, table->seed); + uint32_t value =3D virHashCodeGen(name, strlen(name), table->seed); return value % table->size; } @@ -138,11 +103,6 @@ virHashNew(virHashDataFree dataFree) table->size =3D 32; table->nbElems =3D 0; table->dataFree =3D dataFree; - table->keyCode =3D virHashStrCode; - table->keyEqual =3D virHashStrEqual; - table->keyCopy =3D virHashStrCopy; - table->keyPrint =3D virHashStrPrintHuman; - table->keyFree =3D virHashStrFree; table->table =3D g_new0(virHashEntryPtr, table->size); @@ -260,8 +220,7 @@ virHashFree(virHashTablePtr table) if (table->dataFree) table->dataFree(iter->payload); - if (table->keyFree) - table->keyFree(iter->name); + g_free(iter->name); VIR_FREE(iter); iter =3D next; } @@ -287,20 +246,15 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const = char *name, /* Check for duplicate entry */ for (entry =3D table->table[key]; entry; entry =3D entry->next) { - if (table->keyEqual(entry->name, name)) { + if (STREQ(entry->name, name)) { if (is_update) { if (table->dataFree) table->dataFree(entry->payload); entry->payload =3D userdata; return 0; } else { - g_autofree char *keystr =3D NULL; - - if (table->keyPrint) - keystr =3D table->keyPrint(name); - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Duplicate hash table key '%s'"), NULLSTR= (keystr)); + _("Duplicate hash table key '%s'"), name); return -1; } } @@ -309,7 +263,7 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const ch= ar *name, } entry =3D g_new0(virHashEntry, 1); - entry->name =3D table->keyCopy(name); + entry->name =3D g_strdup(name); entry->payload =3D userdata; if (last) @@ -388,7 +342,7 @@ virHashGetEntry(const virHashTable *table, key =3D virHashComputeKey(table, name); for (entry =3D table->table[key]; entry; entry =3D entry->next) { - if (table->keyEqual(entry->name, name)) + if (STREQ(entry->name, name)) return entry; } @@ -510,11 +464,10 @@ virHashRemoveEntry(virHashTablePtr table, const char = *name) nextptr =3D table->table + virHashComputeKey(table, name); for (entry =3D *nextptr; entry; entry =3D entry->next) { - if (table->keyEqual(entry->name, name)) { + if (STREQ(entry->name, name)) { if (table->dataFree) table->dataFree(entry->payload); - if (table->keyFree) - table->keyFree(entry->name); + g_free(entry->name); *nextptr =3D entry->next; VIR_FREE(entry); table->nbElems--; @@ -601,8 +554,7 @@ virHashRemoveSet(virHashTablePtr table, count++; if (table->dataFree) table->dataFree(entry->payload); - if (table->keyFree) - table->keyFree(entry->name); + g_free(entry->name); *nextptr =3D entry->next; VIR_FREE(entry); table->nbElems--; @@ -669,7 +621,7 @@ void *virHashSearch(const virHashTable *ctable, for (entry =3D table->table[i]; entry; entry =3D entry->next) { if (iter(entry->payload, entry->name, data)) { if (name) - *name =3D table->keyCopy(entry->name); + *name =3D g_strdup(entry->name); return entry->payload; } } diff --git a/src/util/virhash.h b/src/util/virhash.h index 78c7459390..d7cea75c35 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -54,60 +54,6 @@ typedef int (*virHashIterator) (void *payload, const cha= r *name, void *data); typedef int (*virHashSearcher) (const void *payload, const char *name, const void *data); -/** - * virHashKeyCode: - * @name: the hash key - * @seed: random seed - * - * Compute the hash code corresponding to the key @name, using - * @seed to perturb the hashing algorithm - * - * Returns the hash code - */ -typedef uint32_t (*virHashKeyCode)(const char *name, - uint32_t seed); -/** - * virHashKeyEqual: - * @namea: the first hash key - * @nameb: the second hash key - * - * Compare two hash keys for equality - * - * Returns true if the keys are equal, false otherwise - */ -typedef bool (*virHashKeyEqual)(const char *namea, const char *nameb); -/** - * virHashKeyCopy: - * @name: the hash key - * - * Create a copy of the hash key, duplicating - * memory allocation where applicable - * - * Returns a copy of @name which will eventually be passed to the - * 'virHashKeyFree' callback at the end of its lifetime. - */ -typedef char *(*virHashKeyCopy)(const char *name); -/** - * virHashKeyPrintHuman: - * @name: the hash key - * - * Get a human readable version of the key for error messages. Caller - * will free the returned string. - * - * Returns a string representation of the key for use in error messages. C= aller - * promises to always free the returned string. - */ -typedef char *(*virHashKeyPrintHuman) (const char *name); - -/** - * virHashKeyFree: - * @name: the hash key - * - * Free any memory associated with the hash - * key @name - */ -typedef void (*virHashKeyFree)(char *name); - /* * Constructor and destructor. */ --=20 2.26.2