From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4039 invoked by alias); 6 Jan 2015 18:52:07 -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 4026 invoked by uid 89); 6 Jan 2015 18:52:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-ob0-f177.google.com Received: from mail-ob0-f177.google.com (HELO mail-ob0-f177.google.com) (209.85.214.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 06 Jan 2015 18:52:05 +0000 Received: by mail-ob0-f177.google.com with SMTP id va2so65826330obc.8 for ; Tue, 06 Jan 2015 10:52:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=CitGtXi6DTHw1+ZZu0b/r/qRT3FsFpb8FkrUV+FtohA=; b=a6c5Ty5vAbLgXWU7IOYO1JgqhGiuUx2vrsegFfrdPaKhaG/N5ffbF5NqGYf/k0+ItO iVQxcjpmQb3/rP4V3GaJw3HW2hZfA6vv8Z/JD0dqyYp7jHk4jc9DRAM08Ej1j1e+h0mj ODtrQ/gAr1EKLsSmnwcEcat9JTUIxzD1/8g/WNqbEFpL0cBkw+sOprJDq+hUnf5v+T3z vFIElh+XghI8BHXwveUOJrlAdIPQ3xH56Uhe77FFwPzb3+MDBljS+EsSMe3I03fE1Tfa IBbQcXqNgTYc4myHx8trMUK778DvW5FomW1FeRaauIHrgYXoSyrSVrGyFvI1xItT9jDZ LvUA== X-Gm-Message-State: ALoCoQmwK8BdqUzpMWqlT/879ZPXG+0VRmwNSpqmptuV91DtWJ3Q8GJhyL2UsGkTBhcrL3E6BtAU MIME-Version: 1.0 X-Received: by 10.202.91.138 with SMTP id p132mr30649761oib.47.1420570323340; Tue, 06 Jan 2015 10:52:03 -0800 (PST) Received: by 10.182.222.98 with HTTP; Tue, 6 Jan 2015 10:52:03 -0800 (PST) In-Reply-To: <1420556955-13827-1-git-send-email-brobecker@adacore.com> References: <1420556955-13827-1-git-send-email-brobecker@adacore.com> Date: Tue, 06 Jan 2015 18:52:00 -0000 Message-ID: Subject: Re: [pushed] gdb/python: exception trying to create empty array From: Doug Evans To: Joel Brobecker Cc: gdb-patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg00083.txt.bz2 On Tue, Jan 6, 2015 at 7:09 AM, Joel Brobecker wrote: > Hello, > > The following python command fails: > > (gdb) python print gdb.lookup_type('char').array(1, 0) > Traceback (most recent call last): > File "", line 1, in > 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. :-)]