From patchwork Wed Apr 11 21:30:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 151916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6247EB7060 for ; Thu, 12 Apr 2012 08:50:59 +1000 (EST) Received: from localhost ([::1]:34585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SI58h-0000Z7-G2 for incoming@patchwork.ozlabs.org; Wed, 11 Apr 2012 17:31:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SI57t-0006nm-PR for qemu-devel@nongnu.org; Wed, 11 Apr 2012 17:30:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SI57r-0002Wl-Mn for qemu-devel@nongnu.org; Wed, 11 Apr 2012 17:30:53 -0400 Received: from mail-wg0-f53.google.com ([74.125.82.53]:57372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SI57r-0002Vt-F7 for qemu-devel@nongnu.org; Wed, 11 Apr 2012 17:30:51 -0400 Received: by wgbfm10 with SMTP id fm10so1220918wgb.10 for ; Wed, 11 Apr 2012 14:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=xwbiV6z+V3ETj2v60vHRrX7hlpDHmoQf1r7sKKtFAzc=; b=SkV4fznPdSbn7bimWFyKVYz+tEEYkCgMp25B2LvIX71luK3ueI5/7eZMlije3mEkZD 69eslnirjJCJCGOG39oWBERx1xtq48Lv2QaJmhhj7zd8qy1b07jOTiTxvkabx8iogZxu rogoPJL5NcxnSL6JIH1l2XtXQeWODrExvY40opl7YPwDQ/ZIbErBdUrl90hyURdqhg/K yqpIOmaPs5QANzWJd5rntTrbhKI5EmUPP8+qq4yoiRjEpZswcmc/lUFL1IT4rPMOXcMH /QrQdcLJfYjEgbbd2QdzChMQpqQzvi41+nhUHov1OrCHqEhFCqy+ewIe7nLMIzHihoOP oAjw== Received: by 10.180.80.9 with SMTP id n9mr93437wix.4.1334179849303; Wed, 11 Apr 2012 14:30:49 -0700 (PDT) Received: from yakj.lan (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id h8sm13849678wix.4.2012.04.11.14.30.48 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 11 Apr 2012 14:30:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 11 Apr 2012 23:30:21 +0200 Message-Id: <1334179842-6061-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.9.3 In-Reply-To: <1334179793-5914-1-git-send-email-pbonzini@redhat.com> References: <1334179793-5914-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.53 Cc: aliguori@us.ibm.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH v2 03/24] qom: add class_base_init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 470efe3..ccaea7d 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 pointers. * 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 itself + * 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 functions. - * 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 dynamic + * 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; 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; diff --git a/qom/object.c b/qom/object.c index 4975d93..6ff1c19 100644 --- a/qom/object.c +++ b/qom/object.c @@ -45,6 +45,7 @@ struct TypeImpl size_t instance_size; 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; @@ -112,6 +113,7 @@ TypeImpl *type_register(const TypeInfo *info) ti->instance_size = info->instance_size; ti->class_init = info->class_init; + ti->class_base_init = info->class_base_init; ti->class_finalize = info->class_finalize; ti->class_data = info->class_data; @@ -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 = type_get_parent(parent); + } } memset((void *)ti->class + class_size, 0, ti->class_size - class_size);