mirror of
https://github.com/python/cpython.git
synced 2025-12-10 02:50:09 +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
|
|
@ -2484,11 +2484,9 @@ product_dealloc(productobject *lz)
|
|||
static PyObject *
|
||||
product_sizeof(productobject *lz, void *unused)
|
||||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = _PyObject_SIZE(Py_TYPE(lz));
|
||||
res += PyTuple_GET_SIZE(lz->pools) * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSsize_t(res);
|
||||
size_t res = _PyObject_SIZE(Py_TYPE(lz));
|
||||
res += (size_t)PyTuple_GET_SIZE(lz->pools) * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSize_t(res);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(sizeof_doc, "Returns size in memory, in bytes.");
|
||||
|
|
@ -2817,11 +2815,9 @@ combinations_dealloc(combinationsobject *co)
|
|||
static PyObject *
|
||||
combinations_sizeof(combinationsobject *co, void *unused)
|
||||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = _PyObject_SIZE(Py_TYPE(co));
|
||||
res += co->r * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSsize_t(res);
|
||||
size_t res = _PyObject_SIZE(Py_TYPE(co));
|
||||
res += (size_t)co->r * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSize_t(res);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -3153,11 +3149,9 @@ cwr_dealloc(cwrobject *co)
|
|||
static PyObject *
|
||||
cwr_sizeof(cwrobject *co, void *unused)
|
||||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = _PyObject_SIZE(Py_TYPE(co));
|
||||
res += co->r * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSsize_t(res);
|
||||
size_t res = _PyObject_SIZE(Py_TYPE(co));
|
||||
res += (size_t)co->r * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSize_t(res);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -3498,12 +3492,10 @@ permutations_dealloc(permutationsobject *po)
|
|||
static PyObject *
|
||||
permutations_sizeof(permutationsobject *po, void *unused)
|
||||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = _PyObject_SIZE(Py_TYPE(po));
|
||||
res += PyTuple_GET_SIZE(po->pool) * sizeof(Py_ssize_t);
|
||||
res += po->r * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSsize_t(res);
|
||||
size_t res = _PyObject_SIZE(Py_TYPE(po));
|
||||
res += (size_t)PyTuple_GET_SIZE(po->pool) * sizeof(Py_ssize_t);
|
||||
res += (size_t)po->r * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSize_t(res);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue