aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2014-09-13 22:24:50 -0600
committerTom Tromey <tom@tromey.com>2016-05-24 10:05:59 -0600
commitddae946278bf4269370f7d945732485ad13469fa (patch)
tree61bb9e2d9e020af0914071e93cc39a3cd57a074f /gdb/python
parente2b7f516fc688975ea22ad3cf2066c6972454fdc (diff)
downloadgdb-ddae946278bf4269370f7d945732485ad13469fa.zip
gdb-ddae946278bf4269370f7d945732485ad13469fa.tar.gz
gdb-ddae946278bf4269370f7d945732485ad13469fa.tar.bz2
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/python')
-rw-r--r--gdb/python/py-value.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 268f6c8..7a2a235 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1838,7 +1838,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 = {