8000 gh-101277: Add pairwise type to module state · python/cpython@fb0e18d · GitHub
[go: up one dir, main page]

Skip to content

Commit fb0e18d

Browse files
gh-101277: Add pairwise type to module state
1 parent ecb447f commit fb0e18d

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

Modules/clinic/itertoolsmodule.c.h

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

Modules/itertoolsmodule.c

Lines changed: 29 additions & 47 deletions
< 6D40 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef struct {
2222
PyTypeObject *filterfalse_type;
2323
PyTypeObject *groupby_type;
2424
PyTypeObject *_grouper_type;
25+
PyTypeObject *pairwise_type;
2526
PyTypeObject *permutations_type;
2627
PyTypeObject *starmap_type;
2728
PyTypeObject *takewhile_type;
@@ -73,14 +74,13 @@ class itertools.accumulate "accumulateobject *" "clinic_state()->accumulate_type
7374
class itertools.compress "compressobject *" "clinic_state()->compress_type"
7475
class itertools.filterfalse "filterfalseobject *" "clinic_state()->filterfalse_type"
7576
class itertools.count "countobject *" "clinic_state()->count_type"
76-
class itertools.pairwise "pairwiseobject *" "&pairwise_type"
77+
class itertools.pairwise "pairwiseobject *" "clinic_state()->pairwise_type"
7778
[clinic start generated code]*/
78-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=338b4d26465f3eb1]*/
79+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=28ffff5c0c93eed7]*/
7980

8081
static PyTypeObject teedataobject_type;
8182
static PyTypeObject tee_type;
8283
static PyTypeObject batched_type;
83-
static PyTypeObject pairwise_type;
8484

8585
#define clinic_state_by_cls() (get_module_state_by_cls(base_tp))
8686
#include "clinic/itertoolsmodule.c.h"
@@ -308,15 +308,18 @@ pairwise_new_impl(PyTypeObject *type, PyObject *iterable)
308308
static void
309309
pairwise_dealloc(pairwiseobject *po)
310310
{
311+
PyTypeObject *tp = Py_TYPE(po);
311312
PyObject_GC_UnTrack(po);
312313
Py_XDECREF(po->it);
313314
Py_XDECREF(po->old);
314-
Py_TYPE(po)->tp_free(po);
315+
tp->tp_free(po);
316+
Py_DECREF(tp);
315317
}
316318

317319
static int
318320
pairwise_traverse(pairwiseobject *po, visitproc visit, void *arg)
319321
{
322+
Py_VISIT(Py_TYPE(po));
320323
Py_VISIT(po->it);
321324
Py_VISIT(po->old);
322325
return 0;
@@ -351,48 +354,25 @@ pairwise_next(pairwiseobject *po)
351354
return result;
352355
}
353356

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

398378

@@ -4766,6 +4746,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
47664746
Py_VISIT(state->filterfalse_type);
47674747
Py_VISIT(state->groupby_type);
47684748
Py_VISIT(state->_grouper_type);
4749+
Py_VISIT(state->pairwise_type);
47694750
Py_VISIT(state->permutations_type);
47704751
Py_VISIT(state->starmap_type);
47714752
Py_VISIT(state->takewhile_type);
@@ -4786,6 +4767,7 @@ itertoolsmodule_clear(PyObject *mod)
47864767
Py_CLEAR(state->filterfalse_type);
47874768
Py_CLEAR(state->groupby_type);
47884769
Py_CLEAR(state->_grouper_type);
4770+
Py_CLEAR(state->pairwise_type);
47894771
Py_CLEAR(state->permutations_type);
47904772
Py_CLEAR(state->starmap_type);
47914773
Py_CLEAR(state->takewhile_type);
@@ -4823,6 +4805,7 @@ itertoolsmodule_exec(PyObject *mod)
48234805
ADD_TYPE(mod, state->filterfalse_type, &filterfalse_spec);
48244806
ADD_TYPE(mod, state->groupby_type, &groupby_spec);
48254807
ADD_TYPE(mod, state->_grouper_type, &_grouper_spec);
4808+
ADD_TYPE(mod, state->pairwise_type, &pairwise_spec);
48264809
ADD_TYPE(mod, state->permutations_type, &permutations_spec);
48274810
ADD_TYPE(mod, state->starmap_type, &starmap_spec);
48284811
ADD_TYPE(mod, state->takewhile_type, &takewhile_spec);
@@ -4832,7 +4815,6 @@ itertoolsmodule_exec(PyObject *mod)
48324815
&islice_type,
48334816
&chain_type,
48344817
&ziplongest_type,
4835-
&pairwise_type,
48364818
&product_type,
48374819
&repeat_type,
48384820
&tee_type,

0 commit comments

Comments
 (0)
0