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

Skip to content

Commit 38bf6e5

Browse files
gh-101277: Add pairwise type to module state
1 parent 1d2d93c commit 38bf6e5

2 files changed

Lines changed: 30 additions & 50 deletions

File tree

Modules/clinic/itertoolsmodule.c.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/itertoolsmodule.c

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef struct {
2121
PyTypeObject *filterfalse_type;
2222
PyTypeObject *groupby_type;
2323
PyTypeObject *_grouper_type;
24+
PyTypeObject *pairwise_type;
2425
PyTypeObject *permutations_type;
2526
PyTypeObject *starmap_type;
2627
PyTypeObject *takewhile_type;
@@ -63,14 +64,13 @@ class itertools.accumulate "accumulateobject *" "clinic_state()->accumulate_type
6364
class itertools.compress "compressobject *" "clinic_state()->compress_type"
6465
class itertools.filterfalse "filterfalseobject *" "clinic_state()->filterfalse_type"
6566
class itertools.count "countobject *" "clinic_state()->count_type"
66-
class itertools.pairwise "pairwiseobject *" "&pairwise_type"
67+
class itertools.pairwise "pairwiseobject *" "clinic_state()->pairwise_type"
6768
[clinic start generated code]*/
68-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=338b4d26465f3eb1]*/
69+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=28ffff5c0c93eed7]*/
6970

7071
static PyTypeObject teedataobject_type;
7172
static PyTypeObject tee_type;
7273
static PyTypeObject batched_type;
73-
static PyTypeObject pairwise_type;
7474

7575
#include "clinic/itertoolsmodule.c.h"
7676
#undef clinic_state
@@ -296,15 +296,18 @@ pairwise_new_impl(PyTypeObject *type, PyObject *iterable)
296296
static void
297297
pairwise_dealloc(pairwiseobject *po)
298298
{
299+
PyTypeObject *tp = Py_TYPE(po);
299300
PyObject_GC_UnTrack(po);
300301
Py_XDECREF(po->it);
301302
Py_XDECREF(po->old);
302-
Py_TYPE(po)->tp_free(po);
303+
tp->tp_free(po);
304+
Py_DECREF(tp);
303305
}
304306

305307
static int
306308
pairwise_traverse(pairwiseobject *po, visitproc visit, void *arg)
307309
{
310+
Py_VISIT(Py_TYPE(po));
308311
Py_VISIT(po->it);
309312
Py_VISIT(po->old);
310313
return 0;
@@ -339,48 +342,25 @@ pairwise_next(pairwiseobject *po)
339342
return result;
340343
}
341344

342-
static PyTypeObject pairwise_type = {
343-
PyVarObject_HEAD_INIT(&PyType_Type, 0)
344-
"itertools.pairwise", /* tp_name */
345-
sizeof(pairwiseobject), /* tp_basicsize */
346-
0, /* tp_itemsize */
347-
/* methods */
348-
(destructor)pairwise_dealloc, /* tp_dealloc */
349-
0, /* tp_vectorcall_offset */
350-
0, /* tp_getattr */
351-
0, /* tp_setattr */
352-
0, /* tp_as_async */
353-
0, /* tp_repr */
354-
0, /* tp_as_number */
355-
0, /* tp_as_sequence */
356-
0, /* tp_as_mapping */
357-
0, /* tp_hash */
358-
0, /* tp_call */
359-
0, /* tp_str */
360-
PyObject_GenericGetAttr, /* tp_getattro */
361-
0, /* tp_setattro */
362-
0, /* tp_as_buffer */
363-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
364-
Py_TPFLAGS_BASETYPE, /* tp_flags */
365-
pairwise_new__doc__, /* tp_doc */
366-
(traverseproc)pairwise_traverse, /* tp_traverse */
367-
0, /* tp_clear */
368-
0, /* tp_richcompare */
369-
0, /* tp_weaklistoffset */
370-
PyObject_SelfIter, /* tp_iter */
371-
(iternextfunc)pairwise_next, /* tp_iternext */
372-
0, /* tp_methods */
373-
0, /* tp_members */
374-
0, /* tp_getset */
375-
0, /* tp_base */
376-
0, /* tp_dict */
377-
0, /* tp_descr_get */
378-
0, /* tp_descr_set */
379-
0, /* tp_dictoffset */
380-
0, /* tp_init */
381-
PyType_GenericAlloc, /* tp_alloc */
382-
pairwise_new, /* tp_new */
383-
PyObject_GC_Del, /* tp_free */
345+
static PyType_Slot pairwise_slots[] = {
346+
{Py_tp_dealloc, pairwise_dealloc},
347+
{Py_tp_getattro, PyObject_GenericGetAttr},
348+
{Py_tp_doc, (void *)pairwise_new__doc__},
349+
{Py_tp_traverse, pairwise_traverse},
350+
{Py_tp_iter, PyObject_SelfIter},
351+
{Py_tp_iternext, pairwise_next},
352+
{Py_tp_alloc, PyType_GenericAlloc},
353+
{Py_tp_new, pairwise_new},
354+
{Py_tp_free, PyObject_GC_Del},
355+
{0, NULL},
356+
};
357+
358+
static PyType_Spec pairwise_spec = {
359+
.name = "itertools.pairwise",
360+
.basicsize = sizeof(pairwiseobject),
361+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
362+
Py_TPFLAGS_IMMUTABLETYPE),
363+
.slots = pairwise_slots,
384364
};
385365

386366

@@ -4809,6 +4789,7 @@ itertoolsmodule_exec(PyObject *mod)
48094789
ADD_TYPE(mod, state->filterfalse_type, &filterfalse_spec);
48104790
ADD_TYPE(mod, state->groupby_type, &groupby_spec);
48114791
ADD_TYPE(mod, state->_grouper_type, &_grouper_spec);
4792+
ADD_TYPE(mod, state->pairwise_type, &pairwise_spec);
48124793
ADD_TYPE(mod, state->permutations_type, &permutations_spec);
48134794
ADD_TYPE(mod, state->starmap_type, &starmap_spec);
48144795
ADD_TYPE(mod, state->takewhile_type, &takewhile_spec);
@@ -4818,7 +4799,6 @@ itertoolsmodule_exec(PyObject *mod)
48184799
&islice_type,
48194800
&chain_type,
48204801
&ziplongest_type,
4821-
&pairwise_type,
48224802
&product_type,
48234803
&repeat_type,
48244804
&tee_type,

0 commit comments

Comments
 (0)