This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dennis Sweeney
Recipients AlexWaygood, Dennis Sweeney, brandtbucher, steven.daprano
Date 2022-03-13.07:48:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1647157692.01.0.221349810161.issue46961@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-03-13 07:48:12Dennis Sweeneysetrecipients: + Dennis Sweeney, steven.daprano, brandtbucher, AlexWaygood
2022-03-13 07:48:12Dennis Sweeneysetmessageid: <1647157692.01.0.221349810161.issue46961@roundup.psfhosted.org>
2022-03-13 07:48:12Dennis Sweeneylinkissue46961 messages
2022-03-13 07:48:11Dennis Sweeneycreate