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-101696: Make sure immutable types have a valid version tag by erlend-aasland · Pull Request #101742 · python/cpython

Conversation

@erlend-aasland

@erlend-aasland erlend-aasland commented Feb 9, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Reverts #101697

  • Issue: _PyStaticType_Dealloc does not invalidate type version tag #101696

Sorry, something went wrong.

Uh oh!

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

All reactions
@erlend-aasland
pythongh-101696: Make sure immutable types have a valid version tag
4c8dad0
@bedevere-bot bedevere-bot added the awaiting core review label Feb 9, 2023
@bedevere-bot bedevere-bot mentioned this pull request Feb 9, 2023
_PyStaticType_Dealloc does not invalidate type version tag #101696
Closed
@erlend-aasland

erlend-aasland commented Feb 9, 2023

Copy link
Copy Markdown
Contributor Author

cc. @markshannon @kumaraditya303

All reactions

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland
erlend-aasland requested a review from kumaraditya303 February 9, 2023 14:23
@erlend-aasland erlend-aasland added the skip news label Feb 9, 2023
@erlend-aasland

erlend-aasland commented Feb 9, 2023

Copy link
Copy Markdown
Contributor Author

I guess we can skip NEWS, as this is strictly internal.

All reactions

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland
erlend-aasland marked this pull request as ready for review February 9, 2023 17:13
@erlend-aasland
erlend-aasland requested a review from markshannon as a code owner February 9, 2023 17:13
@erlend-aasland
erlend-aasland requested review from ericsnowcurrently and removed request for markshannon February 9, 2023 17:14
@kumaraditya303

kumaraditya303 commented Feb 9, 2023

Copy link
Copy Markdown
Contributor

I'll review this by tomorrow.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

ericsnowcurrently
ericsnowcurrently requested changes Feb 9, 2023
View reviewed changes

@ericsnowcurrently ericsnowcurrently left a comment

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.

LGTM

FWIW, it would be nice if there were a test that covered the original problem from gh-101696 (i.e. fail without the fix and pass with it), whether by crashing or some other means. Would you mind adding something like that in this PR.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Objects/typeobject.c
Comment on lines +232 to +237
if (_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
CHECK(type->tp_version_tag != 0);
}
else {
CHECK(type->tp_version_tag == 0);
}

@ericsnowcurrently ericsnowcurrently Feb 9, 2023

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.

This check is worth adding, regardless of the rest of this PR, right?

Sorry, something went wrong.

Uh oh!

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

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@erlend-aasland erlend-aasland Feb 9, 2023

Copy link
Copy Markdown
Contributor Author

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.

Yes

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Objects/typeobject.c
Comment on lines +6979 to +6983
/* All immutable types must have a static valid version tag */
if (type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) {
type->tp_version_tag = next_version_tag++;
type->tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG;
}

@ericsnowcurrently ericsnowcurrently Feb 9, 2023

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.

tl;dr I'm on board with this.

As I mentioned in gh-101696, this is good as it covers non-builtin static types (AKA non-_Py_TPFLAGS_STATIC_BUILTIN), e.g. in community extension modules. 1 (The switch to Py_TPFLAGS_IMMUTABLETYPE seems fine.)

FWIW, the already merged fix may fit a little better with the vague idea (in my head) that we should be special-casing static types in the runtime as little as possible (or otherwise in more explicit ways, like the dedicated _PyStaticType_Dealloc()). In that spirit, rather than modifying PyType_Ready(), I was going to suggest we could find a way to apply _PyStaticType_Dealloc() to all static types, not just the builtin ones, which might be a good idea regardless. However, that feels like overkill for fixing this issue. Plus, we're already special-casing static types here in PyType_Ready(). (Perhaps my mental model is misaligned...)

Bottom line: dropping the original fix and adding the fix you have here is worth it since it handles non-builtin static types too.

Footnotes

  1. One could argue that non-builtin (non-core) static types should be discouraged (basically, they already are) and we shouldn't bother adding extra maintenance burden--however small--to accommodate them. However, that's not where the community is at nor will be for a long time and there's no reason to be so hard-line about it, especially in a case like this where the additional maintenance burden is essentially zero. ↩

Sorry, something went wrong.

Uh oh!

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

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@erlend-aasland erlend-aasland Feb 9, 2023

Copy link
Copy Markdown
Contributor Author

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.

Note that this PR does not special-case static types; the condition is for immutable types.

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting core review labels Feb 9, 2023
@bedevere-bot

bedevere-bot commented Feb 9, 2023

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

And if you don't make the requested changes, you will be put in the comfy chair!

All reactions

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland

erlend-aasland commented Feb 9, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

it would be nice if there were a test that covered the original problem from gh-101696 (i.e. fail without the fix and pass with it), whether by crashing or some other means. Would you mind adding something like that in this PR.

The original problem was uncovered by test_finalize_structseq in test_embed in gh-101304. Without Kumar's fix (d9de079), that particular test segfaulted. With Kumar's fix applied, the test passed; with Kumar's fix reverted and this PR applied, the test also passes.

I could of course try to add a more deterministic test. I'm not quite sure how to provoke that ATM, but I can look into it.

All reactions

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland erlend-aasland added the DO-NOT-MERGE label Feb 10, 2023
@erlend-aasland

erlend-aasland commented Feb 10, 2023

Copy link
Copy Markdown
Contributor Author

Closing, as per discussion on the issue.

All reactions

Sorry, something went wrong.

Uh oh!

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

@erlend-aasland erlend-aasland closed this Feb 10, 2023
@erlend-aasland
erlend-aasland deleted the versiontag branch February 10, 2023 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ericsnowcurrently ericsnowcurrently ericsnowcurrently requested changes
@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303

Uh oh!

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

Assignees

No one assigned

Labels

awaiting changes DO-NOT-MERGE 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.

4 participants

@erlend-aasland @kumaraditya303 @bedevere-bot @ericsnowcurrently
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.