aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/python
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2023-11-14 15:08:13 +0000
committerJonathan Wakely <jwakely@redhat.com>2023-11-14 15:55:03 +0000
commit4db820928065eccbeb725406450d826186582b9f (patch)
tree55ec98541bfc20cacd745ada48856d24a75ad6a6 /libstdc++-v3/python
parent8f331be42991aa4d58ac770faf993accfcce882b (diff)
downloadgcc-4db820928065eccbeb725406450d826186582b9f.zip
gcc-4db820928065eccbeb725406450d826186582b9f.tar.gz
gcc-4db820928065eccbeb725406450d826186582b9f.tar.bz2
libstdc++: Fix std::deque::size() Xmethod [PR112491]
The Xmethod for std::deque::size() assumed that the first element would be at the start of the first node. That's only true if elements are only added at the back. If an element is inserted at the front, or removed from the front (or anywhere before the middle) then the first node will not be completely populated, and the Xmethod will give the wrong result. libstdc++-v3/ChangeLog: PR libstdc++/112491 * python/libstdcxx/v6/xmethods.py (DequeWorkerBase.size): Fix calculation to use _M_start._M_cur. * testsuite/libstdc++-xmethods/deque.cc: Check failing cases.
Diffstat (limited to 'libstdc++-v3/python')
-rw-r--r--libstdc++-v3/python/libstdcxx/v6/xmethods.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
index 42e60eb..dcef285 100644
--- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py
+++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
@@ -193,11 +193,14 @@ class DequeWorkerBase(gdb.xmethod.XMethodWorker):
self._bufsize = 512 // val_type.sizeof or 1
def size(self, obj):
- first_node = obj['_M_impl']['_M_start']['_M_node']
- last_node = obj['_M_impl']['_M_finish']['_M_node']
- cur = obj['_M_impl']['_M_finish']['_M_cur']
- first = obj['_M_impl']['_M_finish']['_M_first']
- return (last_node - first_node) * self._bufsize + (cur - first)
+ start = obj['_M_impl']['_M_start']
+ finish = obj['_M_impl']['_M_finish']
+ if not start['_M_node']:
+ return 0
+ return (self._bufsize
+ * (finish['_M_node'] - start['_M_node'] - 1)
+ + (finish['_M_cur'] - finish['_M_first'])
+ + (start['_M_last'] - start['_M_cur']))
def index(self, obj, idx):
first_node = obj['_M_impl']['_M_start']['_M_node']