summaryrefslogtreecommitdiffstats
path: root/Tools/gdb
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-03-22 14:49:51 (GMT)
committerGitHub <noreply@github.com>2023-03-22 14:49:51 (GMT)
commit7559f5fda94ab568a1a910b17683ed81dc3426fb (patch)
treea050bbc075372c6246fe3386560596f2283ae8bb /Tools/gdb
parent713df2c53489ce8012d0ede10b70950e6b0d8372 (diff)
downloadcpython-7559f5fda94ab568a1a910b17683ed81dc3426fb.zip
cpython-7559f5fda94ab568a1a910b17683ed81dc3426fb.tar.gz
cpython-7559f5fda94ab568a1a910b17683ed81dc3426fb.tar.bz2
GH-101291: Rearrange the size bits in PyLongObject (GH-102464)
* Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
Diffstat (limited to 'Tools/gdb')
-rwxr-xr-xTools/gdb/libpython.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py
index 56d6970..e38bd59 100755
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -882,10 +882,16 @@ class PyLongObjectPtr(PyObjectPtr):
def proxyval(self, visited):
'''
Python's Include/longobjrep.h has this declaration:
- struct _longobject {
- PyObject_VAR_HEAD
- digit ob_digit[1];
- };
+
+ typedef struct _PyLongValue {
+ uintptr_t lv_tag; /* Number of digits, sign and flags */
+ digit ob_digit[1];
+ } _PyLongValue;
+
+ struct _longobject {
+ PyObject_HEAD
+ _PyLongValue long_value;
+ };
with this description:
The absolute value of a number is equal to
@@ -897,11 +903,13 @@ class PyLongObjectPtr(PyObjectPtr):
#define PyLong_SHIFT 30
#define PyLong_SHIFT 15
'''
- ob_size = int(self.field('ob_size'))
- if ob_size == 0:
+ long_value = self.field('long_value')
+ lv_tag = int(long_value['lv_tag'])
+ size = lv_tag >> 3
+ if size == 0:
return 0
- ob_digit = self.field('long_value')['ob_digit']
+ ob_digit = long_value['ob_digit']
if gdb.lookup_type('digit').sizeof == 2:
SHIFT = 15
@@ -909,9 +917,9 @@ class PyLongObjectPtr(PyObjectPtr):
SHIFT = 30
digits = [int(ob_digit[i]) * 2**(SHIFT*i)
- for i in safe_range(abs(ob_size))]
+ for i in safe_range(size)]
result = sum(digits)
- if ob_size < 0:
+ if (lv_tag & 3) == 2:
result = -result
return result