summaryrefslogtreecommitdiffstats
path: root/Modules/datetimemodule.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-04-20 23:24:25 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-04-20 23:24:25 (GMT)
commita03e53482c39f0b85d852d0b62db3c60d04314f0 (patch)
tree3d06b0d39b01eeb254f4bda1d85355bdb476adc2 /Modules/datetimemodule.c
parent56a60878264ec73f0c65501a4e9d1187cec803bd (diff)
downloadcpython-a03e53482c39f0b85d852d0b62db3c60d04314f0.zip
cpython-a03e53482c39f0b85d852d0b62db3c60d04314f0.tar.gz
cpython-a03e53482c39f0b85d852d0b62db3c60d04314f0.tar.bz2
Rework delta_divmod to avoid use of PyTuple_SetItem.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r--Modules/datetimemodule.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 6ff7eb3..83dab2c 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1927,7 +1927,8 @@ delta_divmod(PyObject *left, PyObject *right)
PyObject *pyus_left;
PyObject *pyus_right;
PyObject *divmod;
- PyObject *microseconds, *delta;
+ PyObject *delta;
+ PyObject *result;
if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
Py_INCREF(Py_NotImplemented);
@@ -1950,14 +1951,16 @@ delta_divmod(PyObject *left, PyObject *right)
if (divmod == NULL)
return NULL;
- microseconds = PyTuple_GetItem(divmod, 1);
- delta = microseconds_to_delta(microseconds);
+ assert(PyTuple_Size(divmod) == 2);
+ delta = microseconds_to_delta(PyTuple_GET_ITEM(divmod, 1));
if (delta == NULL) {
Py_DECREF(divmod);
return NULL;
}
- PyTuple_SetItem(divmod, 1, delta);
- return divmod;
+ result = PyTuple_Pack(2, PyTuple_GET_ITEM(divmod, 0), delta);
+ Py_DECREF(delta);
+ Py_DECREF(divmod);
+ return result;
}
/* Fold in the value of the tag ("seconds", "weeks", etc) component of a