summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-06-03 21:06:45 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-06-03 21:06:45 (GMT)
commite63e5d60ee9173d1f0205e75f4cbdba67c5d66d4 (patch)
tree59d15ed1074aa5f5698ac871d317ba3f901065b2
parent11aaa42d1cc4011c3148641ea04316b58e000297 (diff)
downloadcpython-e63e5d60ee9173d1f0205e75f4cbdba67c5d66d4.zip
cpython-e63e5d60ee9173d1f0205e75f4cbdba67c5d66d4.tar.gz
cpython-e63e5d60ee9173d1f0205e75f4cbdba67c5d66d4.tar.bz2
Issue #27073: Removed redundant checks in long_add and long_sub.
Patch by Oren Milman.
-rw-r--r--Objects/longobject.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 14d2974..4732545 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -3022,8 +3022,14 @@ long_add(PyLongObject *a, PyLongObject *b)
if (Py_SIZE(a) < 0) {
if (Py_SIZE(b) < 0) {
z = x_add(a, b);
- if (z != NULL && Py_SIZE(z) != 0)
+ if (z != NULL) {
+ /* x_add received at least one multiple-digit int,
+ and thus z must be a multiple-digit int.
+ That also means z is not an element of
+ small_ints, so negating it in-place is safe. */
+ assert(Py_REFCNT(z) == 1);
Py_SIZE(z) = -(Py_SIZE(z));
+ }
}
else
z = x_sub(b, a);
@@ -3054,8 +3060,10 @@ long_sub(PyLongObject *a, PyLongObject *b)
z = x_sub(a, b);
else
z = x_add(a, b);
- if (z != NULL && Py_SIZE(z) != 0)
+ if (z != NULL) {
+ assert(Py_SIZE(z) == 0 || Py_REFCNT(z) == 1);
Py_SIZE(z) = -(Py_SIZE(z));
+ }
}
else {
if (Py_SIZE(b) < 0)