Received: from eggs.gnu.org ([208.118.235.92]:37811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUm-0001c9-Bd for qemu-devel@nongnu.org; Mon, 18 Jun 2012 10:00:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SgcUS-0003Vc-VI for qemu-devel@nongnu.org; Mon, 18 Jun 2012 09:59:55 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53226 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUS-0003VH-Lc for qemu-devel@nongnu.org; Mon, 18 Jun 2012 09:59:36 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 18 Jun 2012 15:58:56 +0200 Message-Id: <1340027954-19045-5-git-send-email-afaerber@suse.de> In-Reply-To: <1340027954-19045-1-git-send-email-afaerber@suse.de> References: <1340027954-19045-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 04/22] qom: Add class_base_init List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori From: Paolo Bonzini The class_base_init TypeInfo callback was present in one of the early QOM versions but removed (on my request...) before committing. We will need it soon, add it. Signed-off-by: Paolo Bonzini Reviewed-by: Anthony Liguori Signed-off-by: Andreas F=C3=A4rber --- include/qemu/object.h | 10 ++++++++-- qom/object.c | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/qemu/object.h b/include/qemu/object.h index ce9e51f..3c29c17 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -291,10 +291,15 @@ struct Object * has occurred to allow a class to set its default virtual method poi= nters. * This is also the function to use to override virtual methods from a= parent * class. + * @class_base_init: This function is called for all base classes after = all + * parent class initialization has occurred, but before the class itse= lf + * is initialized. This is the function to use to undo the effects of + * memcpy from the parent class to the descendents. * @class_finalize: This function is called during class destruction and= is * meant to release and dynamic parameters allocated by @class_init. - * @class_data: Data to pass to the @class_init and @class_finalize func= tions. - * This can be useful when building dynamic classes. + * @class_data: Data to pass to the @class_init, @class_base_init and + * @class_finalize functions. This can be useful when building dynami= c + * classes. * @interfaces: The list of interfaces associated with this type. This * should point to a static array that's terminated with a zero filled * element. @@ -312,6 +317,7 @@ struct TypeInfo size_t class_size; =20 void (*class_init)(ObjectClass *klass, void *data); + void (*class_base_init)(ObjectClass *klass, void *data); void (*class_finalize)(ObjectClass *klass, void *data); void *class_data; =20 diff --git a/qom/object.c b/qom/object.c index 7a70d52..36379a1 100644 --- a/qom/object.c +++ b/qom/object.c @@ -45,6 +45,7 @@ struct TypeImpl size_t instance_size; =20 void (*class_init)(ObjectClass *klass, void *data); + void (*class_base_init)(ObjectClass *klass, void *data); void (*class_finalize)(ObjectClass *klass, void *data); =20 void *class_data; @@ -112,6 +113,7 @@ TypeImpl *type_register(const TypeInfo *info) ti->instance_size =3D info->instance_size; =20 ti->class_init =3D info->class_init; + ti->class_base_init =3D info->class_base_init; ti->class_finalize =3D info->class_finalize; ti->class_data =3D info->class_data; =20 @@ -232,6 +234,13 @@ static void type_initialize(TypeImpl *ti) memcpy((void *)ti->class + sizeof(ObjectClass), (void *)parent->class + sizeof(ObjectClass), parent->class_size - sizeof(ObjectClass)); + + while (parent) { + if (parent->class_base_init) { + parent->class_base_init(ti->class, ti->class_data); + } + parent =3D type_get_parent(parent); + } } =20 memset((void *)ti->class + class_size, 0, ti->class_size - class_siz= e); --=20 1.7.7