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.

classification
Title: Clean up PyLong_FromLong and PyLong_FromLongLong
Type: Stage: resolved
Components: Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, mark.dickinson
Priority: normal Keywords: patch

Created on 2022-01-09 11:55 by mark.dickinson, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30496 merged mark.dickinson, 2022-01-09 11:56
Messages (2)
msg410141 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2022-01-09 11:55
PR GH-27832 inadvertently (I believe) introduced a couple of changes to PyLong_FromLong that didn't make a lot of sense: an (unsigned long) cast was replaced with (twodigits), and a digit count variable (counting number of PyLong digits in a C long) had its type needlessly changed from int to Py_ssize_t.

The first change is a potential portability bug, but only on platforms where the width of C's `long` exceeds 64 bits. The (unsigned long) cast is obviously correct, while figuring out whether (twodigits) loses information takes some work.

The second change is merely a potential pessimization: there's no need to use what's typically a 64-bit integer to count the number of PyLong digits in a long.

While fixing these, I've also reworked the PyLong_FromLong code a bit to move the medium int check earlier, and I've applied analogous changes to PyLong_FromLongLong.
msg414263 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-03-01 14:21
New changeset c60e6b6ad7aaf9c72035ff9fb1575e2710aeb4b4 by Mark Dickinson in branch 'main':
bpo-46311: Clean up PyLong_FromLong and PyLong_FromLongLong (GH-30496)
https://github.com/python/cpython/commit/c60e6b6ad7aaf9c72035ff9fb1575e2710aeb4b4
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90469
2022-03-04 14:39:02Mark.Shannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-03-01 14:21:15Mark.Shannonsetmessages: + msg414263
2022-01-09 11:56:03mark.dickinsonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28705
2022-01-09 11:55:44mark.dickinsoncreate