Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Keith Seitz <keiths@redhat.com>
Cc: "gdb-patches@sourceware.org ml" <gdb-patches@sourceware.org>
Subject: Re: [RFA] "constify" parse_exp_1
Date: Fri, 08 Mar 2013 13:55:00 -0000	[thread overview]
Message-ID: <5139EDDB.8080201@redhat.com> (raw)
In-Reply-To: <5139D92B.5090106@redhat.com>

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


  reply	other threads:[~2013-03-08 13:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-08  0:12 Keith Seitz
2013-03-08  0:22 ` Pedro Alves
2013-03-08  1:02   ` Keith Seitz
2013-03-08 12:27     ` Pedro Alves
2013-03-08 13:55       ` Pedro Alves [this message]
2013-03-09  1:00         ` Pedro Alves
2013-03-09  1:04           ` Keith Seitz
2013-03-11 22:09             ` Keith Seitz
2013-03-12 10:18               ` Pedro Alves
2013-03-12 17:40                 ` Keith Seitz
2013-03-08 14:54     ` Tom Tromey
2013-03-11 16:50       ` Keith Seitz
2013-03-11 18:30         ` Tom Tromey

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=5139EDDB.8080201@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.com \
    /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