From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MW9DP-0007KW-UG for qemu-devel@nongnu.org; Wed, 29 Jul 2009 09:29:08 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MW9DL-0007Jb-4f for qemu-devel@nongnu.org; Wed, 29 Jul 2009 09:29:07 -0400 Received: from [199.232.76.173] (port=36584 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MW9DL-0007JY-2A for qemu-devel@nongnu.org; Wed, 29 Jul 2009 09:29:03 -0400 Received: from mx20.gnu.org ([199.232.41.8]:3324) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MW9DJ-0006Hx-OL for qemu-devel@nongnu.org; Wed, 29 Jul 2009 09:29:02 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MW9DI-0004az-MC for qemu-devel@nongnu.org; Wed, 29 Jul 2009 09:29:00 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e9.ny.us.ibm.com (8.14.3/8.13.1) with ESMTP id n6TDSk2Q002789 for ; Wed, 29 Jul 2009 09:28:46 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n6TDSxLu244102 for ; Wed, 29 Jul 2009 09:28:59 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n6TDSx9O020024 for ; Wed, 29 Jul 2009 09:28:59 -0400 Message-ID: <4A704E99.9020107@us.ibm.com> Date: Wed, 29 Jul 2009 08:28:57 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1248818713-11261-1-git-send-email-lcapitulino@redhat.com> <1248818713-11261-2-git-send-email-lcapitulino@redhat.com> <4A701AA3.4060902@redhat.com> In-Reply-To: <4A701AA3.4060902@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 01/25] Introduce QEMU dictionary data type List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: jan.kiszka@siemens.com, dlaor@redhat.com, qemu-devel@nongnu.org, Luiz Capitulino Avi Kivity wrote: > On 07/29/2009 01:04 AM, Luiz Capitulino wrote: >> +struct qemu_dict { >> + size_t size; >> + struct qemu_dict_entry *table[QEMU_DICT_HASH_SIZE]; >> +}; >> > > We don't need to prefix everything with qemu, I think QDict or even > Dict is sufficient. Ditto for the function names. Also please > provide a typedef as is common qemu practice. > > >> + >> +struct qemu_dict *qemu_dict_create(void); >> +void qemu_dict_add(struct qemu_dict *qdict, const char *key, void >> *value); >> +void *qemu_dict_get(const struct qemu_dict *qdict, const char *key); >> +int qemu_dict_exists(const struct qemu_dict *qdict, const char *key); >> +void *qemu_dict_del(struct qemu_dict *qdict, const char *key); >> +void qemu_dict_destroy(struct qemu_dict *qdict); >> +void qemu_dict_walk(const struct qemu_dict *qdict, >> + void (*walkf)(const char *key, void *value)); >> + >> > > I'm worried about all those void *s as they move responsibility for > type safety and lifecycle management to the user. I'd much rather see > a QObject (or Object) with the following methods: > > clone() - deep copy an object; dicts will store copies so we'll > avoid those leaks or a dictionary member modified after it was stored > destroy() It probably would be just as easy to do a ref()/unref() such that the deep copying was avoided. -- Regards, Anthony Liguori