Skip to content

gh-134768: Fix definition of mt_continue_should_break() #134769

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
May 30, 2025

Conversation

thesamesam
Copy link
Contributor

@thesamesam thesamesam commented May 27, 2025

In 121ed71, mt_continue_should_break was changed to be guarded by Py_DEBUG, but it's used in compress_mt_continue_lock_held with just assert, so it needs to be available when NDEBUG is undefined too.

Py_DEBUG implies NDEBUG is undefined, so we can check just that.

Fixes: 121ed71

In 121ed71, mt_continue_should_break
was changed to be guarded by `Py_DEBUG`, but it's used in `compress_mt_continue_lock_held`
with just `assert`, so it needs to be available when `NDEBUG` is undefined
too.

`Py_DEBUG` implies `NDEBUG` is undefined, so we can check just that.

Fixes: 121ed71
@emmatyping
Copy link
Member

emmatyping commented May 27, 2025

Just verifying my understanding, because "NDEBUG" is rather confusingly named it seems: the failure case is you compile in debug (not --enable-optimizations) which defines Py_DEBUG, but also enable assertions via --enable-assertions (which defines NDEBUG)?

@emmatyping emmatyping requested a review from erlend-aasland May 27, 2025 02:54
@mgorny
Copy link
Contributor

mgorny commented May 27, 2025

No. The failure is that you compile regular (which doesn't set Py_DEBUG) but also --with-assertions (which implies -UNDEBUG).

@thesamesam
Copy link
Contributor Author

thesamesam commented May 27, 2025

Other way around:

  • --with-pydebug (Py_DEBUG) => -UNDEBUG -DPy_DEBUG -> -DPy_DEBUG (works on main)
  • --with-assertions (-UNDEBUG) => nothing (needs this PR because assert is not compiled out)
  • nothing (-DNDEBUG) => -DNDEBUG (works on main, because the assert is compiled out)

It's really stupid and it's to do with how assert is defined. By default, assert does something. If NDEBUG is defined, it doesn't. It's very common to set NDEBUG for performance and CPython does that unless you pass --with-assertions.

Copy link
Member

@emmatyping emmatyping left a comment

Choose a reason for hiding this comment

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

Okay, makes sense, thanks for the explanations

@mgorny
Copy link
Contributor

mgorny commented May 29, 2025

Could we merge this, please? It just bit me again as I was about to recheck a failing assertion on main.

@gpshead gpshead enabled auto-merge (squash) May 30, 2025 04:42
@gpshead gpshead merged commit 2f2bee2 into python:main May 30, 2025
52 checks passed
@miss-islington-app
Copy link

Thanks @thesamesam for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 30, 2025
…onGH-134769)

In 121ed71, mt_continue_should_break
was changed to be guarded by `Py_DEBUG`, but it's used in `compress_mt_continue_lock_held`
with just `assert`, so it needs to be available when `NDEBUG` is undefined
too.

`Py_DEBUG` implies `NDEBUG` is undefined, so we can check just that.
(cherry picked from commit 2f2bee2)

Co-authored-by: Sam James <[email protected]>
Fixes: 121ed71
@bedevere-app
Copy link

bedevere-app bot commented May 30, 2025

GH-134916 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 30, 2025
@thesamesam thesamesam deleted the py-assertions-vs-zstd branch May 30, 2025 05:02
gpshead pushed a commit that referenced this pull request May 30, 2025
…134769) (#134916)

gh-134768: Fix definition of `mt_continue_should_break()` (GH-134769)

In 121ed71, mt_continue_should_break
was changed to be guarded by `Py_DEBUG`, but it's used in `compress_mt_continue_lock_held`
with just `assert`, so it needs to be available when `NDEBUG` is undefined
too.

`Py_DEBUG` implies `NDEBUG` is undefined, so we can check just that.
(cherry picked from commit 2f2bee2)


Fixes: 121ed71

Co-authored-by: Sam James <[email protected]>
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.

4 participants