This is the mail archive of the
gdb-prs@sourceware.org
mailing list for the GDB project.
[Bug python/20624] gdb.Value doesn't support Python floordiv operator, //
- From: "jwakely.gcc at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: gdb-prs at sourceware dot org
- Date: Tue, 20 Sep 2016 10:53:56 +0000
- Subject: [Bug python/20624] gdb.Value doesn't support Python floordiv operator, //
- Auto-submitted: auto-generated
- References: <bug-20624-4717@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=20624
--- Comment #1 from Jonathan Wakely <jwakely.gcc at gmail dot com> ---
It gets more complicated. Normal division with / changes behaviour between
Python 2 and Python 3, but the behaviour on gdb.Value doesn't change:
(gdb) ptype i
type = int
(gdb) python ipy = gdb.parse_and_eval('i')
(gdb) print(i)
$1 = 4
(gdb) print(i/3)
$2 = 1
(gdb) python print(ipy/3)
1
(gdb) python print(int(ipy)/3)
1.3333333333333333
Division on a gdb.Value that contains an integer performs integer division, but
if you convert the gdb.Value to a python int then the same division does "true
division". Ugh. This makes gdb python code fragile, because the meaning of the
division operator changes depending on whether you're dealing with a gdb.Value
or an int (and somewhat counterintuitively, operating on the int *doesn't* do
integer division!)
If GDB is using Python 3 should division on gdb.Value behave the same as the
builtin / operator and do "true division"? (That probably doesn't make sense
to change unless gdb.Value supports // but I'm working on that).
--
You are receiving this mail because:
You are on the CC list for the bug.