Skip to content

gh-114828: parenthesize non-atomic macro definitions in pycore_symtable.h #115143

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

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

carljm
Copy link
Member

@carljm carljm commented Feb 7, 2024

In #115139, I used the expression ~DEF_FREE as a mask to clear the DEF_FREE bit in a symbol table entry.

Unfortunately, DEF_FREE is defined as #define DEF_FREE 2<<4, so this macro-expands to ~2<<4, and the bitwise negation binds more tightly than the bit-shift, so this actually meant (~2)<<4 rather than the ~(2<<4) which I intended.

This is why non-atomic macro bodies should always be parenthesized!

Fix it by parenthesizing all the non-atomic definitions in pycore_symtable.h, which not only fixes my ~DEF_FREE, but also prevents anyone else making the same mistake in future.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thanks for figuring this out!

@JelleZijlstra
Copy link
Member

It might be worth backporting this to 3.11, though there will be some conflicts and it's unlikely that we'll make a lot of changes to the 3.11 symtable at this point. Up to you.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks!

@carljm
Copy link
Member Author

carljm commented Feb 7, 2024

Hmm. I think my (weak) inclination is not to backport to 3.11, given that AFAIK there were major symtable changes in 3.12 but not in 3.11, so it seems unlikely we'll be backporting many changes to 3.11, and even less likely that any such changes would be affected by this. This PR is actually a bugfix for 3.12 (given that my ~DEF_FREE exists there), but for 3.11 it would be purely preventative. So I'd err on the side of being conservative with backports.

But like I say, this is a weak preference, and I'll happily backport to 3.11 if anyone feels strongly that that's the thing to do.

@carljm carljm merged commit 8f0998e into python:main Feb 7, 2024
@miss-islington-app
Copy link

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

@carljm carljm deleted the parmacros branch February 7, 2024 20:19
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 7, 2024
…symtable.h (pythonGH-115143)

(cherry picked from commit 8f0998e)

Co-authored-by: Carl Meyer <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Feb 7, 2024

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

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Feb 7, 2024
carljm added a commit that referenced this pull request Feb 7, 2024
…_symtable.h (GH-115143) (#115149)

gh-114828: parenthesize non-atomic macro definitions in pycore_symtable.h (GH-115143)
(cherry picked from commit 8f0998e)

Co-authored-by: Carl Meyer <[email protected]>
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
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.

3 participants