Received: from eggs.gnu.org ([2001:4830:134:3::10]:53042) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpHAD-0000jf-K5 for qemu-devel@nongnu.org; Thu, 22 Oct 2015 10:48:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZpHA8-0008LY-Pw for qemu-devel@nongnu.org; Thu, 22 Oct 2015 10:48:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33632) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpHA8-0008LS-Ku for qemu-devel@nongnu.org; Thu, 22 Oct 2015 10:48:16 -0400 From: Markus Armbruster References: <5628167C.9020802@redhat.com> <87eggn6rl9.fsf@blackfin.pond.sub.org> <5628EABF.8060009@redhat.com> Date: Thu, 22 Oct 2015 16:48:14 +0200 In-Reply-To: <5628EABF.8060009@redhat.com> (Eric Blake's message of "Thu, 22 Oct 2015 07:55:11 -0600") Message-ID: <874mhjx8lt.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] DO_UPCAST confusion List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Peter Maydell , "qemu-devel@nongnu.org" Eric Blake writes: > On 10/22/2015 06:00 AM, Markus Armbruster wrote: >> Peter Maydell writes: >> >>> On 21 October 2015 at 23:49, Eric Blake wrote: >>>> I much prefer the name container_of() (which is a bit more obvious that >>>> it is finding the container or derived type that embeds the parent >>>> type), but if we have to keep the ugly name, could we at least clean up >>>> the comment to make sense, and fix the name to be DO_DOWNCAST to match >>>> what it is actually doing? >> >> DO_UPCAST() needs deletion, not renaming. >> >>> You can't call this one container_of, because it's doing >>> container_of plus extra checking. >>> > > The only extra checking is that the derived class has the parent class > as its first member. > >> Any DO_UPCAST() that have crept into other code could be simply replaced >> by container_of(). If we want to keep the extra checking Peter >> mentioned, we could have a container_of_checked() or something. *Not* a >> renamed DO_UPCAST(), because DO_UPCAST() pointlessly takes its arguments >> in a different order than container_of(). > > Or maybe container_of_first(), to make it obvious that the parent class > is the first member. > > But how often does it really matter whether the container of the parent > class had the parent as the first member? I guess we'll find out as we > try to nuke DO_UPCAST. I don't know. I dimly remember discussing a "parent must be first" restriction in qdev a long time ago. Perhaps all that's left of it by now is this check.