This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [pushed] gdb/python: exception trying to create empty array
- From: Doug Evans <dje at google dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: gdb-patches <gdb-patches at sourceware dot org>
- Date: Tue, 6 Jan 2015 10:52:03 -0800
- Subject: Re: [pushed] gdb/python: exception trying to create empty array
- Authentication-results: sourceware.org; auth=none
- References: <1420556955-13827-1-git-send-email-brobecker at adacore dot 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. :-)]