Message265989
------------ the proposed changes ------------
I believe the following checks are redundant:
1. in Objects/longobject.c in long_add:
In case both a and b are negative, their absolute values are added using x_add, with the result stored in z.
If (z != NULL), it must be that x_add succeeded, and also it must be that (Py_SIZE(z) > 0), as it is guaranteed that the absolute values of a and b are both bigger than zero.
Thus, the check (Py_SIZE(z) != 0) here is redundant.
2. in Objects/longobject.c in long_sub:
In case a is negative, the absolute values of a and b are subtracted or added using x_sub or x_add, with the result stored in z.
Later on, if (z != NULL && Py_SIZE(z) != 0), then Py_SIZE(z) is negated. However, even though it might be that Py_SIZE(z) == 0, it doesn't really matter.
doing 'Py_SIZE(z) = -(Py_SIZE(z));' in that case would do nothing.
Thus, the check (Py_SIZE(z) != 0) here is redundant.
The original versions of both of these checks were added in revision 443 (November 1991!). Back then, ob_size's was implemented using one's complement, and negating it was actually doing 'z->ob_size = ~z->ob_size;'.
Of course, in that case the check (z->ob_size != 0) was necessary, but then, in revision 590, ob_size was changed to use two's complement, and the check (z->ob_size != 0) was left untouched, and remained there to this day.
------------ diff ------------
The patches diff 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 -m test' (on my 64-bit Windows 10) before and after applying the patch, and got quite the same output.
the outputs of both runs are attached. |
|
Date |
User |
Action |
Args |
2016-05-21 07:41:40 | Oren Milman | set | recipients:
+ Oren Milman |
2016-05-21 07:41:40 | Oren Milman | set | messageid: <1463816500.87.0.013124059613.issue27073@psf.upfronthosting.co.za> |
2016-05-21 07:41:40 | Oren Milman | link | issue27073 messages |
2016-05-21 07:41:40 | Oren Milman | create | |
|