public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Doug Evans <dje@google.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [pushed] gdb/python: exception trying to create empty array
Date: Tue, 06 Jan 2015 18:52:00 -0000	[thread overview]
Message-ID: <CADPb22R9OYrvjgpHr63V5ewZPxAmyrcSwMOUAkd05HesPxfwrg@mail.gmail.com> (raw)
In-Reply-To: <1420556955-13827-1-git-send-email-brobecker@adacore.com>

On Tue, Jan 6, 2015 at 7:09 AM, Joel Brobecker <brobecker@adacore.com> wrote:
> Hello,
>
> The following python command fails:
>
>     (gdb) python print gdb.lookup_type('char').array(1, 0)
>     Traceback (most recent call last):
>       File "<string>", line 1, in <module>
>     ValueError: Array length must not be negative
>     Error while executing Python code.
>
> The above is trying to create an empty array, which is fairly command
> in Ada.
>
> gdb/ChangeLog:
>
>         * python/py-type.c (typy_array_1): Do not raise negative-length
>         exception if N2 is equal to N1 - 1.
>
> gdb/testsuite/ChangeLog:
>
>         * gdb.python/py-type.exp: Add a couple test about empty
>         array creation, and negative-length array creation.
>
> Tested on x86_64-linux, no regression.  Pushed a obvious.
> [...]
> diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
> index 54fc30f..8e82c99 100644
> --- a/gdb/python/py-type.c
> +++ b/gdb/python/py-type.c
> @@ -528,7 +528,7 @@ typy_array_1 (PyObject *self, PyObject *args, int is_vector)
>        n1 = 0;
>      }
>
> -  if (n2 < n1)
> +  if (n2 < n1 - 1)
>      {
>        PyErr_SetString (PyExc_ValueError,
>                        _("Array length must not be negative"));

Hi.

I think it might not be immediately obvious to the reader why the test
is "n2 < n1 - 1".
[E.g, there's no
Can you add a comment?

Thanks!

[fwiw, I don't want to introduce thoughts of what might or might not
be an obvious
patch. I don't have a problem with checking in something one thinks is obvious.
I just read code like this and scratch my head for a bit, and wish we had more
comments explaining the why of things. A one liner

  /* Note: An empty array has n2 == n1 - 1.  */

would help this poor reader a lot.

And while not a requirement of this patch,
lookup_array_range_type could use a comment explaining what the
correct way of specifying an empty array is.
[I'm assuming that's the correct way, I haven't actually tried it. :-)]

  reply	other threads:[~2015-01-06 18:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-06 15:09 Joel Brobecker
2015-01-06 18:52 ` Doug Evans [this message]
2015-01-07  3:38   ` Joel Brobecker

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=CADPb22R9OYrvjgpHr63V5ewZPxAmyrcSwMOUAkd05HesPxfwrg@mail.gmail.com \
    --to=dje@google.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).