Skip to content

gh-148268: Avoid debug assertion in specialized list compares#148309

Open
officialasishkumar wants to merge 1 commit intopython:mainfrom
officialasishkumar:gh-148268-list-sort-debug-assert
Open

gh-148268: Avoid debug assertion in specialized list compares#148309
officialasishkumar wants to merge 1 commit intopython:mainfrom
officialasishkumar:gh-148268-list-sort-debug-assert

Conversation

@officialasishkumar
Copy link
Copy Markdown

Handle recursion errors raised by the debug-only cross-check in the specialized latin, compact-int, and float comparison helpers used by list sorting. When that verification path hits the C stack overflow guard, clear the resulting exception so the optimized comparison remains side-effect free.

I did not add a targeted regression test because the failure is in a debug-only verification path that is only triggered when the extra PyObject_RichCompareBool() call hits the C stack guard; I could not produce a stable Python-level reproducer for that condition.

Tests:

  • ./python -m test -j1 test_sort test_richcmp

Handle recursion errors raised by the debug-only cross-check in the specialized latin, compact-int, and float comparison helpers used by list sorting. When the verification path hits the C stack overflow guard, clear that exception so the optimized comparison remains side-effect free.\n\nThe change preserves the consistency assertion when the fallback comparison succeeds and adds a NEWS entry for the fix.
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Apr 9, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

Copy link
Copy Markdown
Member

@tim-one tim-one left a comment

Choose a reason for hiding this comment

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

Looks good! Ship it 😄

@StanFromIreland
Copy link
Copy Markdown
Member

@officialasishkumar you'll need to sign the CLA, see #148309 (comment).

@officialasishkumar
Copy link
Copy Markdown
Author

Done

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