From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzQGC-0007uY-Mh for qemu-devel@nongnu.org; Tue, 03 Oct 2017 12:41:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzQG7-0003be-Um for qemu-devel@nongnu.org; Tue, 03 Oct 2017 12:41:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60656) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzQG7-0003ah-OH for qemu-devel@nongnu.org; Tue, 03 Oct 2017 12:41:27 -0400 Date: Tue, 3 Oct 2017 18:41:22 +0200 From: Igor Mammedov Message-ID: <20171003184122.1e023f6e@nial.brq.redhat.com> In-Reply-To: References: <20171002192404.GC17385@localhost.localdomain> <1507032886-199950-1-git-send-email-imammedo@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qom: add helpers REGISTER_STATIC_TYPE[S]() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: QEMU Developers , Eduardo Habkost On Tue, 3 Oct 2017 16:44:28 +0100 Peter Maydell wrote: > On 3 October 2017 at 13:14, Igor Mammedov wrote: > > it will help to remove code duplication in places > > that currently open code registration of static > > type[s] and remove necessity to declare function > > for type_init() to call, when only static types > > need to be registered. > > > > Signed-off-by: Igor Mammedov > > --- > > I'm going to use it for CPU types in followup patches > > > > CC: ehabkost@redhat.com > > --- > > include/qemu/module.h | 10 ++++++++++ > > include/qom/object.h | 10 ++++++++++ > > qom/object.c | 9 +++++++++ > > 3 files changed, 29 insertions(+) > > > > diff --git a/include/qemu/module.h b/include/qemu/module.h > > index 56dd218..60dd632 100644 > > --- a/include/qemu/module.h > > +++ b/include/qemu/module.h > > @@ -52,6 +52,16 @@ typedef enum { > > #define type_init(function) module_init(function, MODULE_INIT_QOM) > > #define trace_init(function) module_init(function, MODULE_INIT_TRACE) > > > > +#define REGISTER_STATIC_TYPES(t, nr) \ > > +static void do_qemu_init_ ## t(void) \ > > +{ \ > > + type_register_static_array(t, nr); \ > > +} \ > > +type_init(do_qemu_init_ ## t) > > Could we use > type_register_static_array(t, ARRAY_SIZE(t)); > here to save the caller having to pass the array size, > or is that too magic? +1 this way user will not have to type ARRAY_SIZE(t) and make mistake by chance