Rework delta_divmod to avoid use of PyTuple_SetItem.
This commit is contained in:
parent
56a6087826
commit
a03e53482c
@ -1927,7 +1927,8 @@ delta_divmod(PyObject *left, PyObject *right)
|
|||||||
PyObject *pyus_left;
|
PyObject *pyus_left;
|
||||||
PyObject *pyus_right;
|
PyObject *pyus_right;
|
||||||
PyObject *divmod;
|
PyObject *divmod;
|
||||||
PyObject *microseconds, *delta;
|
PyObject *delta;
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
|
if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
|
||||||
Py_INCREF(Py_NotImplemented);
|
Py_INCREF(Py_NotImplemented);
|
||||||
@ -1950,14 +1951,16 @@ delta_divmod(PyObject *left, PyObject *right)
|
|||||||
if (divmod == NULL)
|
if (divmod == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
microseconds = PyTuple_GetItem(divmod, 1);
|
assert(PyTuple_Size(divmod) == 2);
|
||||||
delta = microseconds_to_delta(microseconds);
|
delta = microseconds_to_delta(PyTuple_GET_ITEM(divmod, 1));
|
||||||
if (delta == NULL) {
|
if (delta == NULL) {
|
||||||
Py_DECREF(divmod);
|
Py_DECREF(divmod);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyTuple_SetItem(divmod, 1, delta);
|
result = PyTuple_Pack(2, PyTuple_GET_ITEM(divmod, 0), delta);
|
||||||
return divmod;
|
Py_DECREF(delta);
|
||||||
|
Py_DECREF(divmod);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fold in the value of the tag ("seconds", "weeks", etc) component of a
|
/* Fold in the value of the tag ("seconds", "weeks", etc) component of a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user