diff options
author | 2014-09-13 22:24:50 -0600 | |
---|---|---|
committer | 2016-05-24 10:05:59 -0600 | |
commit | ddae946278bf4269370f7d945732485ad13469fa (patch) | |
tree | 61bb9e2d9e020af0914071e93cc39a3cd57a074f /gdb/testsuite/gdb.python/py-value.exp | |
parent | add nb_inplace_divide for python 2 (diff) | |
download | binutils-gdb-ddae946278bf4269370f7d945732485ad13469fa.tar.gz binutils-gdb-ddae946278bf4269370f7d945732485ad13469fa.tar.bz2 binutils-gdb-ddae946278bf4269370f7d945732485ad13469fa.zip |
Fix PR python/17386 - add __index__ method to gdb.Value
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.
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 to accomodate it.
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-24 Tom Tromey <tom@tromey.com>
PR python/17386:
* python/py-value.c (value_object_as_number): Add
nb_inplace_floor_divide, nb_inplace_true_divide, nb_index.
2016-05-24 Tom Tromey <tom@tromey.com>
PR python/17386:
* gdb.python/py-value.exp (test_value_numeric_ops): Add tests that
use value as an index.
Diffstat (limited to 'gdb/testsuite/gdb.python/py-value.exp')
-rw-r--r-- | gdb/testsuite/gdb.python/py-value.exp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index a9dbe97784a..57a9ba1f516 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -124,6 +124,13 @@ 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 string index" + gdb_test "python print ('result = ' + str((1,2,3)\[gdb.Value(0)\]))" \ + "result = 1" "use value as tuple index" + gdb_test "python print ('result = ' + str(\[1,2,3\]\[gdb.Value(0)\]))" \ + "result = 1" "use value as array index" + # Test some invalid operations. gdb_test_multiple "python print ('result = ' + str(i+'foo'))" "catch error in python type conversion" { |