From patchwork Thu May 19 00:13:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 12366 Received: (qmail 17416 invoked by alias); 19 May 2016 00:14:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 17403 invoked by uid 89); 19 May 2016 00:14:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_00, FSL_HELO_HOME, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=ba, b2, H*m:tromey, 18277 X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Thu, 19 May 2016 00:14:15 +0000 Received: (qmail 13238 invoked by uid 0); 19 May 2016 00:14:13 -0000 Received: from unknown (HELO cmgw4) (10.0.90.85) by gproxy5.mail.unifiedlayer.com with SMTP; 19 May 2016 00:14:13 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id w0Dy1s0092f2jeq010E1dk; Wed, 18 May 2016 18:14:13 -0600 X-Authority-Analysis: v=2.1 cv=EftbHpWC c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=PnD2wP_eR3oA:10 a=_v2sUkyEFrwA:10 a=yrkiwgmsf1kA:10 a=zstS-IiYAAAA:8 a=0FD05c-RAAAA:8 a=tShbsuj29VkDRnoWY1QA:9 a=GH5duLTDHCAMCef2:21 a=Ami-TPFTFz4ooQg-:21 a=4G6NA9xxw8l3yy4pmD5M:22 a=l1rpMCqCXRGZwUSuRcM3:22 Received: from [71.215.116.141] (port=36574 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1b3BbB-0000mI-T6; Wed, 18 May 2016 18:13:58 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Fix PR python/17386 - add __index__ method to gdb.Value Date: Wed, 18 May 2016 18:13:50 -0600 Message-Id: <1463616830-12259-1-git-send-email-tom@tromey.com> X-Identified-User: {36111:box522.bluehost.com:elynrobi:tromey.com} {sentby:smtp auth 71.215.116.141 authed with tom+tromey.com} This patch fixes PR python/17386. The bug is that gdb.Value does not implement the Python __index__ method. This method is needed to convert a Python object to an index and is used by various operations in Python, such as indexing an array. The fix is to implement the nb_index method for gdb.Value. While doing this I discovered that value_object_as_number was missing an entry. This patch fixes this. nb_index was added in Python 2.5. I don't have a good way to test Python 2.4, but I made an attempt. I chose to use valpy_long in all cases because this simplifies porting to Python 3, and because there didn't seem to be any harm. Built and regtested on x86-64 Fedora 23. 2016-05-18 Tom Tromey PR python/17386: * python/py-value.c (value_object_as_number): Add nb_inplace_divide entry, nb_inplace_floor_divide, nb_inplace_true_divide, nb_index. 2016-05-18 Tom Tromey PR python/17386: * gdb.python/py-value.exp (test_value_numeric_ops): Add test that uses value as an index. --- gdb/ChangeLog | 7 +++++++ gdb/python/py-value.c | 9 ++++++++- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-value.exp | 3 +++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 92024b6..7656a34 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2016-05-18 Tom Tromey + PR python/17386: + * python/py-value.c (value_object_as_number): Add + nb_inplace_divide entry, nb_inplace_floor_divide, + nb_inplace_true_divide, nb_index. + +2016-05-18 Tom Tromey + * rust-lang.c (rust_subscript): Initialize "high". 2016-05-17 Simon Marchi diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 7dba0ad..d34428d 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1827,6 +1827,7 @@ static PyNumberMethods value_object_as_number = { NULL, /* nb_inplace_add */ NULL, /* nb_inplace_subtract */ NULL, /* nb_inplace_multiply */ + NULL, /* nb_inplace_divide */ NULL, /* nb_inplace_remainder */ NULL, /* nb_inplace_power */ NULL, /* nb_inplace_lshift */ @@ -1835,7 +1836,13 @@ static PyNumberMethods value_object_as_number = { NULL, /* nb_inplace_xor */ NULL, /* nb_inplace_or */ NULL, /* nb_floor_divide */ - valpy_divide /* nb_true_divide */ + valpy_divide, /* nb_true_divide */ + NULL, /* nb_inplace_floor_divide */ + NULL /* nb_inplace_true_divide */ +#ifndef HAVE_LIBPYTHON_2_4 + /* This was added in Python 2.5. */ + , valpy_long /* nb_index */ +#endif /* HAVE_LIBPYTHON_2_4 */ }; static PyMappingMethods value_object_as_mapping = { diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index a773c63..5441877 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-05-18 Tom Tromey + + PR python/17386: + * gdb.python/py-value.exp (test_value_numeric_ops): Add test that + uses value as an index. + 2016-05-18 Simon Marchi * gdb.mi/mi-threads-interrupt.c: New file. diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index a9dbe97..019e45b 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -124,6 +124,9 @@ proc test_value_numeric_ops {} { gdb_test "python print ('result = ' + str(b-2))" " = 0x3( <.*>)?" "subtract python integer from pointer value" gdb_test "python print ('result = ' + str(b-a))" " = 3" "subtract two pointer values" + gdb_test "python print ('result = ' + 'result'\[gdb.Value(0)\])" \ + "result = r" "use value as an index" + # Test some invalid operations. gdb_test_multiple "python print ('result = ' + str(i+'foo'))" "catch error in python type conversion" {