diff options
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r-- | Modules/itertoolsmodule.c | 70 |
1 files changed, 28 insertions, 42 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 55d88a8..cac02ad 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -157,15 +157,12 @@ groupby_setstate(groupbyobject *lz, PyObject *state) PyObject *currkey, *currvalue, *tgtkey; if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey)) return NULL; - Py_CLEAR(lz->currkey); - lz->currkey = currkey; - Py_INCREF(lz->currkey); - Py_CLEAR(lz->currvalue); - lz->currvalue = currvalue; - Py_INCREF(lz->currvalue); - Py_CLEAR(lz->tgtkey); - lz->tgtkey = tgtkey; - Py_INCREF(lz->tgtkey); + Py_INCREF(currkey); + Py_SETREF(lz->currkey, currkey); + Py_INCREF(currvalue); + Py_SETREF(lz->currvalue, currvalue); + Py_INCREF(tgtkey); + Py_SETREF(lz->tgtkey, tgtkey); Py_RETURN_NONE; } @@ -634,8 +631,7 @@ tee_next(teeobject *to) link = teedataobject_jumplink(to->dataobj); if (link == NULL) return NULL; - Py_DECREF(to->dataobj); - to->dataobj = (teedataobject *)link; + Py_SETREF(to->dataobj, (teedataobject *)link); to->index = 0; } value = teedataobject_getitem(to->dataobj, to->index); @@ -746,9 +742,8 @@ tee_setstate(teeobject *to, PyObject *state) PyErr_SetString(PyExc_ValueError, "Index out of range"); return NULL; } - Py_CLEAR(to->dataobj); - to->dataobj = tdo; - Py_INCREF(to->dataobj); + Py_INCREF(tdo); + Py_SETREF(to->dataobj, tdo); to->index = index; Py_RETURN_NONE; } @@ -973,9 +968,8 @@ cycle_setstate(cycleobject *lz, PyObject *state) int firstpass; if (!PyArg_ParseTuple(state, "Oi", &saved, &firstpass)) return NULL; - Py_CLEAR(lz->saved); - lz->saved = saved; - Py_XINCREF(lz->saved); + Py_XINCREF(saved); + Py_SETREF(lz->saved, saved); lz->firstpass = firstpass != 0; Py_RETURN_NONE; } @@ -1900,12 +1894,10 @@ chain_setstate(chainobject *lz, PyObject *state) if (! PyArg_ParseTuple(state, "O|O", &source, &active)) return NULL; - Py_CLEAR(lz->source); - lz->source = source; - Py_INCREF(lz->source); - Py_CLEAR(lz->active); - lz->active = active; - Py_XINCREF(lz->active); + Py_INCREF(source); + Py_SETREF(lz->source, source); + Py_XINCREF(active); + Py_SETREF(lz->active, active); Py_RETURN_NONE; } @@ -2087,7 +2079,7 @@ product_sizeof(productobject *lz, void *unused) { Py_ssize_t res; - res = sizeof(productobject); + res = _PyObject_SIZE(Py_TYPE(lz)); res += PyTuple_GET_SIZE(lz->pools) * sizeof(Py_ssize_t); return PyLong_FromSsize_t(res); } @@ -2261,8 +2253,7 @@ product_setstate(productobject *lz, PyObject *state) Py_INCREF(element); PyTuple_SET_ITEM(result, i, element); } - Py_CLEAR(lz->result); - lz->result = result; + Py_SETREF(lz->result, result); Py_RETURN_NONE; } @@ -2418,7 +2409,7 @@ combinations_sizeof(combinationsobject *co, void *unused) { Py_ssize_t res; - res = sizeof(combinationsobject); + res = _PyObject_SIZE(Py_TYPE(co)); res += co->r * sizeof(Py_ssize_t); return PyLong_FromSsize_t(res); } @@ -2584,8 +2575,7 @@ combinations_setstate(combinationsobject *lz, PyObject *state) PyTuple_SET_ITEM(result, i, element); } - Py_CLEAR(lz->result); - lz->result = result; + Py_SETREF(lz->result, result); Py_RETURN_NONE; } @@ -2759,7 +2749,7 @@ cwr_sizeof(cwrobject *co, void *unused) { Py_ssize_t res; - res = sizeof(cwrobject); + res = _PyObject_SIZE(Py_TYPE(co)); res += co->r * sizeof(Py_ssize_t); return PyLong_FromSsize_t(res); } @@ -2915,8 +2905,7 @@ cwr_setstate(cwrobject *lz, PyObject *state) Py_INCREF(element); PyTuple_SET_ITEM(result, i, element); } - Py_CLEAR(lz->result); - lz->result = result; + Py_SETREF(lz->result, result); Py_RETURN_NONE; } @@ -3108,7 +3097,7 @@ permutations_sizeof(permutationsobject *po, void *unused) { Py_ssize_t res; - res = sizeof(permutationsobject); + res = _PyObject_SIZE(Py_TYPE(po)); res += PyTuple_GET_SIZE(po->pool) * sizeof(Py_ssize_t); res += po->r * sizeof(Py_ssize_t); return PyLong_FromSsize_t(res); @@ -3309,8 +3298,7 @@ permutations_setstate(permutationsobject *po, PyObject *state) Py_INCREF(element); PyTuple_SET_ITEM(result, i, element); } - Py_CLEAR(po->result); - po->result = result; + Py_SETREF(po->result, result); Py_RETURN_NONE; } @@ -3480,9 +3468,8 @@ accumulate_reduce(accumulateobject *lz) static PyObject * accumulate_setstate(accumulateobject *lz, PyObject *state) { - Py_CLEAR(lz->total); - lz->total = state; - Py_INCREF(lz->total); + Py_INCREF(state); + Py_SETREF(lz->total, state); Py_RETURN_NONE; } @@ -3882,7 +3869,7 @@ typedef struct { fast_mode: when cnt an integer < PY_SSIZE_T_MAX and no step is specified. - assert(cnt != PY_SSIZE_T_MAX && long_cnt == NULL && long_step==PyInt(1)); + assert(cnt != PY_SSIZE_T_MAX && long_cnt == NULL && long_step==PyLong(1)); Advances with: cnt += 1 When count hits Y_SSIZE_T_MAX, switch to slow_mode. @@ -4463,9 +4450,8 @@ zip_longest_reduce(ziplongestobject *lz) static PyObject * zip_longest_setstate(ziplongestobject *lz, PyObject *state) { - Py_CLEAR(lz->fillvalue); - lz->fillvalue = state; - Py_INCREF(lz->fillvalue); + Py_INCREF(state); + Py_SETREF(lz->fillvalue, state); Py_RETURN_NONE; } |