summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-04-06 00:43:15 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-04-06 00:43:15 (GMT)
commit28deea1fa56379f88f3a726c8145ec893c2040d5 (patch)
treee3072b2836cb3ed82fad4c55df91d596d458952f /Modules
parent3bd9729dc92ad3fc57aee17479231eb426fd076f (diff)
parentb6f5ec737008f5c739ba3c667e1ae01b8625488b (diff)
downloadcpython-28deea1fa56379f88f3a726c8145ec893c2040d5.zip
cpython-28deea1fa56379f88f3a726c8145ec893c2040d5.tar.gz
cpython-28deea1fa56379f88f3a726c8145ec893c2040d5.tar.bz2
Issue #11576: Fixed timedelta subtraction glitch on big timedelta values
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_datetimemodule.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index f50cae0..a19c0c3 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1801,13 +1801,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)