Skip to content

gh-126596: Use PyObject_VAR_HEAD for generator objects #126597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jbower-fb
Copy link
Contributor

@jbower-fb jbower-fb commented Nov 8, 2024

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

This looks pretty good, but this does need a NEWS entry, and I would like a simple test case to make sure that the size is actually working and doing the right thing.

Now, I'm not totally sure whether it's right to backport this. It might be a bug considering we use PyObject_GC_NewVar in the generator implementation, but at the same time, this very much feels like a feature (it wasn't necessarily documented as supported previously). I'll defer to Mark on whether to backport.

@jbower-fb
Copy link
Contributor Author

While thinking about adding a test I realized we actually no longer need a custom __sizeof__() implementation now as the value of ob_size should be accurate. So, I've removed that, and now the tests in test_sys.py should be sufficient to exercise the change. For good measure I've added an extra case to cover two differently sized generators.

Honestly, though this has left me even more puzzled as to whether this was intentional or not. It should be noted that this change will increase the size of all generator objects (e.g. by 8 bytes on x86-64 Linux systems). The addition of the custom __sizeof__() makes it looks like we were trying to avoid exposing the lack of correct ob_size, maybe to save the need for the storage? However, that only works for Python code, not users of the C-API.

@ZeroIntensity
Copy link
Member

No idea. @markshannon was who wrote it, I'll wait for his input.

@markshannon
Copy link
Member

See #126596 (comment)

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

Successfully merging this pull request may close these issues.

3 participants