From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 53402 invoked by alias); 28 Sep 2017 10:20:45 -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 53389 invoked by uid 89); 28 Sep 2017 10:20:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Thu, 28 Sep 2017 10:20:44 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C89402CE1EC; Thu, 28 Sep 2017 10:20:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C89402CE1EC Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves@redhat.com Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2969351894; Thu, 28 Sep 2017 10:20:41 +0000 (UTC) Subject: Re: [RFA 10/11] Use a std::vector for ada_exceptions_list To: Tom Tromey , gdb-patches@sourceware.org References: <20170912185736.20436-1-tom@tromey.com> <20170912185736.20436-11-tom@tromey.com> From: Pedro Alves Message-ID: <6bb3084f-9051-1d18-c109-d6663a993a64@redhat.com> Date: Thu, 28 Sep 2017 10:20:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170912185736.20436-11-tom@tromey.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-09/txt/msg00860.txt.bz2 On 09/12/2017 07:57 PM, Tom Tromey wrote: > Change ada_exceptions_list to return a std::vector and fix up the > users. This allows removing a cleanup in MI. Looks good to me with the nits below addressed. > diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c > index 64f1a33..cafba2d 100644 > --- a/gdb/ada-lang.c > +++ b/gdb/ada-lang.c > @@ -62,6 +62,7 @@ > #include "cli/cli-utils.h" > #include "common/function-view.h" > #include "common/byte-vector.h" > +#include > > /* Define whether or not the C operator '/' truncates towards zero for > differently signed operands (truncation direction is undefined in C). > @@ -13121,23 +13122,23 @@ ada_is_non_standard_exception_sym (struct symbol *sym) > The comparison is determined first by exception name, and then > by exception address. */ This comment talks about qsort. It should be updated to mention std::sort instead, since the logic is different. > > -static int > -compare_ada_exception_info (const void *a, const void *b) > +bool > +ada_exc_info::operator< (const ada_exc_info &other) > { > - const struct ada_exc_info *exc_a = (struct ada_exc_info *) a; > - const struct ada_exc_info *exc_b = (struct ada_exc_info *) b; > int result; > > - result = strcmp (exc_a->name, exc_b->name); > - if (result != 0) > - return result; > - > - if (exc_a->addr < exc_b->addr) > - return -1; > - if (exc_a->addr > exc_b->addr) > - return 1; > + result = strcmp (name, other.name); > + if (result < 0) > + return true; > + if (result == 0 && addr < other.addr) > + return true; > + return false; > +} > > - return 0; > +bool > +ada_exc_info::operator== (const ada_exc_info &other) > +{ > + return strcmp (name, other.name) == 0 && addr == other.addr; I'd swap the comparisons to put the cheap addr comparison first. > if (regexp != NULL) > printf_filtered > @@ -13404,10 +13386,8 @@ info_exceptions_command (char *regexp, int from_tty) > else > printf_filtered (_("All defined Ada exceptions:\n")); > > - for (ix = 0; VEC_iterate(ada_exc_info, exceptions, ix, info); ix++) > - printf_filtered ("%s: %s\n", info->name, paddress (gdbarch, info->addr)); > - > - do_cleanups (cleanup); > + for (ada_exc_info &info : exceptions) > + printf_filtered ("%s: %s\n", info.name, paddress (gdbarch, info.addr)); I'd write 'const ada_exc_info &', just for general use-const-if-possible reasons. > - for (ix = 0; VEC_iterate(ada_exc_info, exceptions, ix, info); ix++) > + for (ada_exc_info &info : exceptions) Ditto. Thanks, Pedro Alves