summaryrefslogtreecommitdiff
path: root/Modules/_datetimemodule.c
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-04-05 20:43:15 -0400
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2011-04-05 20:43:15 -0400
commitb02488d6df14a0cc39520c8ea7d9afa53c5b9eca (patch)
tree366204659ac83f2c4d5e9d2e0036dc6036ea00d8 /Modules/_datetimemodule.c
parent1292d5100f2b4d92c52900f90e2eeb050ef36eaa (diff)
parent4a4e378e8d1f260c57a090ea743ed868e286414f (diff)
downloadcpython-b02488d6df14a0cc39520c8ea7d9afa53c5b9eca.tar.gz
Issue #11576: Fixed timedelta subtraction glitch on big timedelta values
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r--Modules/_datetimemodule.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index f50cae0bd8..a19c0c355b 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)