[New-bugs-announce] [issue46311] Clean up PyLong_FromLong and PyLong_FromLongLong
Mark Dickinson
report at bugs.python.org
Sun Jan 9 06:55:44 EST 2022
New submission from Mark Dickinson <dickinsm at gmail.com>:
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.
----------
messages: 410141
nosy: Mark.Shannon, mark.dickinson
priority: normal
severity: normal
status: open
title: Clean up PyLong_FromLong and PyLong_FromLongLong
versions: Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46311>
_______________________________________
More information about the New-bugs-announce
mailing list