From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94410 invoked by alias); 19 Jun 2017 07:18:57 -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 94331 invoked by uid 89); 19 Jun 2017 07:18:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 19 Jun 2017 07:18:53 +0000 Received: by simark.ca (Postfix, from userid 33) id B9E4A1E5A2; Mon, 19 Jun 2017 03:18:56 -0400 (EDT) To: Sergio Durigan Junior Subject: Re: [PATCH v6] C++ify gdb/common/environ.c X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 19 Jun 2017 07:18:00 -0000 From: Simon Marchi Cc: GDB Patches , Pedro Alves In-Reply-To: <87k248y3zp.fsf@redhat.com> References: <20170413040455.23996-1-sergiodj@redhat.com> <20170619043531.32394-1-sergiodj@redhat.com> <87k248y3zp.fsf@redhat.com> Message-ID: <8aabc6fabb04f4e3e8b08e6fa1b0eacc@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.5 X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg00494.txt.bz2 On 2017-06-19 06:51, Sergio Durigan Junior wrote: > On Monday, June 19 2017, I wrote: > >> [...] >> -struct gdb_environ * >> -make_environ (void) >> +gdb_environ & >> +gdb_environ::operator= (gdb_environ &&e) >> { >> - struct gdb_environ *e; >> - >> - e = XNEW (struct gdb_environ); >> - >> - e->allocated = 10; >> - e->vector = (char **) xmalloc ((e->allocated + 1) * sizeof (char >> *)); >> - e->vector[0] = 0; >> - return e; >> -} >> - >> -/* Free an environment and all the strings in it. */ >> - >> -void >> -free_environ (struct gdb_environ *e) >> -{ >> - char **vector = e->vector; >> - >> - while (*vector) >> - xfree (*vector++); >> - >> - xfree (e->vector); >> - xfree (e); >> + clear (); >> + m_environ_vector = std::move (e.m_environ_vector); >> + return *this; >> } > > I should probably do an m_environ_vector.clear () before doing the > std::move, because the vector will contain the NULL element. I'll make > sure to do this before I push the patch. From what I saw stepping in the STL code, the previous content of the moved-to vector is cleared, as if you called .clear(). In _M_move_assign, it moves the old content to a temporary, stack allocated vector, which gets cleared when exiting that function. So I think it's not necessary. Simon