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:
Victor Stinner 2022-11-30 17:22:52 +01:00 committed by GitHub
parent 18a6967544
commit 85dd6cb6df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 85 additions and 108 deletions

View file

@ -804,12 +804,11 @@ mmap__repr__method(PyObject *self)
static PyObject *
mmap__sizeof__method(mmap_object *self, void *unused)
{
Py_ssize_t res;
res = _PyObject_SIZE(Py_TYPE(self));
if (self->tagname)
size_t res = _PyObject_SIZE(Py_TYPE(self));
if (self->tagname) {
res += strlen(self->tagname) + 1;
return PyLong_FromSsize_t(res);
}
return PyLong_FromSize_t(res);
}
#endif