Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a03e534

Browse files
committed
Rework delta_divmod to avoid use of PyTuple_SetItem.
1 parent 56a6087 commit a03e534

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Modules/datetimemodule.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,8 @@ delta_divmod(PyObject *left, PyObject *right)
19271927
PyObject *pyus_left;
19281928
PyObject *pyus_right;
19291929
PyObject *divmod;
1930-
PyObject *microseconds, *delta;
1930+
PyObject *delta;
1931+
PyObject *result;
19311932

19321933
if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
19331934
Py_INCREF(Py_NotImplemented);
@@ -1950,14 +1951,16 @@ delta_divmod(PyObject *left, PyObject *right)
19501951
if (divmod == NULL)
19511952
return NULL;
19521953

1953-
microseconds = PyTuple_GetItem(divmod, 1);
1954-
delta = microseconds_to_delta(microseconds);
1954+
assert(PyTuple_Size(divmod) == 2);
1955+
delta = microseconds_to_delta(PyTuple_GET_ITEM(divmod, 1));
19551956
if (delta == NULL) {
19561957
Py_DECREF(divmod);
19571958
return NULL;
19581959
}
1959-
PyTuple_SetItem(divmod, 1, delta);
1960-
return divmod;
1960+
result = PyTuple_Pack(2, PyTuple_GET_ITEM(divmod, 0), delta);
1961+
Py_DECREF(delta);
1962+
Py_DECREF(divmod);
1963+
return result;
19611964
}
19621965

19631966
/* Fold in the value of the tag ("seconds", "weeks", etc) component of a

0 commit comments

Comments
 (0)