GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-99845: Clean up _PyObject_VAR_SIZE() usage by vstinner · Pull Request #99847 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Nov 28, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • 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).
  • Issue: PEP 670: Convert _PyObject_SIZE() and _PyObject_VAR_SIZE() macros to functions #99845

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
gh-99845: Clean up _PyObject_VAR_SIZE() usage
3ec8130
* 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).
@vstinner vstinner added the skip news label Nov 28, 2022
@vstinner
vstinner requested review from markshannon and pablogsal as code owners November 28, 2022 16:43
@bedevere-bot bedevere-bot mentioned this pull request Nov 28, 2022
PEP 670: Convert _PyObject_SIZE() and _PyObject_VAR_SIZE() macros to functions #99845
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Nov 28, 2022
@vstinner
vstinner merged commit 74d5f61 into python:main Nov 29, 2022
@vstinner
vstinner deleted the sizeof_var branch November 29, 2022 11:15
@bedevere-bot bedevere-bot removed the awaiting core review label Nov 29, 2022
serhiy-storchaka
serhiy-storchaka reviewed Nov 30, 2022
View reviewed changes
Comment thread Objects/object.c
}
size_t size = _PyObject_VAR_SIZE(tp, tsize);
assert(size <= (size_t)PY_SSIZE_T_MAX);
dictoffset += (Py_ssize_t)size;

@serhiy-storchaka serhiy-storchaka Nov 30, 2022

Copy link
Copy Markdown
Member

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.

It should be backported.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner

vstinner commented Dec 1, 2022

Copy link
Copy Markdown
Member Author

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).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Dec 1, 2022

Copy link
Copy Markdown
Member Author

I created PR #99922 to backport the cast fix to Python 3.11 (and 3.10).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner
@markshannon 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

Labels

skip news

Projects

None yet

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.

3 participants

@vstinner @serhiy-storchaka @bedevere-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.