Author Oren Milman
Recipients Oren Milman
Date 2016-07-02.14:38:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1467470337.8.0.776341442151.issue27441@psf.upfronthosting.co.za>
In-reply-to
Content
------------ current state ------------
In six different functions, the following happens:
    1. Function x calls _PyLong_New, with var y as the size argument.
        * Among others, _PyLong_New sets the ob_size of the new int to y (the size argument it received).
    2. Function x sets the ob_size of the new int to y, even though y is already the value of ob_size.

The functions in which this happens are:
    1. in Objects/longobject.c:
        - PyLong_FromUnsignedLong
        - PyLong_FromLongLong
        - PyLong_FromUnsignedLongLong
        - PyLong_FromSsize_t
        - PyLong_FromSize_t
    2. in Python/marshal.c:
        - r_PyLong

With regard to relevant changes made in the past, it seems that the redundant assignment was added (in each of these six functions) on the last major rewriting of the function, or when the function was first added, and remained there to this day.

The revisions in which the redundant assignments were added:
    1. changeset 18114 (https://hg.python.org/cpython/rev/31cd0db0f09f):
        - PyLong_FromUnsignedLong
    2. changeset 38307 (https://hg.python.org/cpython/rev/5a63369056a7):
        - PyLong_FromLongLong
        - PyLong_FromUnsignedLongLong
    3. changeset 46460 (https://hg.python.org/cpython/rev/b04f2052e812):
        - PyLong_FromSize_t
        - PyLong_FromSsize_t
    4. changeset 52215 (https://hg.python.org/cpython/rev/bb5de24a343f):
        - r_PyLong


------------ proposed changes ------------
Remove these six redundant assignments.


------------ diff ------------
The proposed patches diff file is attached.


------------ tests ------------
I built the patched CPython for x86, and played with it a little. Everything seemed to work as usual. 

In addition, I ran 'python_d.exe -m test -j3' (on my 64-bit Windows 10) with and without the patches, and got quite the same output.
The outputs of both runs are attached.
History
Date User Action Args
2016-07-02 14:39:01Oren Milmansetrecipients: + Oren Milman
2016-07-02 14:38:57Oren Milmansetmessageid: <1467470337.8.0.776341442151.issue27441@psf.upfronthosting.co.za>
2016-07-02 14:38:57Oren Milmanlinkissue27441 messages
2016-07-02 14:38:57Oren Milmancreate