mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
gh-100637: Fix int and bool __sizeof__ calculation to include the 1 element ob_digit array for 0 and False (#100663)
Fixes behaviour where int (and subtypes like bool) __sizeof__ under-reports true size as it did not take into account the size 1 `ob_digit` array for the zero int. Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
This commit is contained in:
parent
9dee973166
commit
d7e7f79ca7
3 changed files with 7 additions and 2 deletions
|
@ -5879,7 +5879,10 @@ int___sizeof___impl(PyObject *self)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = offsetof(PyLongObject, ob_digit) + Py_ABS(Py_SIZE(self))*sizeof(digit);
|
||||
res = offsetof(PyLongObject, ob_digit)
|
||||
/* using Py_MAX(..., 1) because we always allocate space for at least
|
||||
one digit, even though the integer zero has a Py_SIZE of 0 */
|
||||
+ Py_MAX(Py_ABS(Py_SIZE(self)), 1)*sizeof(digit);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue