diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2023-11-14 15:08:13 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2023-11-15 11:16:49 +0000 |
commit | 452476db0c705caeac8712d560fc16ced0ca5226 (patch) | |
tree | b6723b5a3b8f75cc29fb15d98ef46cf5c9ed3fc0 /libstdc++-v3/python | |
parent | cbd0fe22a5ced9751d2450dc4fd6fe3525c2fc02 (diff) | |
download | gcc-452476db0c705caeac8712d560fc16ced0ca5226.zip gcc-452476db0c705caeac8712d560fc16ced0ca5226.tar.gz gcc-452476db0c705caeac8712d560fc16ced0ca5226.tar.bz2 |
libstdc++: Fix std::deque::operator[] Xmethod [PR112491]
The Xmethod for std::deque::operator[] has the same bug that I recently
fixed for the std::deque::size() Xmethod. The first node might have
unused capacity at the start, which needs to be accounted for when
indexing into the deque.
libstdc++-v3/ChangeLog:
PR libstdc++/112491
* python/libstdcxx/v6/xmethods.py (DequeWorkerBase.index):
Correctly handle unused capacity at the start of the first node.
* testsuite/libstdc++-xmethods/deque.cc: Check index operator
when elements have been removed from the front.
Diffstat (limited to 'libstdc++-v3/python')
-rw-r--r-- | libstdc++-v3/python/libstdcxx/v6/xmethods.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py index dcef285..f29bc2d 100644 --- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py +++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py @@ -195,7 +195,7 @@ class DequeWorkerBase(gdb.xmethod.XMethodWorker): def size(self, obj): start = obj['_M_impl']['_M_start'] finish = obj['_M_impl']['_M_finish'] - if not start['_M_node']: + if start['_M_cur'] == finish['_M_cur']: return 0 return (self._bufsize * (finish['_M_node'] - start['_M_node'] - 1) @@ -203,9 +203,13 @@ class DequeWorkerBase(gdb.xmethod.XMethodWorker): + (start['_M_last'] - start['_M_cur'])) def index(self, obj, idx): - first_node = obj['_M_impl']['_M_start']['_M_node'] - index_node = first_node + int(idx) // self._bufsize - return index_node[0][idx % self._bufsize] + start = obj['_M_impl']['_M_start'] + first_node_size = start['_M_last'] - start['_M_cur'] + if idx < first_node_size: + return start['_M_cur'][idx] + idx = idx - first_node_size + index_node = start['_M_node'][1 + int(idx) // self._bufsize] + return index_node[idx % self._bufsize] class DequeEmptyWorker(DequeWorkerBase): |