From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Sergio Durigan Junior <sergiodj@redhat.com>,
GDB Patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH v6] C++ify gdb/common/environ.c
Date: Mon, 19 Jun 2017 15:44:00 -0000 [thread overview]
Message-ID: <7cf7b53f-600a-32f5-c9d0-2f45a8bb2b46@redhat.com> (raw)
In-Reply-To: <1cff1a8055c0d770fef7171b8394e86d@polymtl.ca>
On 06/19/2017 04:30 PM, Simon Marchi wrote:
> On 2017-06-19 16:26, Pedro Alves wrote:
>> Right, m_environ_vector.clear() is not necessary.
>>
>> Note that this move assignment (and likewise the move ctor) leaves the
>> source vector empty, which violates the "there's always a NULL entry
>> at the end" invariant. That's OK if the only thing we want to support
>> of moved-from gdb_environ objects is destroying them, but please do
>> document that.
>>
>> Otherwise, people assuming the standard library's rule, may be
>> confused/surprised, into thinking that this, e.g., should work:
>>
>> gdb_environ env1;
>> env1.set ("VAR1", "value1");
>> gdb_environ env2;
>> env2 = std::move (env1); // env1 has no NULL terminator after this.
>> env1.set ("VAR1", "value2); // whoops.
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> 17.6.5.15 Moved-from state of library types
>> [lib.types.movedfrom]
>>
>> Objects of types defined in the C++ standard library may be moved
>> from (12.8).
>> Move operations may be explicitly specified or implicitly
>> generated. Unless
>> otherwise specified, such moved-from objects shall be placed in a
>> valid
>> but unspecified state.
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> That's a good point. We should definitely not let the environ object
> get in an invalid state.
>
> Whatever the rule we choose for the terminating NULL, there exists some
> valid vector states which result in invalid environ states. For
> example, an environ whose vector contains { NULL, NULL } is not valid.
> Trying to set an env var in it would give { NULL, "FOO=BAR", NULL }, and
> that results in an unexpected environment array in the end.
>
> Does that mean that after the vector move, we should make sure to leave
> the moved-from vector in a known state (i.e. clear it, and possible add
> a NULL), to make sure that we leave our environ object in a valid state?
If we take the "always push a NULL on construction" approach, and
we want moved-from gdb_environs to be valid, then yes. Note how this
results in extra heap allocations when e.g., returning a
gdb_environ from functions by value, and makes std::vector<gdb_environ>
much less efficient when it decides it needs to reallocate/move
elements. Representing the empty state with a cleared internal
vector would avoid this.
Note BTW, that we need to be careful with self-move leaving the
*this object in a valid state.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2017-06-19 15:44 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
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 [this message]
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=7cf7b53f-600a-32f5-c9d0-2f45a8bb2b46@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=sergiodj@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