Repository navigation
gh-161387: Check the type of the decimal context ContextVar - #161399
Conversation
|
Addressed in c10e2e7: the error now reports the received type ( |
sobolevn
left a comment
There was a problem hiding this comment.
Please, assert that after the exception is handled: context var must not be cleared. Its value must not change
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: sobolevn <mail@sobolevn.me>
|
GH-161465 is a backport of this pull request to the 3.15 branch. |
|
GH-161466 is a backport of this pull request to the 3.14 branch. |
|
Refs gh-161387.
_decimal.current_context()returned whatever the internaldecimal_contextContextVarheld, without checkingPyDecContext_Check. Callers immediately cast the value toPyDecContextObject *, so setting the variable to a non-context (for example1) segfaults on the next decimal operation.Raise
TypeErrorfromcurrent_context()when the stored value is not a context.CURRENT_CONTEXTalready propagatesNULL, so callers fail cleanly.Tests: new
CContextAPItests.test_current_context_var_wrong_type. Built current main (5aa2f705) with the C_decimalextension (libmpdec 2.5.1): the reproducer exits with SIGSEGV (rc=139) before the change and raisesTypeErrorafter. The new test and the fulltest_decimalsuite (751 tests, 9 skipped) pass.