From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21708 invoked by alias); 8 Mar 2013 13:55:58 -0000 Received: (qmail 21698 invoked by uid 22791); 8 Mar 2013 13:55:53 -0000 X-SWARE-Spam-Status: No, hits=-8.0 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Mar 2013 13:55:41 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r28Dte40029278 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 8 Mar 2013 08:55:40 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r28DtdYQ007262; Fri, 8 Mar 2013 08:55:40 -0500 Message-ID: <5139EDDB.8080201@redhat.com> Date: Fri, 08 Mar 2013 13:55:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130219 Thunderbird/17.0.3 MIME-Version: 1.0 To: Keith Seitz CC: "gdb-patches@sourceware.org ml" Subject: Re: [RFA] "constify" parse_exp_1 References: <51392C56.7040302@redhat.com> <51392F3F.5090102@redhat.com> <51393886.9030602@redhat.com> <5139D92B.5090106@redhat.com> In-Reply-To: <5139D92B.5090106@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 X-SW-Source: 2013-03/txt/msg00363.txt.bz2 On 03/08/2013 12:27 PM, Pedro Alves wrote: >> > @@ -749,9 +749,13 @@ validate_actionline (char **line, struct >> > tmp_p = p; >> > for (loc = t->base.loc; loc; loc = loc->next) >> > { >> > - p = tmp_p; >> > - exp = parse_exp_1 (&p, loc->address, >> > + const char *q, *o; >> > + >> > + o = q = tmp_p; >> > + >> > + exp = parse_exp_1 (&q, loc->address, >> > block_for_pc (loc->address), 1); >> > + p += q - o; >> > old_chain = make_cleanup (free_current_contents, &exp); >> > >> > if (exp->elts[0].opcode == OP_VAR_VALUE) > Argh all that extra pointer arithmetic hurts my eyes. > > Do we really need it? BTW, over lunch I just had an epiphany. :-) This is perfectly fine: for (loc = t->base.loc; loc; loc = loc->next) { - p = tmp_p; + const char *q; + + q = tmp_p; - exp = parse_exp_1 (&p, loc->address, + exp = parse_exp_1 (&q, loc->address, block_for_pc (loc->address), 1); + p = (char *) q; It's perfectly valid, as we know Q on output must point within the object/string TMP_P pointed at on entry. This reads much more intuitively to me, no funny arithmetic, and gets rid of the aliasing issue with the other suggestion, and no new function necessary. -- Pedro Alves