From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Pedro Alves <palves@redhat.com>
Cc: GDB Patches <gdb-patches@sourceware.org>,
Simon Marchi <simon.marchi@polymtl.ca>
Subject: Re: [PATCH v4] C++ify gdb/common/environ.c
Date: Fri, 16 Jun 2017 21:59:00 -0000 [thread overview]
Message-ID: <87mv97387o.fsf@redhat.com> (raw)
In-Reply-To: <a2ee9fc7-00ed-975a-ed15-4ed5dccb9379@redhat.com> (Pedro Alves's message of "Fri, 16 Jun 2017 19:23:39 +0100")
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<char **> (empty_envp);
>>> }
>>> return const_cast<char **> (&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/
next prev parent reply other threads:[~2017-06-16 21:59 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-13 4:05 [PATCH] " Sergio Durigan Junior
2017-04-15 18:51 ` [PATCH v2] " Sergio Durigan Junior
2017-04-15 21:22 ` Simon Marchi
2017-04-18 2:49 ` Sergio Durigan Junior
2017-04-16 5:09 ` Simon Marchi
2017-04-16 17:32 ` Sergio Durigan Junior
2017-04-18 3:03 ` [PATCH v3] " Sergio Durigan Junior
2017-04-19 4:56 ` Simon Marchi
2017-04-19 16:30 ` Pedro Alves
2017-04-19 18:14 ` Pedro Alves
2017-05-01 2:22 ` Sergio Durigan Junior
2017-05-04 15:30 ` Pedro Alves
2017-06-14 19:22 ` [PATCH v4] " Sergio Durigan Junior
2017-06-16 15:45 ` Pedro Alves
2017-06-16 18:01 ` Sergio Durigan Junior
2017-06-16 18:23 ` Pedro Alves
2017-06-16 21:59 ` Sergio Durigan Junior [this message]
2017-06-16 22:23 ` [PATCH v5] " Sergio Durigan Junior
2017-06-17 8:54 ` Simon Marchi
2017-06-19 4:19 ` Sergio Durigan Junior
2017-06-19 13:40 ` Pedro Alves
2017-06-19 16:19 ` Sergio Durigan Junior
2017-06-19 12:13 ` Pedro Alves
2017-06-20 14:02 ` Pedro Alves
2017-06-19 4:36 ` [PATCH v6] " Sergio Durigan Junior
2017-06-19 4:51 ` Sergio Durigan Junior
2017-06-19 7:18 ` Simon Marchi
2017-06-19 14:26 ` Pedro Alves
2017-06-19 15:30 ` Simon Marchi
2017-06-19 15:44 ` Pedro Alves
2017-06-19 15:47 ` Pedro Alves
2017-06-19 16:26 ` Simon Marchi
2017-06-19 16:55 ` Pedro Alves
2017-06-19 17:59 ` Sergio Durigan Junior
2017-06-19 18:09 ` Pedro Alves
2017-06-19 18:23 ` Sergio Durigan Junior
2017-06-19 18:36 ` Pedro Alves
2017-06-19 18:38 ` Pedro Alves
2017-06-19 14:26 ` Pedro Alves
2017-06-19 16:13 ` Sergio Durigan Junior
2017-06-19 16:38 ` Pedro Alves
2017-06-19 16:46 ` Sergio Durigan Junior
2017-06-19 18:27 ` [PATCH v7] " Sergio Durigan Junior
2017-06-20 3:27 ` [PATCH v8] " Sergio Durigan Junior
2017-06-20 12:13 ` Pedro Alves
2017-06-20 12:46 ` Simon Marchi
2017-06-20 13:00 ` Sergio Durigan Junior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mv97387o.fsf@redhat.com \
--to=sergiodj@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox