summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2011-04-06 06:41:42 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2011-04-06 06:41:42 (GMT)
commitbb4e470dcd0fa5cf52e3217dab55c353c8ae923f (patch)
tree3089d1ff2b1702a8bc6498e975687c5ae180f217
parent792eb5dc84b1a7d4652994ca970923bec0573614 (diff)
parent07019bcaab87114bc2312f2b916f929c99f3c48b (diff)
downloadcpython-bb4e470dcd0fa5cf52e3217dab55c353c8ae923f.zip
cpython-bb4e470dcd0fa5cf52e3217dab55c353c8ae923f.tar.gz
cpython-bb4e470dcd0fa5cf52e3217dab55c353c8ae923f.tar.bz2
hg pull/merge - Changes to accomodate.
-rw-r--r--Lib/test/test_datetime.py7
-rw-r--r--Modules/datetimemodule.c15
2 files changed, 15 insertions, 7 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 1a86353..d246d60 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -231,6 +231,13 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
eq(a//10, td(0, 7*24*360))
eq(a//3600000, td(0, 0, 7*24*1000))
+ # Issue #11576
+ eq(td(999999999, 86399, 999999) - td(999999999, 86399, 999998),
+ td(0, 0, 1))
+ eq(td(999999999, 1, 1) - td(999999999, 1, 0),
+ td(0, 0, 1))
+
+
def test_disallowed_computations(self):
a = timedelta(42)
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index f907093..f733fa1 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1737,13 +1737,14 @@ delta_subtract(PyObject *left, PyObject *right)
if (PyDelta_Check(left) && PyDelta_Check(right)) {
/* delta - delta */
- PyObject *minus_right = PyNumber_Negative(right);
- if (minus_right) {
- result = delta_add(left, minus_right);
- Py_DECREF(minus_right);
- }
- else
- result = NULL;
+ /* The C-level additions can't overflow because of the
+ * invariant bounds.
+ */
+ int days = GET_TD_DAYS(left) - GET_TD_DAYS(right);
+ int seconds = GET_TD_SECONDS(left) - GET_TD_SECONDS(right);
+ int microseconds = GET_TD_MICROSECONDS(left) -
+ GET_TD_MICROSECONDS(right);
+ result = new_delta(days, seconds, microseconds, 1);
}
if (result == Py_NotImplemented)