summaryrefslogtreecommitdiff
path: root/Objects/codeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-29 12:15:21 +0100
committerGitHub <noreply@github.com>2022-11-29 12:15:21 +0100
commit74d5f61ebd1cb14907bf7dae1ad9c1e676707bc5 (patch)
tree2ff77f8a0571edb5690e9e22209fb76e99a81560 /Objects/codeobject.c
parent4246fe977d850f8b78505c982f055d33d52ff339 (diff)
downloadcpython-git-74d5f61ebd1cb14907bf7dae1ad9c1e676707bc5.tar.gz
gh-99845: Clean up _PyObject_VAR_SIZE() usage (#99847)
* code_sizeof() now uses an unsigned type (size_t) to compute the result. * Fix _PyObject_ComputedDictPointer(): cast _PyObject_VAR_SIZE() to Py_ssize_t, rather than long: it's a different type on 64-bit Windows. * Clarify that _PyObject_VAR_SIZE() uses an unsigned type (size_t).
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r--Objects/codeobject.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index fc1db72977..f5d90cf65f 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -1867,15 +1867,13 @@ static PyGetSetDef code_getsetlist[] = {
static PyObject *
code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args))
{
- Py_ssize_t res = _PyObject_VAR_SIZE(Py_TYPE(co), Py_SIZE(co));
-
+ size_t res = _PyObject_VAR_SIZE(Py_TYPE(co), Py_SIZE(co));
_PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) co->co_extra;
if (co_extra != NULL) {
- res += sizeof(_PyCodeObjectExtra) +
- (co_extra->ce_size-1) * sizeof(co_extra->ce_extras[0]);
+ res += sizeof(_PyCodeObjectExtra);
+ res += ((size_t)co_extra->ce_size - 1) * sizeof(co_extra->ce_extras[0]);
}
-
- return PyLong_FromSsize_t(res);
+ return PyLong_FromSize_t(res);
}
static PyObject *