diff options
author | Tom Tromey <tom@tromey.com> | 2018-09-14 22:31:12 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-09-23 23:12:59 -0600 |
commit | fb4fa9469c5f5d87a956d45ed3b36fecc1fc31b9 (patch) | |
tree | 67775531ba40c4164d51c62d66e95f7611a43811 /gdb/testsuite/gdb.python | |
parent | e6b5f1e9f5aace67505b4eff43570c82b56139b9 (diff) | |
download | binutils-fb4fa9469c5f5d87a956d45ed3b36fecc1fc31b9.zip binutils-fb4fa9469c5f5d87a956d45ed3b36fecc1fc31b9.tar.gz binutils-fb4fa9469c5f5d87a956d45ed3b36fecc1fc31b9.tar.bz2 |
Allow more Python scalar conversions
PR python/18352 points out that the gdb Python code can't convert an
integer-valued gdb.Value to a Python float. While writing the test I
noticed that, similarly, converting integer gdb.Values to float does
not work. However, all of these cases seem reasonable.
gdb/ChangeLog
2018-09-23 Tom Tromey <tom@tromey.com>
PR python/18352;
* python/py-value.c (valpy_float): Allow conversions from int or
char.
(valpy_int, valpy_long): Allow conversions from float.
gdb/testsuite/ChangeLog
2018-09-23 Tom Tromey <tom@tromey.com>
PR python/18352;
* gdb.python/py-value.exp (test_float_conversion): New proc.
Use it.
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/py-value.exp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index eb82a77..ac08faa 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -483,6 +483,18 @@ proc test_value_hash {} { gdb_test "python print (one.__hash__() == hash(one))" "True" "test inbuilt hash" } +proc test_float_conversion {} { + global gdb_py_is_py3k + gdb_test "python print(int(gdb.Value(0)))" "0" + gdb_test "python print(int(gdb.Value(2.5)))" "2" + if {!$gdb_py_is_py3k} { + gdb_test "python print(long(gdb.Value(0)))" "0" + gdb_test "python print(long(gdb.Value(2.5)))" "2" + } + gdb_test "python print(float(gdb.Value(2.5)))" "2\\.5" + gdb_test "python print(float(gdb.Value(0)))" "0\\.0" +} + # Build C version of executable. C++ is built later. if { [build_inferior "${binfile}" "c"] < 0 } { return -1 @@ -501,6 +513,7 @@ test_value_compare test_objfiles test_parse_and_eval test_value_hash +test_float_conversion # The following tests require execution. |