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

[3.9] bpo-43710: Change layout of pystate struct to preserve intra-version ABI compatibiliy. #25160

Closed

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Apr 3, 2021

This PR replaces the original (in 3.9.0)

    char overflowed;
    char recursion_critical;

with

    short recursion_headroom; 

restoring the ABI broken by #24501

Since recursion_headroom, overflowed, and recursion_critical all serve the same purpose, indicating that RecursionError should not be raised unless overflow become excessive, we can safely merge them.

I choose to use short recursion_headroom rather than using char recursion_headroom and leaving recursion_critical in place, so that assignments to recursion_critical in code compiled for 3.9.0 will be visible as changes to recursion_headroom.

The layout will be the same (at least for all compilers where sizeof(short) == sizeof(char)*2).

https://bugs.python.org/issue43710

@markshannon markshannon changed the title bpo-43710: Change layout of pystate struct to preserve intra-version ABI compatibiliy. [3.9] bpo-43710: Change layout of pystate struct to preserve intra-version ABI compatibiliy. Apr 3, 2021
@ambv ambv requested a review from vstinner April 3, 2021 17:46
Copy link
Contributor

@ambv ambv left a comment

Choose a reason for hiding this comment

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

LGTM. Sorry for missing the layout change in a public struct in #24501.

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

3.9 originally had int, char, char, int. #24501 replaced it with int, int, char, int, which was an ABI break. This PR is betting that int, short, int will restore the ABI. It sounds like a reasonable bet, unless we both have sizeof(short) != 2 * sizeof(char) and sizeof(short) > alignof(int).

@@ -69,10 +69,10 @@ PyAPI_FUNC(void) Py_LeaveRecursiveCall(void);

#define Py_ALLOW_RECURSION \
do { unsigned char _old = PyThreadState_GET()->recursion_critical;\
Copy link
Member

Choose a reason for hiding this comment

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

recursion_critical needs fixing up here too. Are you sure you grepped the whole codebase?

Copy link
Member

Choose a reason for hiding this comment

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

How did this even compile and pass CI?

Copy link
Member

Choose a reason for hiding this comment

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

I suppose this macro is only used in third-party code? Which of course makes wonder whether it still works as expected.

@bedevere-bot
Copy link

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!

@gpshead
Copy link
Member

gpshead commented Apr 4, 2021

PR 25179 is a simple revert of the offending change. I consider that a safer choice for a rushed 3.9.4 than attempting to fix a bugfix of a non-critical issue under time pressure. Up to ambv to decide.

@markshannon
Copy link
Member Author

I agree with @gpshead
Let's just revert the change.
The bug fix is in 3.10, and the risk of further breaking 3.9 isn't worth it for such a minor bug fix.

@markshannon markshannon closed this Apr 4, 2021
@markshannon markshannon deleted the binary-compat-recursion-check branch May 4, 2021 09:01
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.

6 participants