13
13
14
14
typedef struct {
15
15
PyTypeObject * accumulate_type ;
16
+ PyTypeObject * chain_type ;
16
17
PyTypeObject * combinations_type ;
17
18
PyTypeObject * compress_type ;
18
19
PyTypeObject * count_type ;
@@ -69,7 +70,7 @@ class itertools.cycle "cycleobject *" "clinic_state()->cycle_type"
69
70
class itertools.dropwhile "dropwhileobject *" "clinic_state()->dropwhile_type"
70
71
class itertools.takewhile "takewhileobject *" "clinic_state()->takewhile_type"
71
72
class itertools.starmap "starmapobject *" "clinic_state()->starmap_type"
72
- class itertools.chain "chainobject *" "& chain_type"
73
+ class itertools.chain "chainobject *" "clinic_state()-> chain_type"
73
74
class itertools.combinations "combinationsobject *" "clinic_state()->combinations_type"
74
75
class itertools.combinations_with_replacement "cwr_object *" "clinic_state()->cwr_type"
75
76
class itertools.permutations "permutationsobject *" "clinic_state()->permutations_type"
@@ -79,7 +80,7 @@ class itertools.filterfalse "filterfalseobject *" "clinic_state()->filterfalse_t
79
80
class itertools.count "countobject *" "clinic_state()->count_type"
80
81
class itertools.pairwise "pairwiseobject *" "clinic_state()->pairwise_type"
81
82
[clinic start generated code]*/
82
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=28ffff5c0c93eed7 ]*/
83
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=102319065d3e090b ]*/
83
84
84
85
static PyTypeObject teedataobject_type ;
85
86
static PyTypeObject tee_type ;
@@ -2038,8 +2039,6 @@ typedef struct {
2038
2039
PyObject * active ; /* Currently running input iterator */
2039
2040
} chainobject ;
2040
2041
2041
- static PyTypeObject chain_type ;
2042
-
2043
2042
static PyObject *
2044
2043
chain_new_internal (PyTypeObject * type , PyObject * source )
2045
2044
{
@@ -2061,9 +2060,12 @@ chain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2061
2060
{
2062
2061
PyObject * source ;
2063
2062
2064
- if ((type == & chain_type || type -> tp_init == chain_type .tp_init ) &&
2065
- !_PyArg_NoKeywords ("chain" , kwds ))
2063
+ itertools_state * st = find_state_by_type (type );
2064
+ if ((type == st -> chain_type || type -> tp_init == st -> chain_type -> tp_init )
2065
+ && !_PyArg_NoKeywords ("chain" , kwds ))
2066
+ {
2066
2067
return NULL ;
2068
+ }
2067
2069
2068
2070
source = PyObject_GetIter (args );
2069
2071
if (source == NULL )
@@ -2096,15 +2098,18 @@ itertools_chain_from_iterable(PyTypeObject *type, PyObject *arg)
2096
2098
static void
2097
2099
chain_dealloc (chainobject * lz )
2098
2100
{
2101
+ PyTypeObject * tp = Py_TYPE (lz );
2099
2102
PyObject_GC_UnTrack (lz );
2100
2103
Py_XDECREF (lz -> active );
2101
2104
Py_XDECREF (lz -> source );
2102
- Py_TYPE (lz )-> tp_free (lz );
2105
+ tp -> tp_free (lz );
2106
+ Py_DECREF (tp );
2103
2107
}
2104
2108
2105
2109
static int
2106
2110
chain_traverse (chainobject * lz , visitproc visit , void * arg )
2107
2111
{
2112
+ Py_VISIT (Py_TYPE (lz ));
2108
2113
Py_VISIT (lz -> source );
2109
2114
Py_VISIT (lz -> active );
2110
2115
return 0 ;
@@ -2209,48 +2214,24 @@ static PyMethodDef chain_methods[] = {
2209
2214
{NULL , NULL } /* sentinel */
2210
2215
};
2211
2216
2212
- static PyTypeObject chain_type = {
2213
- PyVarObject_HEAD_INIT (NULL , 0 )
2214
- "itertools.chain" , /* tp_name */
2215
- sizeof (chainobject ), /* tp_basicsize */
2216
- 0 , /* tp_itemsize */
2217
- /* methods */
2218
- (destructor )chain_dealloc , /* tp_dealloc */
2219
- 0 , /* tp_vectorcall_offset */
2220
- 0 , /* tp_getattr */
2221
- 0 , /* tp_setattr */
2222
- 0 , /* tp_as_async */
2223
- 0 , /* tp_repr */
2224
- 0 , /* tp_as_number */
2225
- 0 , /* tp_as_sequence */
2226
- 0 , /* tp_as_mapping */
2227
- 0 , /* tp_hash */
2228
- 0 , /* tp_call */
2229
- 0 , /* tp_str */
2230
- PyObject_GenericGetAttr , /* tp_getattro */
2231
- 0 , /* tp_setattro */
2232
- 0 , /* tp_as_buffer */
2233
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
2234
- Py_TPFLAGS_BASETYPE , /* tp_flags */
2235
- chain_doc , /* tp_doc */
2236
- (traverseproc )chain_traverse , /* tp_traverse */
2237
- 0 , /* tp_clear */
2238
- 0 , /* tp_richcompare */
2239
- 0 , /* tp_weaklistoffset */
2240
- PyObject_SelfIter , /* tp_iter */
2241
- (iternextfunc )chain_next , /* tp_iternext */
2242
- chain_methods , /* tp_methods */
2243
- 0 , /* tp_members */
2244
- 0 , /* tp_getset */
2245
- 0 , /* tp_base */
2246
- 0 , /* tp_dict */
2247
- 0 , /* tp_descr_get */
2248
- 0 , /* tp_descr_set */
2249
- 0 , /* tp_dictoffset */
2250
- 0 , /* tp_init */
2251
- 0 , /* tp_alloc */
2252
- chain_new , /* tp_new */
2253
- PyObject_GC_Del , /* tp_free */
2217
+ static PyType_Slot chain_slots [] = {
2218
+ {Py_tp_dealloc , chain_dealloc },
2219
+ {Py_tp_getattro , PyObject_GenericGetAttr },
2220
+ {Py_tp_doc , (void * )chain_doc },
2221
+ {Py_tp_traverse , chain_traverse },
2222
+ {Py_tp_iter , PyObject_SelfIter },
2223
+ {Py_tp_iternext , chain_next },
2224
+ {Py_tp_methods , chain_methods },
2225
+ {Py_tp_new , chain_new },
2226
+ {Py_tp_free , PyObject_GC_Del },
2227
+ {0 , NULL },
2228
+ };
2229
+
2230
+ static PyType_Spec chain_spec = {
2231
+ .name = "itertools.chain" ,
2232
+ .basicsize = sizeof (chainobject ),
2233
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE ,
2234
+ .slots = chain_slots ,
2254
2235
};
2255
2236
2256
2237
@@ -3656,13 +3637,14 @@ accumulate_next(accumulateobject *lz)
3656
3637
static PyObject *
3657
3638
accumulate_reduce (accumulateobject * lz , PyObject * Py_UNUSED (ignored ))
3658
3639
{
3640
+ PyTypeObject * tp = Py_TYPE (lz );
3641
+ itertools_state * state = find_state_by_type (tp );
3642
+
3659
3643
if (lz -> initial != Py_None ) {
3660
3644
PyObject * it ;
3661
3645
3662
3646
assert (lz -> total == NULL );
3663
- if (PyType_Ready (& chain_type ) < 0 )
3664
- return NULL ;
3665
- it = PyObject_CallFunction ((PyObject * )& chain_type , "(O)O" ,
3647
+ it = PyObject_CallFunction ((PyObject * )(state -> chain_type ), "(O)O" ,
3666
3648
lz -> initial , lz -> it );
3667
3649
if (it == NULL )
3668
3650
return NULL ;
@@ -3672,9 +3654,7 @@ accumulate_reduce(accumulateobject *lz, PyObject *Py_UNUSED(ignored))
3672
3654
if (lz -> total == Py_None ) {
3673
3655
PyObject * it ;
3674
3656
3675
- if (PyType_Ready (& chain_type ) < 0 )
3676
- return NULL ;
3677
- it = PyObject_CallFunction ((PyObject * )& chain_type , "(O)O" ,
3657
+ it = PyObject_CallFunction ((PyObject * )(state -> chain_type ), "(O)O" ,
3678
3658
lz -> total , lz -> it );
3679
3659
if (it == NULL )
3680
3660
return NULL ;
@@ -3683,8 +3663,6 @@ accumulate_reduce(accumulateobject *lz, PyObject *Py_UNUSED(ignored))
3683
3663
if (it == NULL )
3684
3664
return NULL ;
3685
3665
3686
- PyTypeObject * tp = Py_TYPE (lz );
3687
- itertools_state * state = find_state_by_type (tp );
3688
3666
return Py_BuildValue ("O(NiO)" , state -> islice_type , it , 1 , Py_None );
3689
3667
}
3690
3668
return Py_BuildValue ("O(OO)O" , Py_TYPE (lz ),
@@ -4656,6 +4634,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4656
4634
{
4657
4635
itertools_state * state = get_module_state (mod );
4658
4636
Py_VISIT (state -> accumulate_type );
4637
+ Py_VISIT (state -> chain_type );
4659
4638
Py_VISIT (state -> combinations_type );
4660
4639
Py_VISIT (state -> compress_type );
4661
4640
Py_VISIT (state -> count_type );
@@ -4681,6 +4660,7 @@ itertoolsmodule_clear(PyObject *mod)
4681
4660
{
4682
4661
itertools_state * state = get_module_state (mod );
4683
4662
Py_CLEAR (state -> accumulate_type );
4663
+ Py_CLEAR (state -> chain_type );
4684
4664
Py_CLEAR (state -> combinations_type );
4685
4665
Py_CLEAR (state -> compress_type );
4686
4666
Py_CLEAR (state -> count_type );
@@ -4723,6 +4703,7 @@ itertoolsmodule_exec(PyObject *mod)
4723
4703
{
4724
4704
itertools_state * state = get_module_state (mod );
4725
4705
ADD_TYPE (mod , state -> accumulate_type , & accumulate_spec );
4706
+ ADD_TYPE (mod , state -> chain_type , & chain_spec );
4726
4707
ADD_TYPE (mod , state -> combinations_type , & combinations_spec );
4727
4708
ADD_TYPE (mod , state -> compress_type , & compress_spec );
4728
4709
ADD_TYPE (mod , state -> count_type , & count_spec );
@@ -4743,7 +4724,6 @@ itertoolsmodule_exec(PyObject *mod)
4743
4724
4744
4725
PyTypeObject * typelist [] = {
4745
4726
& batched_type ,
4746
- & chain_type ,
4747
4727
& tee_type ,
4748
4728
& teedataobject_type
4749
4729
};
0 commit comments