From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuW11-0001qN-G4 for qemu-devel@nongnu.org; Mon, 06 Feb 2012 16:22:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RuW0z-0008P0-Tx for qemu-devel@nongnu.org; Mon, 06 Feb 2012 16:22:23 -0500 Received: from mail-pw0-f45.google.com ([209.85.160.45]:62358) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuW0z-0008OI-Kz for qemu-devel@nongnu.org; Mon, 06 Feb 2012 16:22:21 -0500 Received: by pbaa11 with SMTP id a11so7170892pba.4 for ; Mon, 06 Feb 2012 13:22:20 -0800 (PST) Message-ID: <4F304488.1010106@codemonkey.ws> Date: Mon, 06 Feb 2012 15:22:16 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1328237992-14953-1-git-send-email-afaerber@suse.de> <1328237992-14953-4-git-send-email-afaerber@suse.de> <4F3028D2.2060409@codemonkey.ws> <4F3034AF.3000205@suse.de> In-Reply-To: <4F3034AF.3000205@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH RFC v3 03/21] qom: Introduce CPU class List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?QW5kcmVhcyBGw6RyYmVy?= Cc: Peter Maydell , qemu-devel@nongnu.org, Paolo Bonzini On 02/06/2012 02:14 PM, Andreas Färber wrote: > Am 06.02.2012 20:24, schrieb Anthony Liguori: >> On 02/02/2012 08:59 PM, Andreas Färber wrote: >>> +/** >>> + * cpu_common_reset: >>> + * @cpu: The CPU whose common state is to be reset. >>> + * >>> + * To be used by derived classes. >>> + */ >>> +void cpu_common_reset(CPU *cpu); >> >> Make this static, initialize reset = cpu_common_reset in >> cpu_class_initfn, then in the derived class initfn, save the pointer to >> the parent reset function so it can be called later. > > I don't see how that would work. To initialize, e.g., the ARMCPUClass > with additional class fields I'm overriding the .class_init. You're not overriding the class_init. The class init for a type is called when that class is initialized for the first time. See the documentation in object.h. When class_init is called, the parent class type's class_init has already been called and the default values are set. So: static void arm_cpu_reset(CPUCommon *cpu) { ARMCPU *s = ARM_CPU(cpu); ARMCPUClass *ac = ARM_CPU_GET_CLASS(s); // do arm specific reset // call super class reset ac->super_reset(cpu); } static void arm_cpu_class_initfn(ObjectClass *klass, void *data) { CPUCommonClass *cc = CPU_COMMON_CLASS(klass); ARMCPUClass *ac = ARM_CPU_CLASS(klass); // cc->reset was set in CPUCommonClass's class_init ac->super_reset = cc->reset; cc->reset = arm_cpu_reset; } It's admittedly a little funky but this is the common idiom in gobject. I'm not sure there's a better way. Regards, Anthony Liguori So in order > to let CPUClass initialize the reset callback to its static one I'd need > to make CPU's class_init function non-static so that I can call that > from my derived class' class_init function, no? > > Andreas >