Dennis Sweeney <[email protected]> added the comment:
I believe the issue is the usage of the x_divrem function.
x_divrem always returns fresh ints, never cached small ints. This behavior is
relied upon in the long_true_divide function, as it mutates the returned
quotient at the line """x->ob_digit[0] = low & ~(2U*mask-1U);""".
The other uses of x_divrem account for this when handling the *quotient*, but
apparently missed checking for small ints in the *remainder*.
uses of x_divrem:
- long_divrem
- uses maybe_small_long on quotient
- doesn't check if remainder is small <---- oops
- long_rem
- throws away quotient
- doesn't check if remainder is small <---- oops
- long_true_divide
- modifies the quotient
- throws away remainder
Possible patches to fix it:
1) Modify long_divrem and long_rem to check for small remainders, in addition
to the small-quotient checks they already do.
2) Modify x_divrem to check for small remainders, but still always return fresh
quotients.
3) Modify x_divrem to return cached quotients and remainders, and modify
long_true_divide to make a copy before mutating.
I'd lean towards #1, since that quotient check already exists.
In #2, the mismatch of checking/not checking between quotient/remainder would
be confusing.
In #3, an extra int allocation gets added to integer true divide, which isn't
ideal.
----------
nosy: +Dennis Sweeney
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46961>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com