mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-99845: Use size_t type in __sizeof__() methods (#99846)
The implementation of __sizeof__() methods using _PyObject_SIZE() now use an unsigned type (size_t) to compute the size, rather than a signed type (Py_ssize_t). Cast explicitly signed (Py_ssize_t) values to unsigned type (Py_ssize_t).
This commit is contained in:
parent
18a6967544
commit
85dd6cb6df
15 changed files with 85 additions and 108 deletions
|
@ -1508,15 +1508,13 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
|
|||
static PyObject *
|
||||
deque_sizeof(dequeobject *deque, void *unused)
|
||||
{
|
||||
Py_ssize_t res;
|
||||
Py_ssize_t blocks;
|
||||
|
||||
res = _PyObject_SIZE(Py_TYPE(deque));
|
||||
size_t res = _PyObject_SIZE(Py_TYPE(deque));
|
||||
size_t blocks;
|
||||
blocks = (size_t)(deque->leftindex + Py_SIZE(deque) + BLOCKLEN - 1) / BLOCKLEN;
|
||||
assert(deque->leftindex + Py_SIZE(deque) - 1 ==
|
||||
(blocks - 1) * BLOCKLEN + deque->rightindex);
|
||||
assert(((size_t)deque->leftindex + (size_t)Py_SIZE(deque) - 1) ==
|
||||
((blocks - 1) * BLOCKLEN + (size_t)deque->rightindex));
|
||||
res += blocks * sizeof(block);
|
||||
return PyLong_FromSsize_t(res);
|
||||
return PyLong_FromSize_t(res);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(sizeof_doc,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue