Skip to content

gh-139716: StackRef tests are added - #139717

Open
efimov-mikhail wants to merge 32 commits into
python:mainfrom
efimov-mikhail:stackref_tests
Open

gh-139716: StackRef tests are added#139717
efimov-mikhail wants to merge 32 commits into
python:mainfrom
efimov-mikhail:stackref_tests

Conversation

@efimov-mikhail

@efimov-mikhailefimov-mikhail commented Oct 7, 2025

Copy link
Copy Markdown
Member

New test file Lib/test/test_stackrefs.py introduced.
Some auxillary functions are added to _testinternalcapi.
Those functions are examples of correct StackRef scenarios.
We check that all refcounts remain correct.
And that results are the same for equivalent scenarios.

@bedevere-appbedevere-appBot added tests Tests in the Lib/test dir awaiting review labels Oct 7, 2025
@efimov-mikhail

Copy link
Copy Markdown
MemberAuthor

@efimov-mikhailefimov-mikhail mentioned this pull request Oct 7, 2025
Comment threadLib/test/test_stackrefs.py

@markshannonmarkshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. I've one concern about code organization, but that's all.

Comment threadModules/_testinternalcapi.c Outdated
@bedevere-app

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@efimov-mikhail

Copy link
Copy Markdown
MemberAuthor

I have made the requested changes; please review again.

@bedevere-app

Copy link
Copy Markdown

Thanks for making the requested changes!

@markshannon: please review the changes made to this pull request.

@efimov-mikhail
efimov-mikhail marked this pull request as draft October 27, 2025 19:05
@efimov-mikhail
efimov-mikhail marked this pull request as ready for review October 27, 2025 19:05
@efimov-mikhail

Copy link
Copy Markdown
MemberAuthor

Friendly ping, @markshannon@Fidget-Spinner .
Maybe I should make another change to this PR?

@Fidget-SpinnerFidget-Spinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just two questions

Comment threadInclude/internal/pycore_stackref.h Outdated
Comment threadLib/test/test_stackrefs.py Outdated
Comment threadInclude/internal/pycore_stackref.h Outdated
_PyStackRef_AsTuple(_PyStackRef ref, PyObject *op)
{
// Do not check StackRef flags in the free threading build.
return Py_BuildValue("(ni)", Py_REFCNT(op), -1);

@efimov-mikhailefimov-mikhailNov 17, 2025

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Actually, I've realized that we could remove this special case.
It's related only to stackrefs for immortal objects at ft build.

We can make a little change for _PyStackRef_FromPyObjectSteal and for PyStackRef_FromPyObjectNew function: add Py_TAG_DEFERRED flag to references on immortal objects.
All tests passed with this change on my machine.
But I suggest doing this in the next small PR, and keep only tests changes here.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I've created a #141675 for this change.

Comment threadLib/test/test_stackrefs.py
Comment threadModules/_testinternalcapi.c
Comment threadModules/_testinternalcapi.c Outdated
Comment threadLib/test/test_stackrefs.py Outdated
Comment threadModules/_testinternalcapi.c Outdated
Comment threadModules/_testinternalcapi.c Outdated

@sergey-miryanovsergey-miryanov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@efimov-mikhail

Copy link
Copy Markdown
MemberAuthor

CC @markshannon@Fidget-Spinner@colesbury
Could we merge this?

Another option is merge #143024 first and adapt tests for that change here.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label Apr 30, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewskip newsstaleStale PR or inactive for long period of time.testsTests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@efimov-mikhail@sergey-miryanov@markshannon@Fidget-Spinner@StanFromIreland@nazeerali4325-commits