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.

Title: longobject.c: minor fixes, cleanups and optimizations
Type: behavior Stage: patch review
Components: Interpreter Core Versions: Python 3.1, Python 2.7
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: gregory.p.smith, mark.dickinson, pitrou
Priority: normal Keywords: patch

Created on 2009-02-14 17:44 by mark.dickinson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
trunk_long_cleanup.patch mark.dickinson, 2009-02-14 17:44
Messages (4)
msg82095 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-02-14 17:44
Here are various minor portability and standards-compliance fixes,
optimizations and cleanups for the trunk version of
Objects/longobject.c.  Most of these also apply to py3k.

I'll admit to an ulterior motive here:  the aim is to extract all
the trivial, non-behaviour-changing pieces of the 30-bit longdigit
patch (issue 4258), in order to make that patch easier to review.
A good few of the changes here are designed to weaken the assumptions
about the relative sizes of digit, int and long.

Detailed contents of this patch:

- make longs smaller by being more careful about tp_basicsize: it's
  defined as offsetof(PyLongObject, ob_digit) instead of the previous
  sizeof(PyLongObject) - sizeof(digit).  On average, this saves 2
  bytes per long on 32-bit platforms and 6 bytes per
  long on 64-bit platforms.  This is similar to the fix that's already
  in py3k, but more portable since it doesn't make assumptions about
  the amount of padding between the PyVarObject head and the long

- add overflow check in _PyLong_New

- replace double cast (double -> long -> digit) in PyLong_FromDouble
  with a single double -> digit cast.

- int -> Py_ssize_t fixes in _PyLong_FromByteArray.

- fix bogus overflow check in _PyLong_FromByteArray.

- inline muladd1 into mul1

- simplify long_hash (without changing its semantics in any way):
  there's no need for the masking when rotating x;  everything in
  sight is unsigned and unambiguous.

- make PyLong_MASK unsigned (of type digit);  this is safer, since
  it's used in many bitwise operations.

- remove wdigit from Include/longintrepr.h;  it's no longer used

- remove some unnecessary forward declarations

- add a few extra casts to silence compiler warnings from gcc -Wextra
msg82103 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-02-14 18:33
The patch looks good.
msg82113 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-02-14 19:11
agreed, looks good.  (and thats a good motive)
msg82149 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-02-15 11:06
Thanks, Antoine and Gregory!

Committed, r69634 and r69635.
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49510
2009-02-15 11:06:53mark.dickinsonsetstatus: open -> closed
resolution: accepted
messages: + msg82149
2009-02-14 19:11:47gregory.p.smithlinkissue4258 dependencies
2009-02-14 19:11:36gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg82113
2009-02-14 18:33:56pitrousetnosy: + pitrou
messages: + msg82103
2009-02-14 17:44:49mark.dickinsoncreate