Skip to content

Commit

Permalink
pythongh-101277: Add pairwise type to module state
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Jan 24, 2023
1 parent 1d2d93c commit 38bf6e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 50 deletions.
6 changes: 3 additions & 3 deletions Modules/clinic/itertoolsmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 27 additions & 47 deletions Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct {
PyTypeObject *filterfalse_type;
PyTypeObject *groupby_type;
PyTypeObject *_grouper_type;
PyTypeObject *pairwise_type;
PyTypeObject *permutations_type;
PyTypeObject *starmap_type;
PyTypeObject *takewhile_type;
Expand Down Expand Up @@ -63,14 +64,13 @@ class itertools.accumulate "accumulateobject *" "clinic_state()->accumulate_type
class itertools.compress "compressobject *" "clinic_state()->compress_type"
class itertools.filterfalse "filterfalseobject *" "clinic_state()->filterfalse_type"
class itertools.count "countobject *" "clinic_state()->count_type"
class itertools.pairwise "pairwiseobject *" "&pairwise_type"
class itertools.pairwise "pairwiseobject *" "clinic_state()->pairwise_type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=338b4d26465f3eb1]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=28ffff5c0c93eed7]*/

static PyTypeObject teedataobject_type;
static PyTypeObject tee_type;
static PyTypeObject batched_type;
static PyTypeObject pairwise_type;

#include "clinic/itertoolsmodule.c.h"
#undef clinic_state
Expand Down Expand Up @@ -296,15 +296,18 @@ pairwise_new_impl(PyTypeObject *type, PyObject *iterable)
static void
pairwise_dealloc(pairwiseobject *po)
{
PyTypeObject *tp = Py_TYPE(po);
PyObject_GC_UnTrack(po);
Py_XDECREF(po->it);
Py_XDECREF(po->old);
Py_TYPE(po)->tp_free(po);
tp->tp_free(po);
Py_DECREF(tp);
}

static int
pairwise_traverse(pairwiseobject *po, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(po));
Py_VISIT(po->it);
Py_VISIT(po->old);
return 0;
Expand Down Expand Up @@ -339,48 +342,25 @@ pairwise_next(pairwiseobject *po)
return result;
}

static PyTypeObject pairwise_type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"itertools.pairwise", /* tp_name */
sizeof(pairwiseobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)pairwise_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
pairwise_new__doc__, /* tp_doc */
(traverseproc)pairwise_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)pairwise_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
pairwise_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
static PyType_Slot pairwise_slots[] = {
{Py_tp_dealloc, pairwise_dealloc},
{Py_tp_getattro, PyObject_GenericGetAttr},
{Py_tp_doc, (void *)pairwise_new__doc__},
{Py_tp_traverse, pairwise_traverse},
{Py_tp_iter, PyObject_SelfIter},
{Py_tp_iternext, pairwise_next},
{Py_tp_alloc, PyType_GenericAlloc},
{Py_tp_new, pairwise_new},
{Py_tp_free, PyObject_GC_Del},
{0, NULL},
};

static PyType_Spec pairwise_spec = {
.name = "itertools.pairwise",
.basicsize = sizeof(pairwiseobject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = pairwise_slots,
};


Expand Down Expand Up @@ -4809,6 +4789,7 @@ itertoolsmodule_exec(PyObject *mod)
ADD_TYPE(mod, state->filterfalse_type, &filterfalse_spec);
ADD_TYPE(mod, state->groupby_type, &groupby_spec);
ADD_TYPE(mod, state->_grouper_type, &_grouper_spec);
ADD_TYPE(mod, state->pairwise_type, &pairwise_spec);
ADD_TYPE(mod, state->permutations_type, &permutations_spec);
ADD_TYPE(mod, state->starmap_type, &starmap_spec);
ADD_TYPE(mod, state->takewhile_type, &takewhile_spec);
Expand All @@ -4818,7 +4799,6 @@ itertoolsmodule_exec(PyObject *mod)
&islice_type,
&chain_type,
&ziplongest_type,
&pairwise_type,
&product_type,
&repeat_type,
&tee_type,
Expand Down

0 comments on commit 38bf6e5

Please sign in to comment.