Re: [PATCH] libstdc++/77645 fix deque and vector xmethods for Python 3
On 20/09/16 09:41 +0100, Jonathan Wakely wrote: On 19/09/16 21:39 +, Joseph Myers wrote: On Mon, 19 Sep 2016, Jonathan Wakely wrote: On 19/09/16 17:24 +, Joe Buck wrote: Python has a distinct integer division operator, "//". 7 // 3 returns the integer 2. Python 3 does, but Python 2 doesn't have it unless you import it from __future, and I don't know how far back that works. I don't want to introduce a fix for Python 3 that breaks it for old systems. No, // is available in Python, without needing __future__, from 2.2 onwards. I stand corrected, thanks both of you. I'll test and commnit this then. I still need a cast in one place, because gdb.Value doesn't support the // operator (https://sourceware.org/PR20624). Tested x86_64-linux, committed to all branches. commit c5abd6b08844bb626ea3f3df9e33bb2b97829624 Author: Jonathan WakelyDate: Tue Sep 20 10:50:55 2016 +0100 Replace casts with floordiv operator in Python xmethods * python/libstdcxx/v6/xmethods.py (DequeWorkerBase.__init__) (DequeWorkerBase.index, VectorWorkerBase.get): Use // for division. diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py index 71a5b75..eb0dd79 100644 --- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py +++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py @@ -165,7 +165,7 @@ class ArrayMethodsMatcher(gdb.xmethod.XMethodMatcher): class DequeWorkerBase(gdb.xmethod.XMethodWorker): def __init__(self, val_type): self._val_type = val_type -self._bufsize = int(512 / val_type.sizeof) or 1 +self._bufsize = 512 // val_type.sizeof or 1 def size(self, obj): first_node = obj['_M_impl']['_M_start']['_M_node'] @@ -176,7 +176,7 @@ class DequeWorkerBase(gdb.xmethod.XMethodWorker): def index(self, obj, idx): first_node = obj['_M_impl']['_M_start']['_M_node'] -index_node = first_node + int(idx / self._bufsize) +index_node = first_node + int(idx) // self._bufsize return index_node[0][idx % self._bufsize] class DequeEmptyWorker(DequeWorkerBase): @@ -419,7 +419,7 @@ class VectorWorkerBase(gdb.xmethod.XMethodWorker): if self._val_type.code == gdb.TYPE_CODE_BOOL: start = obj['_M_impl']['_M_start']['_M_p'] bit_size = start.dereference().type.sizeof * 8 -valp = start + int(index / bit_size) +valp = start + index // bit_size offset = index % bit_size return (valp.dereference() & (1 << offset)) > 0 else:
Re: [PATCH] libstdc++/77645 fix deque and vector xmethods for Python 3
On 19/09/16 21:39 +, Joseph Myers wrote: On Mon, 19 Sep 2016, Jonathan Wakely wrote: On 19/09/16 17:24 +, Joe Buck wrote: > Python has a distinct integer division operator, "//". 7 // 3 returns the > integer 2. Python 3 does, but Python 2 doesn't have it unless you import it from __future, and I don't know how far back that works. I don't want to introduce a fix for Python 3 that breaks it for old systems. No, // is available in Python, without needing __future__, from 2.2 onwards. I stand corrected, thanks both of you. I'll test and commnit this then. commit 07345154582af68b50866cbe9b90432f2d45 Author: Jonathan WakelyDate: Tue Sep 20 09:38:49 2016 +0100 Use python floored quotient operator in xmethods * python/libstdcxx/v6/xmethods.py (DequeWorkerBase.__init__) (DequeWorkerBase.index, VectorWorkerBase.get): Use // for division. diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py index 71a5b75..ed6a111 100644 --- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py +++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py @@ -165,7 +165,7 @@ class ArrayMethodsMatcher(gdb.xmethod.XMethodMatcher): class DequeWorkerBase(gdb.xmethod.XMethodWorker): def __init__(self, val_type): self._val_type = val_type -self._bufsize = int(512 / val_type.sizeof) or 1 +self._bufsize = 512 // val_type.sizeof or 1 def size(self, obj): first_node = obj['_M_impl']['_M_start']['_M_node'] @@ -176,7 +176,7 @@ class DequeWorkerBase(gdb.xmethod.XMethodWorker): def index(self, obj, idx): first_node = obj['_M_impl']['_M_start']['_M_node'] -index_node = first_node + int(idx / self._bufsize) +index_node = first_node + idx // self._bufsize return index_node[0][idx % self._bufsize] class DequeEmptyWorker(DequeWorkerBase): @@ -419,7 +419,7 @@ class VectorWorkerBase(gdb.xmethod.XMethodWorker): if self._val_type.code == gdb.TYPE_CODE_BOOL: start = obj['_M_impl']['_M_start']['_M_p'] bit_size = start.dereference().type.sizeof * 8 -valp = start + int(index / bit_size) +valp = start + index // bit_size offset = index % bit_size return (valp.dereference() & (1 << offset)) > 0 else:
Re: [PATCH] libstdc++/77645 fix deque and vector xmethods for Python 3
On Mon, 19 Sep 2016, Jonathan Wakely wrote: > On 19/09/16 17:24 +, Joe Buck wrote: > > Python has a distinct integer division operator, "//". 7 // 3 returns the > > integer 2. > > Python 3 does, but Python 2 doesn't have it unless you import it from > __future, and I don't know how far back that works. I don't want to > introduce a fix for Python 3 that breaks it for old systems. No, // is available in Python, without needing __future__, from 2.2 onwards. -- Joseph S. Myers jos...@codesourcery.com
Re: [PATCH] libstdc++/77645 fix deque and vector xmethods for Python 3
On 19/09/16 17:24 +, Joe Buck wrote: Python has a distinct integer division operator, "//". 7 // 3 returns the integer 2. Python 3 does, but Python 2 doesn't have it unless you import it from __future, and I don't know how far back that works. I don't want to introduce a fix for Python 3 that breaks it for old systems. Using a cast is clear and (AFAIK) works with all versions.
RE: [PATCH] libstdc++/77645 fix deque and vector xmethods for Python 3
Python has a distinct integer division operator, "//". 7 // 3 returns the integer 2. -Original Message- From: libstdc++-ow...@gcc.gnu.org [mailto:libstdc++-ow...@gcc.gnu.org] On Behalf Of Jonathan Wakely Sent: Monday, September 19, 2016 10:11 AM To: libstd...@gcc.gnu.org; gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++/77645 fix deque and vector xmethods for Python 3 The problem for these xmethods is that in Python 3 division of two integers produces a float, and GDB then doesn't allow that value to be used for pointer arithmetic (https://sourceware.org/PR20622). PR libstdc++/77645 * python/libstdcxx/v6/xmethods.py (DequeWorkerBase.__init__) (DequeWorkerBase.index, VectorWorkerBase.get): Cast results of division to int to work with Python 3. Tested x86_64-linux, committed to trunk. I'll fix it for gcc-5 and gcc-6 too.