Repository navigation
fix: raise SystemError when a key's C slot fails without an exception - #120
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
utils::pyobject_hashandutils::pyobject_equalassume an exception is set whenPyObject_Hashreturns -1 orPyObject_RichCompareBoolreturns a negative value:PyErr::take(py).unwrap()andPyErr::take(py).unwrap_unchecked(). A C type that reports an error without setting one breaks that assumption. It is a bug in that type, but with 6.2.9 it takes down the whole interpreter: the release profile haspanic = "abort", sounwrap()aborts (exit code 134), andunwrap_unchecked()onNoneis undefined behaviour (in practice PyO3 aborts with "PyErr state should never be invalid outside of normalization"). Adictgiven the same key raisesSystemError: ... returned NULL without setting an exceptionand goes on.This adds a small
take_error(py)that returns the pending exception or, if there is none,SystemError("error return without exception set"), and uses it at both call sites. I didn't usePyErr::fetch: in PyO3 0.30 it panics in debug builds and returnsSystemErroronly in release, so the result would depend on the build profile and the test below could not tell the fixed code from the old one in CI.Test
test_c_key_error_without_exception(intests/test_hashing.py, for every cache class) builds such a type withctypes+PyType_FromSpec— once with atp_hashreturning -1, once with atp_richcomparereturningNULL— in a child process, since the old code aborts, and expectsSystemError. Skipped on PyPy (noctypes.pythonapi).main(run): 14 failures on every CPython job (3.10–3.15, 3.14t, 3.15t, ubuntu, macos, windows), everything else passes.SystemErrorfor both cases where PyPI 6.2.9 aborts.