Visitar URL original
gh-99845: Use size_t type in __sizeof__() methods by vstinner · Pull Request #99846 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix compiler warnings in deque_sizeof()
  • Loading branch information
vstinner committed Nov 28, 2022
commit 1710a7d57c0061b5d53daa5db5289ce440a7365c
4 changes: 2 additions & 2 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1511,8 +1511,8 @@ deque_sizeof(dequeobject *deque, void *unused)
size_t res = _PyObject_SIZE(Py_TYPE(deque));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it need an explicit cast to size_t?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to limit this change only to prepare the code for _PyObject_SIZE() API change.

With commit 131801d, _PyObject_SIZE() return type is now well defined: it returns a size_t.

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_FromSize_t(res);
}
Expand Down