From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvLTl-0008H4-Un for qemu-devel@nongnu.org; Tue, 06 Oct 2009 21:38:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvLTh-0008Af-81 for qemu-devel@nongnu.org; Tue, 06 Oct 2009 21:38:09 -0400 Received: from [199.232.76.173] (port=43177 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvLTg-0008AI-QP for qemu-devel@nongnu.org; Tue, 06 Oct 2009 21:38:04 -0400 Received: from e38.co.us.ibm.com ([32.97.110.159]:36637) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MvLTg-0006ay-AT for qemu-devel@nongnu.org; Tue, 06 Oct 2009 21:38:04 -0400 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e38.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id n971XZ9a000402 for ; Tue, 6 Oct 2009 19:33:35 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id n971biWP217394 for ; Tue, 6 Oct 2009 19:37:44 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n971biv9027850 for ; Tue, 6 Oct 2009 19:37:44 -0600 Message-ID: <4ACBF0E7.1010207@us.ibm.com> Date: Tue, 06 Oct 2009 20:37:43 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1254875232-25012-1-git-send-email-lcapitulino@redhat.com> <1254875232-25012-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1254875232-25012-3-git-send-email-lcapitulino@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 02/15] Introduce QList List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: qemu-devel@nongnu.org, avi@redhat.com Luiz Capitulino wrote: > QList is a high-level data type that can be used to store QObjects > in a singly-linked list. > > The following functions are available: > > - qlist_new() Create a new QList > - qlist_append() Append a QObject to the list > - qlist_iter() Iterate over stored QObjects > > Signed-off-by: Luiz Capitulino > --- > Makefile | 2 +- > qlist.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > qlist.h | 27 ++++++++++++++++ > qobject.h | 1 + > 4 files changed, 129 insertions(+), 1 deletions(-) > create mode 100644 qlist.c > create mode 100644 qlist.h > > +/** > + * qlist_iter(): Iterate over all the list's stored values. > + * > + * This function allows the user to provide an iterator, which will be > + * called for each stored value in the list. > + */ > +void qlist_iter(const QList *qlist, > + void (*iter)(QObject *obj, void *opaque), void *opaque) > +{ > + QListEntry *entry; > + > + QTAILQ_FOREACH(entry, &qlist->head, next) > + iter(entry->value, opaque); > +} > + > +/** > + * qobject_to_qlist(): Convert a QObject into a QList > + */ > +QList *qobject_to_qlist(const QObject *obj) > +{ > + if (qobject_type(obj) != QTYPE_QLIST) > + return NULL; > + > + return container_of(obj, QList, base); > +} > Missing {} around ifs. > + > +/** > + * qlist_destroy_obj(): Free all the memory allocated by a QList > + */ > +static void qlist_destroy_obj(QObject *obj) > +{ > + QList *qlist; > + QListEntry *entry, *next_entry; > + > + assert(obj != NULL); > Usually accepting NULL in a free function makes for nicer exit paths in function. > + qlist = qobject_to_qlist(obj); > + > + QTAILQ_FOREACH_SAFE(entry, &qlist->head, next, next_entry) { > + QTAILQ_REMOVE(&qlist->head, entry, next); > + qobject_decref(entry->value); > + qemu_free(entry); > + } > + > + qemu_free(qlist); > +} > + > +static const QType qlist_type = { > + .code = QTYPE_QLIST, > + .destroy = qlist_destroy_obj, > +}; > Forward definitions of statics usually indicate code motion is in order. In this case, I think it's probably a good idea as my first reaction to this was, gees, this has to be dead code since it's a static at the end of a file. > diff --git a/qlist.h b/qlist.h > new file mode 100644 > index 0000000..b38786e > --- /dev/null > +++ b/qlist.h > @@ -0,0 +1,27 @@ > Missing copyright/license. > +#ifndef QLIST > +#define QLIST > Should probably at least do QLIST_H to avoid namespace polution. -- Regards, Anthony Liguori