GeezerVison is showing github.com — gh-99845: Clean up _PyObject_VAR_SIZE() usage by vstinner · Pull Request #99847 · python/cpython
Conversation
vstinner
commented
Nov 28, 2022
•
edited by bedevere-bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
- code_sizeof() now uses unsigned type to compute the result.
- Fix _PyObject_ComputedDictPointer(): cast _PyObject_VAR_SIZE() to Py_ssize_t, rather than long.
- Clarify that _PyObject_VAR_SIZE() uses an unsigned type (size_t).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
* code_sizeof() now uses unsigned type to compute the result.
* Fix _PyObject_ComputedDictPointer(): cast _PyObject_VAR_SIZE() to
Py_ssize_t, rather than long.
* Clarify that _PyObject_VAR_SIZE() uses an unsigned type (size_t).
|
|
}
|
|
|
size_t size = _PyObject_VAR_SIZE(tp, tsize);
|
|
|
assert(size <= (size_t)PY_SSIZE_T_MAX);
|
|
|
dictoffset += (Py_ssize_t)size;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
The dictoffset code was different in 2001 when the cast was added: commit 6d483d3
Change:
- dictoffset += size;
+ dictoffset += (long)size;
Code:
PyObject **
_PyObject_GetDictPtr(PyObject *obj)
{
long dictoffset;
...
if (dictoffset < 0) {
size_t size;
_PyObject_VAR_SIZE(size, tp, ((PyVarObject *)obj)->ob_size);
dictoffset += (long)size;
assert(dictoffset > 0);
assert(dictoffset % SIZEOF_VOID_P == 0);
}
...
}
The dictoffset type was changed in 2006 by commit 725507b without updating the cast, forgotten in the enhancement.
My change, replace (long) cast with (Py_ssize_t) only impact 64-bit Windows. On other platforms, long and Py_ssize_t should be the same type (either 32-bit or 64-bit signed integer, int32_t or int64_t).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I created PR #99922 to backport the cast fix to Python 3.11 (and 3.10).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
pablogsal
Awaiting requested review from pablogsal
pablogsal is a code owner
markshannon
Awaiting requested review from markshannon
markshannon is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.