From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61557 invoked by alias); 21 Jul 2017 19:53:39 -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 61505 invoked by uid 89); 21 Jul 2017 19:53:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Jul 2017 19:53:37 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id v6LJrUfL012323 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2017 15:53:35 -0400 Received: by simark.ca (Postfix, from userid 112) id 58C641E5B7; Fri, 21 Jul 2017 15:53:30 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 2A26B1E5A6; Fri, 21 Jul 2017 15:53:29 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 21 Jul 2017 19:53:00 -0000 From: Simon Marchi To: Sergio Durigan Junior Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFA v2 1/4] C++-ify break-catch-sig In-Reply-To: <87d18vkmdb.fsf@redhat.com> References: <20170719203225.6714-1-tom@tromey.com> <20170719203225.6714-2-tom@tromey.com> <87d18vkmdb.fsf@redhat.com> Message-ID: <562efb619fe2c15a3c5c039770e3158f@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 21 Jul 2017 19:53:30 +0000 X-IsSubscribed: yes X-SW-Source: 2017-07/txt/msg00321.txt.bz2 On 2017-07-20 20:13, Sergio Durigan Junior wrote: >> >> while (*arg != '\0') >> { >> int num; >> - gdb_signal_type signal_number; >> - char *one_arg, *endptr; >> - struct cleanup *inner_cleanup; >> + gdb_signal signal_number; >> + char *endptr; >> >> - one_arg = extract_arg (&arg); >> + gdb::unique_xmalloc_ptr one_arg (extract_arg (&arg)); >> if (one_arg == NULL) >> break; >> - inner_cleanup = make_cleanup (xfree, one_arg); >> >> /* Check for the special flag "all". */ >> - if (strcmp (one_arg, "all") == 0) >> + if (strcmp (one_arg.get (), "all") == 0) >> { >> arg = skip_spaces (arg); >> if (*arg != '\0' || !first) >> error (_("'all' cannot be caught with other signals")); >> - *catch_all = 1; >> - gdb_assert (result == NULL); >> - do_cleanups (inner_cleanup); >> - discard_cleanups (cleanup); >> - return NULL; >> + *catch_all = true; >> + gdb_assert (result.empty ()); >> + return result; >> } >> >> first = 0; >> >> /* Check if the user provided a signal name or a number. */ >> - num = (int) strtol (one_arg, &endptr, 0); >> + num = (int) strtol (one_arg.get (), &endptr, 0); >> if (*endptr == '\0') >> signal_number = gdb_signal_from_command (num); >> else >> { >> - signal_number = gdb_signal_from_name (one_arg); >> + signal_number = gdb_signal_from_name (one_arg.get ()); >> if (signal_number == GDB_SIGNAL_UNKNOWN) >> - error (_("Unknown signal name '%s'."), one_arg); >> + error (_("Unknown signal name '%s'."), one_arg.get ()); >> } >> >> - VEC_safe_push (gdb_signal_type, result, signal_number); >> - do_cleanups (inner_cleanup); >> + result.push_back (signal_number); >> } >> >> - discard_cleanups (cleanup); >> + result.shrink_to_fit (); > > Do you really need this call here? You're using safe_push above, so I > don't think the vector will end up with a bigger capacity than its > size. safe_push is the old implementations, std::vector grows the capacity exponentially, so you're likely to be left with unused capacity. Simon