]> granicus.if.org Git - python/commitdiff
Rework delta_divmod to avoid use of PyTuple_SetItem.
authorMark Dickinson <dickinsm@gmail.com>
Tue, 20 Apr 2010 23:24:25 +0000 (23:24 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Tue, 20 Apr 2010 23:24:25 +0000 (23:24 +0000)
Modules/datetimemodule.c

index 6ff7eb3c0a27bb37ebaf1281c82258674fb3cb06..83dab2c93508b899c98325e68f94cbc028d8d707 100644 (file)
@@ -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