bool strict;
} batchedobject;
+#define batchedobject_CAST(op) ((batchedobject *)(op))
+
/*[clinic input]
@classmethod
itertools.batched.__new__ as batched_new
}
static void
-batched_dealloc(batchedobject *bo)
+batched_dealloc(PyObject *op)
{
+ batchedobject *bo = batchedobject_CAST(op);
PyTypeObject *tp = Py_TYPE(bo);
PyObject_GC_UnTrack(bo);
Py_XDECREF(bo->it);
}
static int
-batched_traverse(batchedobject *bo, visitproc visit, void *arg)
+batched_traverse(PyObject *op, visitproc visit, void *arg)
{
+ batchedobject *bo = batchedobject_CAST(op);
Py_VISIT(Py_TYPE(bo));
Py_VISIT(bo->it);
return 0;
}
static PyObject *
-batched_next(batchedobject *bo)
+batched_next(PyObject *op)
{
+ batchedobject *bo = batchedobject_CAST(op);
Py_ssize_t i;
Py_ssize_t n = bo->batch_size;
PyObject *it = bo->it;
PyObject *result;
} pairwiseobject;
+#define pairwiseobject_CAST(op) ((pairwiseobject *)(op))
+
/*[clinic input]
@classmethod
itertools.pairwise.__new__ as pairwise_new
}
static void
-pairwise_dealloc(pairwiseobject *po)
+pairwise_dealloc(PyObject *op)
{
+ pairwiseobject *po = pairwiseobject_CAST(op);
PyTypeObject *tp = Py_TYPE(po);
PyObject_GC_UnTrack(po);
Py_XDECREF(po->it);
}
static int
-pairwise_traverse(pairwiseobject *po, visitproc visit, void *arg)
+pairwise_traverse(PyObject *op, visitproc visit, void *arg)
{
+ pairwiseobject *po = pairwiseobject_CAST(op);
Py_VISIT(Py_TYPE(po));
Py_VISIT(po->it);
Py_VISIT(po->old);
}
static PyObject *
-pairwise_next(pairwiseobject *po)
+pairwise_next(PyObject *op)
{
+ pairwiseobject *po = pairwiseobject_CAST(op);
PyObject *it = po->it;
PyObject *old = po->old;
PyObject *new, *result;
itertools_state *state;
} groupbyobject;
+#define groupbyobject_CAST(op) ((groupbyobject *)(op))
+
static PyObject *_grouper_create(groupbyobject *, PyObject *);
/*[clinic input]
}
static void
-groupby_dealloc(groupbyobject *gbo)
+groupby_dealloc(PyObject *op)
{
+ groupbyobject *gbo = groupbyobject_CAST(op);
PyTypeObject *tp = Py_TYPE(gbo);
PyObject_GC_UnTrack(gbo);
Py_XDECREF(gbo->it);
}
static int
-groupby_traverse(groupbyobject *gbo, visitproc visit, void *arg)
+groupby_traverse(PyObject *op, visitproc visit, void *arg)
{
+ groupbyobject *gbo = groupbyobject_CAST(op);
Py_VISIT(Py_TYPE(gbo));
Py_VISIT(gbo->it);
Py_VISIT(gbo->keyfunc);
}
static PyObject *
-groupby_next(groupbyobject *gbo)
+groupby_next(PyObject *op)
{
PyObject *r, *grouper;
+ groupbyobject *gbo = groupbyobject_CAST(op);
gbo->currgrouper = NULL;
/* skip to next iteration group */
PyObject *tgtkey;
} _grouperobject;
+#define _grouperobject_CAST(op) ((_grouperobject *)(op))
+
/*[clinic input]
@classmethod
itertools._grouper.__new__
PyObject *tgtkey)
/*[clinic end generated code: output=462efb1cdebb5914 input=afe05eb477118f12]*/
{
- return _grouper_create((groupbyobject*) parent, tgtkey);
+ return _grouper_create(groupbyobject_CAST(parent), tgtkey);
}
static PyObject *
}
static void
-_grouper_dealloc(_grouperobject *igo)
+_grouper_dealloc(PyObject *op)
{
+ _grouperobject *igo = _grouperobject_CAST(op);
PyTypeObject *tp = Py_TYPE(igo);
PyObject_GC_UnTrack(igo);
Py_DECREF(igo->parent);
}
static int
-_grouper_traverse(_grouperobject *igo, visitproc visit, void *arg)
+_grouper_traverse(PyObject *op, visitproc visit, void *arg)
{
+ _grouperobject *igo = _grouperobject_CAST(op);
Py_VISIT(Py_TYPE(igo));
Py_VISIT(igo->parent);
Py_VISIT(igo->tgtkey);
}
static PyObject *
-_grouper_next(_grouperobject *igo)
+_grouper_next(PyObject *op)
{
- groupbyobject *gbo = (groupbyobject *)igo->parent;
+ _grouperobject *igo = _grouperobject_CAST(op);
+ groupbyobject *gbo = groupbyobject_CAST(igo->parent);
PyObject *r;
int rcmp;
PyObject *(values[LINKCELLS]);
} teedataobject;
+#define teedataobject_CAST(op) ((teedataobject *)(op))
+
typedef struct {
PyObject_HEAD
teedataobject *dataobj;
itertools_state *state;
} teeobject;
+#define teeobject_CAST(op) ((teeobject *)(op))
+
static PyObject *
teedataobject_newinternal(itertools_state *state, PyObject *it)
{
}
static int
-teedataobject_traverse(teedataobject *tdo, visitproc visit, void * arg)
+teedataobject_traverse(PyObject *op, visitproc visit, void * arg)
{
int i;
+ teedataobject *tdo = teedataobject_CAST(op);
Py_VISIT(Py_TYPE(tdo));
Py_VISIT(tdo->it);
teedataobject_safe_decref(PyObject *obj)
{
while (obj && Py_REFCNT(obj) == 1) {
- PyObject *nextlink = ((teedataobject *)obj)->nextlink;
- ((teedataobject *)obj)->nextlink = NULL;
+ teedataobject *tmp = teedataobject_CAST(obj);
+ PyObject *nextlink = tmp->nextlink;
+ tmp->nextlink = NULL;
Py_SETREF(obj, nextlink);
}
Py_XDECREF(obj);
}
static int
-teedataobject_clear(teedataobject *tdo)
+teedataobject_clear(PyObject *op)
{
int i;
PyObject *tmp;
+ teedataobject *tdo = teedataobject_CAST(op);
Py_CLEAR(tdo->it);
for (i=0 ; i<tdo->numread ; i++)
}
static void
-teedataobject_dealloc(teedataobject *tdo)
+teedataobject_dealloc(PyObject *op)
{
- PyTypeObject *tp = Py_TYPE(tdo);
- PyObject_GC_UnTrack(tdo);
- teedataobject_clear(tdo);
- PyObject_GC_Del(tdo);
+ PyTypeObject *tp = Py_TYPE(op);
+ PyObject_GC_UnTrack(op);
+ (void)teedataobject_clear(op);
+ PyObject_GC_Del(op);
Py_DECREF(tp);
}
static PyObject *
-tee_next(teeobject *to)
+tee_next(PyObject *op)
{
+ teeobject *to = teeobject_CAST(op);
PyObject *value, *link;
if (to->index >= LINKCELLS) {
}
static int
-tee_traverse(teeobject *to, visitproc visit, void *arg)
+tee_traverse(PyObject *op, visitproc visit, void *arg)
{
+ teeobject *to = teeobject_CAST(op);
Py_VISIT(Py_TYPE(to));
Py_VISIT((PyObject *)to->dataobj);
return 0;
}
-static PyObject *
-tee_copy(teeobject *to, PyObject *Py_UNUSED(ignored))
+static teeobject *
+tee_copy_impl(teeobject *to)
{
- teeobject *newto;
-
- newto = PyObject_GC_New(teeobject, Py_TYPE(to));
- if (newto == NULL)
+ teeobject *newto = PyObject_GC_New(teeobject, Py_TYPE(to));
+ if (newto == NULL) {
return NULL;
- newto->dataobj = (teedataobject*)Py_NewRef(to->dataobj);
+ }
+ newto->dataobj = (teedataobject *)Py_NewRef(to->dataobj);
newto->index = to->index;
newto->weakreflist = NULL;
newto->state = to->state;
PyObject_GC_Track(newto);
- return (PyObject *)newto;
+ return newto;
+}
+
+static inline PyObject *
+tee_copy(PyObject *op, PyObject *Py_UNUSED(ignored))
+{
+ teeobject *to = teeobject_CAST(op);
+ return (PyObject *)tee_copy_impl(to);
}
PyDoc_STRVAR(teecopy_doc, "Returns an independent iterator.");
if (it == NULL)
return NULL;
if (PyObject_TypeCheck(it, state->tee_type)) {
- to = (teeobject *)tee_copy((teeobject *)it, NULL);
+ to = tee_copy_impl((teeobject *)it); // 'it' can be fast casted
goto done;
}
}
static int
-tee_clear(teeobject *to)
+tee_clear(PyObject *op)
{
+ teeobject *to = teeobject_CAST(op);
if (to->weakreflist != NULL)
- PyObject_ClearWeakRefs((PyObject *) to);
+ PyObject_ClearWeakRefs(op);
Py_CLEAR(to->dataobj);
return 0;
}
static void
-tee_dealloc(teeobject *to)
+tee_dealloc(PyObject *op)
{
- PyTypeObject *tp = Py_TYPE(to);
- PyObject_GC_UnTrack(to);
- tee_clear(to);
- PyObject_GC_Del(to);
+ PyTypeObject *tp = Py_TYPE(op);
+ PyObject_GC_UnTrack(op);
+ (void)tee_clear(op);
+ PyObject_GC_Del(op);
Py_DECREF(tp);
}
static PyMethodDef tee_methods[] = {
- {"__copy__", (PyCFunction)tee_copy, METH_NOARGS, teecopy_doc},
+ {"__copy__", tee_copy, METH_NOARGS, teecopy_doc},
{NULL, NULL} /* sentinel */
};
PyTuple_SET_ITEM(result, 0, to);
for (i = 1; i < n; i++) {
- to = tee_copy((teeobject *)to, NULL);
+ to = tee_copy(to, NULL);
if (to == NULL) {
Py_DECREF(result);
return NULL;
int firstpass;
} cycleobject;
+#define cycleobject_CAST(op) ((cycleobject *)(op))
+
/*[clinic input]
@classmethod
itertools.cycle.__new__
}
static void
-cycle_dealloc(cycleobject *lz)
+cycle_dealloc(PyObject *op)
{
+ cycleobject *lz = cycleobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->it);
}
static int
-cycle_traverse(cycleobject *lz, visitproc visit, void *arg)
+cycle_traverse(PyObject *op, visitproc visit, void *arg)
{
+ cycleobject *lz = cycleobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->it);
Py_VISIT(lz->saved);
}
static PyObject *
-cycle_next(cycleobject *lz)
+cycle_next(PyObject *op)
{
+ cycleobject *lz = cycleobject_CAST(op);
PyObject *item;
if (lz->it != NULL) {
long start;
} dropwhileobject;
+#define dropwhileobject_CAST(op) ((dropwhileobject *)(op))
+
/*[clinic input]
@classmethod
itertools.dropwhile.__new__
}
static void
-dropwhile_dealloc(dropwhileobject *lz)
+dropwhile_dealloc(PyObject *op)
{
+ dropwhileobject *lz = dropwhileobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
}
static int
-dropwhile_traverse(dropwhileobject *lz, visitproc visit, void *arg)
+dropwhile_traverse(PyObject *op, visitproc visit, void *arg)
{
+ dropwhileobject *lz = dropwhileobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->it);
Py_VISIT(lz->func);
}
static PyObject *
-dropwhile_next(dropwhileobject *lz)
+dropwhile_next(PyObject *op)
{
+ dropwhileobject *lz = dropwhileobject_CAST(op);
PyObject *item, *good;
PyObject *it = lz->it;
long ok;
long stop;
} takewhileobject;
+#define takewhileobject_CAST(op) ((takewhileobject *)(op))
+
/*[clinic input]
@classmethod
itertools.takewhile.__new__
}
static void
-takewhile_dealloc(takewhileobject *lz)
+takewhile_dealloc(PyObject *op)
{
+ takewhileobject *lz = takewhileobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
}
static int
-takewhile_traverse(takewhileobject *lz, visitproc visit, void *arg)
+takewhile_traverse(PyObject *op, visitproc visit, void *arg)
{
+ takewhileobject *lz = takewhileobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->it);
Py_VISIT(lz->func);
}
static PyObject *
-takewhile_next(takewhileobject *lz)
+takewhile_next(PyObject *op)
{
+ takewhileobject *lz = takewhileobject_CAST(op);
PyObject *item, *good;
PyObject *it = lz->it;
long ok;
Py_ssize_t cnt;
} isliceobject;
+#define isliceobject_CAST(op) ((isliceobject *)(op))
+
static PyObject *
islice_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
}
static void
-islice_dealloc(isliceobject *lz)
+islice_dealloc(PyObject *op)
{
+ isliceobject *lz = isliceobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->it);
}
static int
-islice_traverse(isliceobject *lz, visitproc visit, void *arg)
+islice_traverse(PyObject *op, visitproc visit, void *arg)
{
+ isliceobject *lz = isliceobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->it);
return 0;
}
static PyObject *
-islice_next(isliceobject *lz)
+islice_next(PyObject *op)
{
+ isliceobject *lz = isliceobject_CAST(op);
PyObject *item;
PyObject *it = lz->it;
Py_ssize_t stop = lz->stop;
PyObject *it;
} starmapobject;
+#define starmapobject_CAST(op) ((starmapobject *)(op))
+
/*[clinic input]
@classmethod
itertools.starmap.__new__
}
static void
-starmap_dealloc(starmapobject *lz)
+starmap_dealloc(PyObject *op)
{
+ starmapobject *lz = starmapobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
}
static int
-starmap_traverse(starmapobject *lz, visitproc visit, void *arg)
+starmap_traverse(PyObject *op, visitproc visit, void *arg)
{
+ starmapobject *lz = starmapobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->it);
Py_VISIT(lz->func);
}
static PyObject *
-starmap_next(starmapobject *lz)
+starmap_next(PyObject *op)
{
+ starmapobject *lz = starmapobject_CAST(op);
PyObject *args;
PyObject *result;
PyObject *it = lz->it;
PyObject *active; /* Currently running input iterator */
} chainobject;
+#define chainobject_CAST(op) ((chainobject *)(op))
+
static PyObject *
chain_new_internal(PyTypeObject *type, PyObject *source)
{
}
static void
-chain_dealloc(chainobject *lz)
+chain_dealloc(PyObject *op)
{
+ chainobject *lz = chainobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->active);
}
static int
-chain_traverse(chainobject *lz, visitproc visit, void *arg)
+chain_traverse(PyObject *op, visitproc visit, void *arg)
{
+ chainobject *lz = chainobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->source);
Py_VISIT(lz->active);
}
static PyObject *
-chain_next(chainobject *lz)
+chain_next(PyObject *op)
{
+ chainobject *lz = chainobject_CAST(op);
PyObject *item;
/* lz->source is the iterator of iterables. If it's NULL, we've already
int stopped; /* set to 1 when the iterator is exhausted */
} productobject;
+#define productobject_CAST(op) ((productobject *)(op))
+
static PyObject *
product_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
}
static void
-product_dealloc(productobject *lz)
+product_dealloc(PyObject *op)
{
+ productobject *lz = productobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->pools);
Py_XDECREF(lz->result);
- if (lz->indices != NULL)
- PyMem_Free(lz->indices);
+ PyMem_Free(lz->indices);
tp->tp_free(lz);
Py_DECREF(tp);
}
static PyObject *
-product_sizeof(productobject *lz, void *unused)
+product_sizeof(PyObject *op, PyObject *Py_UNUSED(ignored))
{
+ productobject *lz = productobject_CAST(op);
size_t res = _PyObject_SIZE(Py_TYPE(lz));
res += (size_t)PyTuple_GET_SIZE(lz->pools) * sizeof(Py_ssize_t);
return PyLong_FromSize_t(res);
PyDoc_STRVAR(sizeof_doc, "Returns size in memory, in bytes.");
static int
-product_traverse(productobject *lz, visitproc visit, void *arg)
+product_traverse(PyObject *op, visitproc visit, void *arg)
{
+ productobject *lz = productobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->pools);
Py_VISIT(lz->result);
}
static PyObject *
-product_next(productobject *lz)
+product_next(PyObject *op)
{
+ productobject *lz = productobject_CAST(op);
PyObject *pool;
PyObject *elem;
PyObject *oldelem;
}
static PyMethodDef product_methods[] = {
- {"__sizeof__", (PyCFunction)product_sizeof, METH_NOARGS,
- sizeof_doc},
+ {"__sizeof__", product_sizeof, METH_NOARGS, sizeof_doc},
{NULL, NULL} /* sentinel */
};
int stopped; /* set to 1 when the iterator is exhausted */
} combinationsobject;
+#define combinationsobject_CAST(op) ((combinationsobject *)(op))
/*[clinic input]
@classmethod
}
static void
-combinations_dealloc(combinationsobject *co)
+combinations_dealloc(PyObject *op)
{
+ combinationsobject *co = combinationsobject_CAST(op);
PyTypeObject *tp = Py_TYPE(co);
PyObject_GC_UnTrack(co);
Py_XDECREF(co->pool);
Py_XDECREF(co->result);
- if (co->indices != NULL)
- PyMem_Free(co->indices);
+ PyMem_Free(co->indices);
tp->tp_free(co);
Py_DECREF(tp);
}
static PyObject *
-combinations_sizeof(combinationsobject *co, void *unused)
+combinations_sizeof(PyObject *op, PyObject *Py_UNUSED(args))
{
+ combinationsobject *co = combinationsobject_CAST(op);
size_t res = _PyObject_SIZE(Py_TYPE(co));
res += (size_t)co->r * sizeof(Py_ssize_t);
return PyLong_FromSize_t(res);
}
static int
-combinations_traverse(combinationsobject *co, visitproc visit, void *arg)
+combinations_traverse(PyObject *op, visitproc visit, void *arg)
{
+ combinationsobject *co = combinationsobject_CAST(op);
Py_VISIT(Py_TYPE(co));
Py_VISIT(co->pool);
Py_VISIT(co->result);
}
static PyObject *
-combinations_next(combinationsobject *co)
+combinations_next(PyObject *op)
{
+ combinationsobject *co = combinationsobject_CAST(op);
PyObject *elem;
PyObject *oldelem;
PyObject *pool = co->pool;
}
static PyMethodDef combinations_methods[] = {
- {"__sizeof__", (PyCFunction)combinations_sizeof, METH_NOARGS,
- sizeof_doc},
+ {"__sizeof__", combinations_sizeof, METH_NOARGS, sizeof_doc},
{NULL, NULL} /* sentinel */
};
int stopped; /* set to 1 when the cwr iterator is exhausted */
} cwrobject;
+#define cwrobject_CAST(op) ((cwrobject *)(op))
+
/*[clinic input]
@classmethod
itertools.combinations_with_replacement.__new__
}
static void
-cwr_dealloc(cwrobject *co)
+cwr_dealloc(PyObject *op)
{
+ cwrobject *co = cwrobject_CAST(op);
PyTypeObject *tp = Py_TYPE(co);
PyObject_GC_UnTrack(co);
Py_XDECREF(co->pool);
Py_XDECREF(co->result);
- if (co->indices != NULL)
- PyMem_Free(co->indices);
+ PyMem_Free(co->indices);
tp->tp_free(co);
Py_DECREF(tp);
}
static PyObject *
-cwr_sizeof(cwrobject *co, void *unused)
+cwr_sizeof(PyObject *op, PyObject *Py_UNUSED(args))
{
+ cwrobject *co = cwrobject_CAST(op);
size_t res = _PyObject_SIZE(Py_TYPE(co));
res += (size_t)co->r * sizeof(Py_ssize_t);
return PyLong_FromSize_t(res);
}
static int
-cwr_traverse(cwrobject *co, visitproc visit, void *arg)
+cwr_traverse(PyObject *op, visitproc visit, void *arg)
{
+ cwrobject *co = cwrobject_CAST(op);
Py_VISIT(Py_TYPE(co));
Py_VISIT(co->pool);
Py_VISIT(co->result);
}
static PyObject *
-cwr_next(cwrobject *co)
+cwr_next(PyObject *op)
{
+ cwrobject *co = cwrobject_CAST(op);
PyObject *elem;
PyObject *oldelem;
PyObject *pool = co->pool;
}
static PyMethodDef cwr_methods[] = {
- {"__sizeof__", (PyCFunction)cwr_sizeof, METH_NOARGS,
- sizeof_doc},
+ {"__sizeof__", cwr_sizeof, METH_NOARGS, sizeof_doc},
{NULL, NULL} /* sentinel */
};
int stopped; /* set to 1 when the iterator is exhausted */
} permutationsobject;
+#define permutationsobject_CAST(op) ((permutationsobject *)(op))
+
/*[clinic input]
@classmethod
itertools.permutations.__new__
}
static void
-permutations_dealloc(permutationsobject *po)
+permutations_dealloc(PyObject *op)
{
+ permutationsobject *po = permutationsobject_CAST(op);
PyTypeObject *tp = Py_TYPE(po);
PyObject_GC_UnTrack(po);
Py_XDECREF(po->pool);
}
static PyObject *
-permutations_sizeof(permutationsobject *po, void *unused)
+permutations_sizeof(PyObject *op, PyObject *Py_UNUSED(args))
{
+ permutationsobject *po = permutationsobject_CAST(op);
size_t res = _PyObject_SIZE(Py_TYPE(po));
res += (size_t)PyTuple_GET_SIZE(po->pool) * sizeof(Py_ssize_t);
res += (size_t)po->r * sizeof(Py_ssize_t);
}
static int
-permutations_traverse(permutationsobject *po, visitproc visit, void *arg)
+permutations_traverse(PyObject *op, visitproc visit, void *arg)
{
+ permutationsobject *po = permutationsobject_CAST(op);
Py_VISIT(Py_TYPE(po));
Py_VISIT(po->pool);
Py_VISIT(po->result);
}
static PyObject *
-permutations_next(permutationsobject *po)
+permutations_next(PyObject *op)
{
+ permutationsobject *po = permutationsobject_CAST(op);
PyObject *elem;
PyObject *oldelem;
PyObject *pool = po->pool;
}
static PyMethodDef permuations_methods[] = {
- {"__sizeof__", (PyCFunction)permutations_sizeof, METH_NOARGS,
- sizeof_doc},
+ {"__sizeof__", permutations_sizeof, METH_NOARGS, sizeof_doc},
{NULL, NULL} /* sentinel */
};
itertools_state *state;
} accumulateobject;
+#define accumulateobject_CAST(op) ((accumulateobject *)(op))
+
/*[clinic input]
@classmethod
itertools.accumulate.__new__
}
static void
-accumulate_dealloc(accumulateobject *lz)
+accumulate_dealloc(PyObject *op)
{
+ accumulateobject *lz = accumulateobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->binop);
}
static int
-accumulate_traverse(accumulateobject *lz, visitproc visit, void *arg)
+accumulate_traverse(PyObject *op, visitproc visit, void *arg)
{
+ accumulateobject *lz = accumulateobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->binop);
Py_VISIT(lz->it);
}
static PyObject *
-accumulate_next(accumulateobject *lz)
+accumulate_next(PyObject *op)
{
+ accumulateobject *lz = accumulateobject_CAST(op);
PyObject *val, *newtotal;
if (lz->initial != Py_None) {
PyObject *selectors;
} compressobject;
+#define compressobject_CAST(op) ((compressobject *)(op))
+
/*[clinic input]
@classmethod
itertools.compress.__new__
}
static void
-compress_dealloc(compressobject *lz)
+compress_dealloc(PyObject *op)
{
+ compressobject *lz = compressobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->data);
}
static int
-compress_traverse(compressobject *lz, visitproc visit, void *arg)
+compress_traverse(PyObject *op, visitproc visit, void *arg)
{
+ compressobject *lz = compressobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->data);
Py_VISIT(lz->selectors);
}
static PyObject *
-compress_next(compressobject *lz)
+compress_next(PyObject *op)
{
+ compressobject *lz = compressobject_CAST(op);
PyObject *data = lz->data, *selectors = lz->selectors;
PyObject *datum, *selector;
PyObject *(*datanext)(PyObject *) = *Py_TYPE(data)->tp_iternext;
PyObject *it;
} filterfalseobject;
+#define filterfalseobject_CAST(op) ((filterfalseobject *)(op))
+
/*[clinic input]
@classmethod
itertools.filterfalse.__new__
}
static void
-filterfalse_dealloc(filterfalseobject *lz)
+filterfalse_dealloc(PyObject *op)
{
+ filterfalseobject *lz = filterfalseobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
}
static int
-filterfalse_traverse(filterfalseobject *lz, visitproc visit, void *arg)
+filterfalse_traverse(PyObject *op, visitproc visit, void *arg)
{
+ filterfalseobject *lz = filterfalseobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->it);
Py_VISIT(lz->func);
}
static PyObject *
-filterfalse_next(filterfalseobject *lz)
+filterfalse_next(PyObject *op)
{
+ filterfalseobject *lz = filterfalseobject_CAST(op);
PyObject *item;
PyObject *it = lz->it;
long ok;
PyObject *long_step;
} countobject;
+#define countobject_CAST(op) ((countobject *)(op))
+
/* Counting logic and invariants:
fast_mode: when cnt an integer < PY_SSIZE_T_MAX and no step is specified.
}
static void
-count_dealloc(countobject *lz)
+count_dealloc(PyObject *op)
{
+ countobject *lz = countobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->long_cnt);
}
static int
-count_traverse(countobject *lz, visitproc visit, void *arg)
+count_traverse(PyObject *op, visitproc visit, void *arg)
{
+ countobject *lz = countobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->long_cnt);
Py_VISIT(lz->long_step);
}
static PyObject *
-count_next(countobject *lz)
+count_next(PyObject *op)
{
+ countobject *lz = countobject_CAST(op);
#ifndef Py_GIL_DISABLED
if (lz->cnt == PY_SSIZE_T_MAX)
return count_nextlong(lz);
}
static PyObject *
-count_repr(countobject *lz)
+count_repr(PyObject *op)
{
+ countobject *lz = countobject_CAST(op);
if (lz->long_cnt == NULL)
return PyUnicode_FromFormat("%s(%zd)",
_PyType_Name(Py_TYPE(lz)), lz->cnt);
Py_ssize_t cnt;
} repeatobject;
+#define repeatobject_CAST(op) ((repeatobject *)(op))
+
static PyObject *
repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
}
static void
-repeat_dealloc(repeatobject *ro)
+repeat_dealloc(PyObject *op)
{
+ repeatobject *ro = repeatobject_CAST(op);
PyTypeObject *tp = Py_TYPE(ro);
PyObject_GC_UnTrack(ro);
Py_XDECREF(ro->element);
}
static int
-repeat_traverse(repeatobject *ro, visitproc visit, void *arg)
+repeat_traverse(PyObject *op, visitproc visit, void *arg)
{
+ repeatobject *ro = repeatobject_CAST(op);
Py_VISIT(Py_TYPE(ro));
Py_VISIT(ro->element);
return 0;
}
static PyObject *
-repeat_next(repeatobject *ro)
+repeat_next(PyObject *op)
{
+ repeatobject *ro = repeatobject_CAST(op);
if (ro->cnt == 0)
return NULL;
if (ro->cnt > 0)
}
static PyObject *
-repeat_repr(repeatobject *ro)
+repeat_repr(PyObject *op)
{
+ repeatobject *ro = repeatobject_CAST(op);
if (ro->cnt == -1)
return PyUnicode_FromFormat("%s(%R)",
_PyType_Name(Py_TYPE(ro)), ro->element);
}
static PyObject *
-repeat_len(repeatobject *ro, PyObject *Py_UNUSED(ignored))
+repeat_len(PyObject *op, PyObject *Py_UNUSED(args))
{
+ repeatobject *ro = repeatobject_CAST(op);
if (ro->cnt == -1) {
PyErr_SetString(PyExc_TypeError, "len() of unsized object");
return NULL;
PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
static PyMethodDef repeat_methods[] = {
- {"__length_hint__", (PyCFunction)repeat_len, METH_NOARGS, length_hint_doc},
+ {"__length_hint__", repeat_len, METH_NOARGS, length_hint_doc},
{NULL, NULL} /* sentinel */
};
PyObject *fillvalue;
} ziplongestobject;
+#define ziplongestobject_CAST(op) ((ziplongestobject *)(op))
+
static PyObject *
zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
}
static void
-zip_longest_dealloc(ziplongestobject *lz)
+zip_longest_dealloc(PyObject *op)
{
+ ziplongestobject *lz = ziplongestobject_CAST(op);
PyTypeObject *tp = Py_TYPE(lz);
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->ittuple);
}
static int
-zip_longest_traverse(ziplongestobject *lz, visitproc visit, void *arg)
+zip_longest_traverse(PyObject *op, visitproc visit, void *arg)
{
+ ziplongestobject *lz = ziplongestobject_CAST(op);
Py_VISIT(Py_TYPE(lz));
Py_VISIT(lz->ittuple);
Py_VISIT(lz->result);
}
static PyObject *
-zip_longest_next(ziplongestobject *lz)
+zip_longest_next(PyObject *op)
{
+ ziplongestobject *lz = ziplongestobject_CAST(op);
Py_ssize_t i;
Py_ssize_t tuplesize = lz->tuplesize;
PyObject *result = lz->result;