From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12818 invoked by alias); 16 Jun 2017 21:59:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 12797 invoked by uid 89); 16 Jun 2017 21:59:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=arriving X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Jun 2017 21:59:04 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C65585363; Fri, 16 Jun 2017 21:59:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2C65585363 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sergiodj@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2C65585363 Received: from localhost (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0263160461; Fri, 16 Jun 2017 21:59:07 +0000 (UTC) From: Sergio Durigan Junior To: Pedro Alves Cc: GDB Patches , Simon Marchi Subject: Re: [PATCH v4] C++ify gdb/common/environ.c References: <20170413040455.23996-1-sergiodj@redhat.com> <20170614192219.12364-1-sergiodj@redhat.com> <87vanv3j71.fsf@redhat.com> Date: Fri, 16 Jun 2017 21:59:00 -0000 In-Reply-To: (Pedro Alves's message of "Fri, 16 Jun 2017 19:23:39 +0100") Message-ID: <87mv97387o.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg00468.txt.bz2 On Friday, June 16 2017, Pedro Alves wrote: >>> Nit: I find it a bit odd that the ctors/dtors are short but >>> defined out of line, while this function is defined inline. >>> If I was looking at controlling what the compiler could inline, >>> then I'd do it the other way around -- small ctor/dtor in >>> the header, and this larger function out of line in the .c file. >> >> Question: if I define a method inside the class, does this implicitly >> tell the compiler that I want to inline it, as oppose to defining the >> method outside? > > It's not about inside vs outside. It's about the compiler seeing the > body when compiling a foo.c file that includes the gdb_environ.h header. > The compiler is invoked on a per-compilation-unit base. If you put the > method's definition outside the class but still in the gdb_environ.h header, > then the compiler would still be able to inline the method's body in the > foo.c compilation unit if it so chooses. Of course, then you'd run into > multiple definition problems at link time. So you can then mark > the definition as inline explicitly. But that's no different from putting a > free function's definition in a header. > > If you put the method instead in gdb_environ.c instead, then when the compiler > is compiling compilation unit foo.c, it has no idea what the body of > the method is, so it can't inline it. Unless you build with -flto, > of course. Ah, of course, thanks for the explanation, it makes sense obviously. >>> So we either always add a NULL to the vector, or we >>> change gdb_environ::get_char_vector instead, like: >>> >>> char ** >>> gdb_environ::get_char_vector () const >>> { >>> if (m_environ_vector.empty ()) >>> { >>> static const char *const empty_envp[1] = { NULL }; >>> return const_cast (empty_envp); >>> } >>> return const_cast (&m_environ_vector[0]); >>> } >>> >>> This is OK because execve etc. are garanteed to never change >>> the envp they're passed. >> >> Oh, good catch. I prefer to just initialize the vector with a NULL >> value in the ctor; will do that now. > > I'd prefer the other option. Because then constructing gdb_environ > is dirt cheap and doesn't require heap memory. We're constructing one > environ per inferior, even if we end up not setting any variable > [now thinking ahead to when we make this work with remote]. I guess I should always implement the option that I *don't* prefer... Anyway, v5 is ready, should be arriving at your INBOX soon. -- Sergio GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36 Please send encrypted e-mail if possible http://sergiodj.net/