Skip to content
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

gh-117482: Fix Builtin Types Slot Wrappers #121602

Merged

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrently ericsnowcurrently commented Jul 10, 2024

When builtin static types are initialized for a subinterpreter, various "tp" slots have already been inherited (for the main interpreter). This was interfering with the logic in add_operators() (in Objects/typeobject.c), causing a wrapper to get created when it shouldn't. This changes fixes that by preserving the original data from the static type struct and checking that.

Lib/test/test_types.py Outdated Show resolved Hide resolved
@ericsnowcurrently ericsnowcurrently enabled auto-merge (squash) July 11, 2024 19:56
@ericsnowcurrently
Copy link
Member Author

FYI, I've dropped the code that restored the original static type struct values. It isn't necessary to fix this bug, except under multiple init/fini cycles, and can be done separately.

@ericsnowcurrently ericsnowcurrently added needs backport to 3.13 bugs and security fixes needs backport to 3.12 bug and security fixes labels Jul 11, 2024
@ericsnowcurrently ericsnowcurrently merged commit 5250a03 into python:main Jul 11, 2024
38 checks passed
@miss-islington-app
Copy link

Thanks @ericsnowcurrently for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 11, 2024
When builtin static types are initialized for a subinterpreter, various "tp" slots have already been inherited (for the main interpreter).  This was interfering with the logic in add_operators() (in Objects/typeobject.c), causing a wrapper to get created when it shouldn't.  This change fixes that by preserving the original data from the static type struct and checking that.
(cherry picked from commit 5250a03)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
@miss-islington-app
Copy link

Sorry, @ericsnowcurrently, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 5250a031332eb9499d5fc190d7287642e5a144b9 3.12

@bedevere-app
Copy link

bedevere-app bot commented Jul 11, 2024

GH-121630 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jul 11, 2024
@ericsnowcurrently ericsnowcurrently deleted the fix-builtin-slot-wrappers branch July 11, 2024 20:23
ericsnowcurrently added a commit that referenced this pull request Jul 11, 2024
When builtin static types are initialized for a subinterpreter, various "tp" slots have already been inherited (for the main interpreter).  This was interfering with the logic in add_operators() (in Objects/typeobject.c), causing a wrapper to get created when it shouldn't.  This change fixes that by preserving the original data from the static type struct and checking that.

(cherry picked from commit 5250a03, AKA gh-121602)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
ericsnowcurrently added a commit to ericsnowcurrently/cpython that referenced this pull request Jul 11, 2024
When builtin static types are initialized for a subinterpreter, various "tp" slots have already been inherited (for the main interpreter).  This was interfering with the logic in add_operators() (in Objects/typeobject.c), causing a wrapper to get created when it shouldn't.  This change fixes that by preserving the original data from the static type struct and checking that.
@bedevere-app
Copy link

bedevere-app bot commented Jul 11, 2024

GH-121632 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Jul 11, 2024
ericsnowcurrently added a commit that referenced this pull request Jul 11, 2024
When builtin static types are initialized for a subinterpreter, various "tp" slots have already been inherited (for the main interpreter).  This was interfering with the logic in add_operators() (in Objects/typeobject.c), causing a wrapper to get created when it shouldn't.  This change fixes that by preserving the original data from the static type struct and checking that.

(cherry picked from commit 5250a03, AKA gh-121602)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
@freakboy3742
Copy link
Contributor

@ericsnowcurrently I've narrowed down the failure on iOS reported as #121832 to this PR. It was masked by CI because it landed when the buildbots were in the process of being updated.

When debug is enabled, the assert(self->tp_version_tag != 0) check is failing during the test_types test - but only if you run the entire test suite. I'm trying to work out a narrower collection of tests that will generate the failure.

I'm not familiar with this section of the code; if you're able to shed any light on what is going on here (and in particular, what set of conditions might lead to tp_version_tag not being 0), that would be really helpful.

ericsnowcurrently added a commit to ericsnowcurrently/cpython that referenced this pull request Jul 16, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
When builtin static types are initialized for a subinterpreter, various "tp" slots have already been inherited (for the main interpreter).  This was interfering with the logic in add_operators() (in Objects/typeobject.c), causing a wrapper to get created when it shouldn't.  This change fixes that by preserving the original data from the static type struct and checking that.
ericsnowcurrently added a commit to ericsnowcurrently/cpython that referenced this pull request Jul 17, 2024
ericsnowcurrently added a commit that referenced this pull request Jul 24, 2024
…h-121932)

In gh-121602, I applied a fix to a builtin types initialization bug.
That fix made sense in the context of some broader future changes,
but introduced a little bit of extra complexity.  For earlier versions
those future changes are not relevant; we can avoid the extra complexity.
Thus we can revert that earlier change and replace it with this one,
which is more focused and conceptually simpler.  This is essentially
the implementation of an idea that @markshannon pointed out to me.

Note that this change would be much smaller if we didn't have to deal
with repr compatibility for builtin types that explicitly inherit tp slots
(see expect_manually_inherited()).  The alternative is to stop
*explicitly* inheriting tp slots in static PyTypeObject values,
which is churn that we can do separately.
ericsnowcurrently added a commit to ericsnowcurrently/cpython that referenced this pull request Jul 24, 2024
…ers (pythongh-121932)

In pythongh-121602, I applied a fix to a builtin types initialization bug.
That fix made sense in the context of some broader future changes,
but introduced a little bit of extra complexity.  For earlier versions
those future changes are not relevant; we can avoid the extra complexity.
Thus we can revert that earlier change and replace it with this one,
which is more focused and conceptually simpler.  This is essentially
the implementation of an idea that @markshannon pointed out to me.

Note that this change would be much smaller if we didn't have to deal
with repr compatibility for builtin types that explicitly inherit tp slots
(see expect_manually_inherited()).  The alternative is to stop
*explicitly* inheriting tp slots in static PyTypeObject values,
which is churn that we can do separately.

(cherry picked from commit 716c677, AKA pythongh-121932)
ericsnowcurrently added a commit that referenced this pull request Jul 24, 2024
…h-122241)

In gh-121602, I applied a fix to a builtin types initialization bug.
That fix made sense in the context of some broader future changes,
but introduced a little bit of extra complexity.  For earlier versions
those future changes are not relevant; we can avoid the extra complexity.
Thus we can revert that earlier change and replace it with this one,
which is more focused and conceptually simpler.  This is essentially
the implementation of an idea that @markshannon pointed out to me.

Note that this change would be much smaller if we didn't have to deal
with repr compatibility for builtin types that explicitly inherit tp slots
(see expect_manually_inherited()).  The alternative is to stop
*explicitly* inheriting tp slots in static PyTypeObject values,
which is churn that we can do separately.

(cherry picked from commit 716c677, AKA gh-121932)
encukou pushed a commit that referenced this pull request Sep 9, 2024
In gh-121602, I applied a fix to a builtin types initialization bug.
That fix made sense in the context of some broader future changes,
but introduced a little bit of extra complexity. That fix has turned
out to be incomplete for some of the builtin types we haven't
been testing. I found that out while improving the tests.

A while back, @markshannon suggested a simpler fix that doesn't
have that problem, which I've already applied to 3.12 and 3.13.
I'm switching to that here. Given the potential long-term
benefits of the more complex (but still incomplete) approach,
I'll circle back to it in the future, particularly after I've improved
the tests so no corner cases slip through the cracks.

(This is effectively a "forward-port" of 716c677 from 3.13.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants