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-134786: Py_TPFLAGS_MANAGED_WEAKREF and Py_TPFLAGS_MANAGED_DICT must be used only if Py_TPFLAGS_HAVE_GC set by sergey-miryanov · Pull Request #135863 · python/cpython

Conversation

@sergey-miryanov

@sergey-miryanov sergey-miryanov commented Jun 23, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

According to discussion Py_TPFLAGS_MANAGED_WEAKREF and Py_TPFLAGS_MANAGED_DICT must be used only if Py_TPFLAGS_HAVE_GC is set.

  • Issue: Types with Py_TPFLAGS_MANAGED_WEAKREF but not Py_TPFLAGS_HAVE_GC crash when creating a weak reference #134786

📚 Documentation preview 📚: https://cpython-previews--135863.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

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

All reactions
@sergey-miryanov
Py_TPFLAGS_MANAGED_WEAKREF implies Py_TPFLAGS_HAVE_GC too and force c…
f7bf5f8
…hecking of it presence
@sergey-miryanov
sergey-miryanov requested a review from markshannon as a code owner June 23, 2025 20:51
@bedevere-app bedevere-app Bot added the awaiting review label Jun 23, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jun 23, 2025
Types with Py_TPFLAGS_MANAGED_WEAKREF but not Py_TPFLAGS_HAVE_GC crash when creating a weak reference #134786
Closed
sergey-miryanov added 2 commits June 24, 2025 13:13
@sergey-miryanov
Add news
dcca465
@sergey-miryanov
Update whatsnew
9e83c06
@sergey-miryanov

sergey-miryanov commented Jun 24, 2025

Copy link
Copy Markdown
Contributor Author

@markshannon Please take a look.

All reactions

Sorry, something went wrong.

Uh oh!

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

@chris-se

chris-se commented Jun 25, 2025

Copy link
Copy Markdown

As the person who reported #134786: I would suggest making the documentation more explicit and replacing should with must here, especially since the code now errors out if Py_TPFLAGS_HAVE_GC is not set.

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov
sergey-miryanov marked this pull request as draft July 26, 2025 18:47
@bedevere-app bedevere-app Bot removed the awaiting review label Jul 26, 2025
@Starbuck5

Starbuck5 commented Sep 20, 2025

Copy link
Copy Markdown

As the person who reported #134786: I would suggest making the documentation more explicit and replacing should with must here, especially since the code now errors out if Py_TPFLAGS_HAVE_GC is not set.

+1

Additionally, this PR puts this into a WhatsNew entry for 3.15. This is not a new thing, this is a documentation fix + fix for the runtime to not allow these invalid types to be created. So I think the added whatsnew is misleading.

All reactions

Sorry, something went wrong.

Uh oh!

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

sergey-miryanov added 3 commits September 25, 2025 23:46
@sergey-miryanov
Merge branch 'main' into pythongh-134786-managed-weakref
504f0af
@sergey-miryanov
Add support of weakrefs without gc
42c0932
@sergey-miryanov
Make FT happy
10fce20
sergey-miryanov
sergey-miryanov commented Sep 25, 2025
View reviewed changes
Comment thread Objects/typeobject.c Resolved

Uh oh!

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

sergey-miryanov added 3 commits September 26, 2025 00:32
@sergey-miryanov
Update docs according review's feedback
6dbabaf
@sergey-miryanov
Support Py_TPFLAGS_MANAGED_DICT without gc
7da03e2
@sergey-miryanov
Update news
f195b04
@sergey-miryanov

sergey-miryanov commented Sep 25, 2025

Copy link
Copy Markdown
Contributor Author

I'm not sure if we should support Py_TPFLAGS_MANAGED_DICT without Py_TPFLAGS_HAVE_GC, because Py_TPFLAGS_MANAGED_DICT implies Py_TPFLAGS_HAVE_GC. However, I have added it, though, to confirm that it is doable.

I think the current version needs some updates and clarification in the docs. First, though, I would like to get some feedback on the overall approach. Is this the right way to do after all?

Please take a look if someone interested.

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov
sergey-miryanov marked this pull request as ready for review September 25, 2025 19:42
@sergey-miryanov
sergey-miryanov requested a review from AA-Turner as a code owner September 25, 2025 19:42
@bedevere-app bedevere-app Bot added the awaiting review label Sep 25, 2025
@sergey-miryanov sergey-miryanov changed the title gh-134786: Py_TPFLAGS_MANAGED_WEAKREF implies Py_TPFLAGS_HAVE_GC too and force checking of its presence gh-134786: Allow use Py_TPFLAGS_MANAGED_WEAKREF without Py_TPFLAGS_HAVE_GC Sep 26, 2025
@sergey-miryanov sergey-miryanov changed the title gh-134786: Allow use Py_TPFLAGS_MANAGED_WEAKREF without Py_TPFLAGS_HAVE_GC gh-134786: Allow to use Py_TPFLAGS_MANAGED_WEAKREF without Py_TPFLAGS_HAVE_GC Sep 26, 2025
sergey-miryanov added 2 commits September 26, 2025 18:34
@sergey-miryanov
Revert last changes
f710627
@sergey-miryanov
Fix wording
3608747
@sergey-miryanov

sergey-miryanov commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

@markshannon Please take a look.

All reactions

Sorry, something went wrong.

Uh oh!

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

efimov-mikhail
efimov-mikhail reviewed Sep 26, 2025
View reviewed changes

@efimov-mikhail efimov-mikhail 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.

Maybe we should rename this PR?

Sorry, something went wrong.

Uh oh!

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

sergey-miryanov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

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

@sergey-miryanov

sergey-miryanov commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Maybe we should rename this PR?

I forgot to apply changes :(

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov sergey-miryanov changed the title gh-134786: Allow to use Py_TPFLAGS_MANAGED_WEAKREF without Py_TPFLAGS_HAVE_GC gh-134786: Py_TPFLAGS_MANAGED_WEAKREF and Py_TPFLAGS_MANAGED_DICT must be used only if Py_TPFLAGS_HAVE_GC set Sep 26, 2025
neonene
neonene reviewed Sep 27, 2025
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

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

sergey-miryanov added 2 commits September 27, 2025 13:49
@sergey-miryanov
Merge branch 'main' into pythongh-134786-managed-weakref
531bf38
@sergey-miryanov
Fix whatsnew section
c691449
@markshannon

markshannon commented Oct 22, 2025

Copy link
Copy Markdown
Member

Once the remaining comment has been addressed, I'm happy to merge this.

For the record, the requirements may change in the future:
For Py_TPFLAGS_MANAGED_DICT things are clear: Py_TPFLAGS_HAVE_GC must be set.
For Py_TPFLAGS_MANAGED_WEAKREF things are more complex. The current implementation requires that Py_TPFLAGS_HAVE_GC to be set, but there is no fundamental reason why the VM cannot manage the weakrefs of objects that cannot be part of cycles.

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov @efimov-mikhail
Update Doc/whatsnew/3.15.rst
86acf79
Co-authored-by: Mikhail Efimov <[email protected]>
@sergey-miryanov

sergey-miryanov commented Oct 22, 2025

Copy link
Copy Markdown
Contributor Author

For Py_TPFLAGS_MANAGED_WEAKREF things are more complex. The current implementation requires that Py_TPFLAGS_HAVE_GC to be set, but there is no fundamental reason why the VM cannot manage the weakrefs of objects that cannot be part of cycles.

I had such commit 42c0932, we decided to revert it for now. Maybe we should open a separate PR for it?

All reactions

Sorry, something went wrong.

Uh oh!

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

efimov-mikhail
efimov-mikhail approved these changes Oct 25, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting core review and removed awaiting review labels Oct 25, 2025
@kumaraditya303

kumaraditya303 commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

If it isn't too much work, it is worth adding a test for this.

All reactions

Sorry, something went wrong.

Uh oh!

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

sergey-miryanov added 2 commits October 28, 2025 22:12
@sergey-miryanov
Merge branch 'main' into pythongh-134786-managed-weakref
76e7aa7
@sergey-miryanov
Add tests
252c6bd
@sergey-miryanov

sergey-miryanov commented Oct 28, 2025

Copy link
Copy Markdown
Contributor Author

@kumaraditya303 I have added test.

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergey-miryanov

sergey-miryanov commented Oct 28, 2025

Copy link
Copy Markdown
Contributor Author

@markshannon @kumaraditya303 It is ready to review, could you please take a look.

All reactions

Sorry, something went wrong.

Uh oh!

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

efimov-mikhail
efimov-mikhail reviewed Oct 28, 2025
View reviewed changes
Comment thread Modules/_testcapimodule.c Resolved

Uh oh!

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

Comment thread Objects/typeobject.c Resolved

Uh oh!

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

@sergey-miryanov
Fix name for create_managed_weakref_nogc_type
1715eff
kumaraditya303
kumaraditya303 approved these changes Oct 29, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Oct 29, 2025
@kumaraditya303
kumaraditya303 merged commit da65f38 into python:main Nov 2, 2025
4 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Nov 2, 2025
@sergey-miryanov

sergey-miryanov commented Nov 2, 2025

Copy link
Copy Markdown
Contributor Author

Thanks all!

efimov-mikhail reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@sergey-miryanov @StanFromIreland
pythongh-134786: raise error if Py_TPFLAGS_MANAGED_WEAKREF or `Py_T…
c442821
…PFLAGS_MANAGED_DICT` is used without `Py_TPFLAGS_HAVE_GC` set (python#135863)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@efimov-mikhail efimov-mikhail efimov-mikhail approved these changes
@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
+1 more reviewer
@neonene neonene neonene left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

7 participants

@sergey-miryanov @chris-se @Starbuck5 @markshannon @kumaraditya303 @efimov-mikhail @neonene
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.