diff options
author | Tom Tromey <tom@tromey.com> | 2018-09-14 23:20:58 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-09-23 23:15:12 -0600 |
commit | f5769a2c696affc3ae1274e2329777d7d4d7e8be (patch) | |
tree | 511d15a345c608ec8f24a5c0401f3aa40b4c28d1 /gdb/python/py-value.c | |
parent | 1c1e54f6b4b6de83aa3f31e6584f5bb4d6242930 (diff) | |
download | binutils-f5769a2c696affc3ae1274e2329777d7d4d7e8be.zip binutils-f5769a2c696affc3ae1274e2329777d7d4d7e8be.tar.gz binutils-f5769a2c696affc3ae1274e2329777d7d4d7e8be.tar.bz2 |
Allow conversion of pointers to Python int
PR python/18170 questions why it's not possible to convert a pointer
value to a Python int.
Digging a bit shows that the Python 2.7 int() constructor will happily
return a long in some cases. And, it seems gdb already understands
this in other places -- this is what gdb_py_object_from_longest
handles.
So, this patch simply extends valpy_int to allow pointer conversions,
as valpy_long does.
gdb/ChangeLog
2018-09-23 Tom Tromey <tom@tromey.com>
PR python/18170:
* python/py-value.c (valpy_int): Allow conversion from pointer
type.
gdb/testsuite/ChangeLog
2018-09-23 Tom Tromey <tom@tromey.com>
PR python/18170:
* gdb.python/py-value.exp (test_value_numeric_ops): Add tests to
convert pointers to int and long.
Diffstat (limited to 'gdb/python/py-value.c')
-rw-r--r-- | gdb/python/py-value.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 5c6792f..26e91ff 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1503,7 +1503,8 @@ valpy_int (PyObject *self) value = value_cast (type, value); } - if (!is_integral_type (type)) + if (!is_integral_type (type) + && TYPE_CODE (type) != TYPE_CODE_PTR) error (_("Cannot convert value to int.")); l = value_as_long (value); |