From nobody Mon May 13 04:49:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1674845781; cv=none; d=zohomail.com; s=zohoarc; b=Lu8S3qyZrF1n5WKNNHJhkFaojq+MbDX5V+j5wKQlyxxvBZ4voV3kR5VMFdothXnktC/kWOeC1+Fl6T4CbM0r6X4Z7eJKtcnMkSs4M2f20J+2qQiMme2Z0ASSx5G48GGNa5LzFPfJ7W2QUrQFIDvG5x1sXTBdG5gA8IlmAfxXuLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674845781; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Pp20tM9NtELwv5dXWmU95bkMysXiBUg791NET6iHyfY=; b=NyPEWD3pXTqcuaz1kBK53LD7nRh2iXO8cKDxC/W1DYmisYsiLbkqVRpr9QkaN1atlUDiwDVwEaJnTHkS4iqaqACAh+8aIn3+V/ingbyNILF3xoNsoD33XtdXCKgBmFFXxCzCoD8xnILVHJxsAo+yh2LvaOt2WkrtovmtMJrLkx8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1674845781512571.4251685104949; Fri, 27 Jan 2023 10:56:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.485881.753313 (Exim 4.92) (envelope-from ) id 1pLTtA-00073M-Fs; Fri, 27 Jan 2023 18:55:52 +0000 Received: by outflank-mailman (output) from mailman id 485881.753313; Fri, 27 Jan 2023 18:55:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pLTtA-00073F-CV; Fri, 27 Jan 2023 18:55:52 +0000 Received: by outflank-mailman (input) for mailman id 485881; Fri, 27 Jan 2023 18:55:51 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pLTt9-000739-Ib for xen-devel@lists.xenproject.org; Fri, 27 Jan 2023 18:55:51 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pLTt9-0005jI-BT; Fri, 27 Jan 2023 18:55:51 +0000 Received: from 54-240-197-224.amazon.com ([54.240.197.224] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pLTt9-0008VI-3T; Fri, 27 Jan 2023 18:55:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From; bh=Pp20tM9NtELwv5dXWmU95bkMysXiBUg791NET6iHyfY=; b=t3i9qm UXJSYfDdLu6L3v9dK044e4R2+jjG1ARSiC8SAeKhhNr3YaRlOQesOqD6iQlZnOL6UBOAzhNRFVGct Xv5MhsSFvoy5p61UeyYLgCEqKLycM5o31Ooe80Sk8g86rJWkdN+fD0Ph2CvKhVn1FCZtRx+Yid46R Pn5e6udcrh0=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Wei Liu , Juergen Gross , Anthony PERARD Subject: [PATCH] tools/xenstored: hashtable: Constify the parameters of hashfn/eqfn Date: Fri, 27 Jan 2023 18:55:46 +0000 Message-Id: <20230127185546.65760-1-julien@xen.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1674845783051100001 Content-Type: text/plain; charset="utf-8" From: Julien Grall The parameters of hashfn/eqfn should never be modified. So constify them and propagate the const to the users. Take the opportunity to solve some coding style issues around the code modified. Signed-off-by: Julien Grall Reviewed-by: Henry Wang Reviewed-by: Juergen Gross Tested-by: Henry Wang --- tools/xenstore/hashtable.c | 16 ++++++++-------- tools/xenstore/hashtable.h | 10 +++++----- tools/xenstore/xenstored_core.c | 8 ++++---- tools/xenstore/xenstored_domain.c | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 30eb9f21d250..3d4466b59756 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -23,8 +23,8 @@ struct hashtable { unsigned int entrycount; unsigned int loadlimit; unsigned int primeindex; - unsigned int (*hashfn) (void *k); - int (*eqfn) (void *k1, void *k2); + unsigned int (*hashfn) (const void *k); + int (*eqfn) (const void *k1, const void *k2); }; =20 /* @@ -53,8 +53,8 @@ indexFor(unsigned int tablelength, unsigned int hashvalue= ) { /*************************************************************************= ****/ struct hashtable * create_hashtable(const void *ctx, unsigned int minsize, - unsigned int (*hashf) (void*), - int (*eqf) (void*,void*), + unsigned int (*hashf) (const void *), + int (*eqf) (const void *, const void *), unsigned int flags) { struct hashtable *h; @@ -92,7 +92,7 @@ err0: =20 /*************************************************************************= ****/ unsigned int -hash(struct hashtable *h, void *k) +hash(const struct hashtable *h, const void *k) { /* Aim to protect against poor hash functions by adding logic here * - logic taken from java 1.4 hashtable source */ @@ -151,7 +151,7 @@ hashtable_expand(struct hashtable *h) =20 /*************************************************************************= ****/ unsigned int -hashtable_count(struct hashtable *h) +hashtable_count(const struct hashtable *h) { return h->entrycount; } @@ -188,7 +188,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v) =20 /*************************************************************************= ****/ void * /* returns value associated with key */ -hashtable_search(struct hashtable *h, void *k) +hashtable_search(const struct hashtable *h, const void *k) { struct entry *e; unsigned int hashvalue, index; @@ -206,7 +206,7 @@ hashtable_search(struct hashtable *h, void *k) =20 /*************************************************************************= ****/ void -hashtable_remove(struct hashtable *h, void *k) +hashtable_remove(struct hashtable *h, const void *k) { /* TODO: consider compacting the table when the load factor drops enou= gh, * or provide a 'compact' method. */ diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index 4e2823134eb3..cc0090f13378 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -24,8 +24,8 @@ struct hashtable; =20 struct hashtable * create_hashtable(const void *ctx, unsigned int minsize, - unsigned int (*hashfunction) (void*), - int (*key_eq_fn) (void*,void*), + unsigned int (*hashfunction) (const void *), + int (*key_eq_fn) (const void *, const void *), unsigned int flags ); =20 @@ -61,7 +61,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v); */ =20 void * -hashtable_search(struct hashtable *h, void *k); +hashtable_search(const struct hashtable *h, const void *k); =20 /*************************************************************************= **** * hashtable_remove @@ -72,7 +72,7 @@ hashtable_search(struct hashtable *h, void *k); */ =20 void -hashtable_remove(struct hashtable *h, void *k); +hashtable_remove(struct hashtable *h, const void *k); =20 /*************************************************************************= **** * hashtable_count @@ -82,7 +82,7 @@ hashtable_remove(struct hashtable *h, void *k); * @return the number of items stored in the hashtable */ unsigned int -hashtable_count(struct hashtable *h); +hashtable_count(const struct hashtable *h); =20 /*************************************************************************= **** * hashtable_iterate diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 4f00e0cdc0cf..7348f935bc26 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2386,9 +2386,9 @@ void setup_structure(bool live_update) } } =20 -static unsigned int hash_from_key_fn(void *k) +static unsigned int hash_from_key_fn(const void *k) { - char *str =3D k; + const char *str =3D k; unsigned int hash =3D 5381; char c; =20 @@ -2399,9 +2399,9 @@ static unsigned int hash_from_key_fn(void *k) } =20 =20 -static int keys_equal_fn(void *key1, void *key2) +static int keys_equal_fn(const void *key1, const void *key2) { - return 0 =3D=3D strcmp((char *)key1, (char *)key2); + return 0 =3D=3D strcmp(key1, key2); } =20 int remember_string(struct hashtable *hash, const char *str) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index 9ef41ede03ae..d7fc2fafc729 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -916,14 +916,14 @@ void dom0_init(void) xenevtchn_notify(xce_handle, dom0->port); } =20 -static unsigned int domhash_fn(void *k) +static unsigned int domhash_fn(const void *k) { - return *(unsigned int *)k; + return *(const unsigned int *)k; } =20 -static int domeq_fn(void *key1, void *key2) +static int domeq_fn(const void *key1, const void *key2) { - return *(unsigned int *)key1 =3D=3D *(unsigned int *)key2; + return *(const unsigned int *)key1 =3D=3D *(const unsigned int *)key2; } =20 void domain_init(int evtfd) --=20 2.38.1