12
12
13
13
typedef struct {
14
14
PyTypeObject * accumulate_type ;
15
+ PyTypeObject * chain_type ;
15
16
PyTypeObject * combinations_type ;
16
17
PyTypeObject * compress_type ;
17
18
PyTypeObject * count_type ;
@@ -60,7 +61,7 @@ class itertools.cycle "cycleobject *" "clinic_state()->cycle_type"
60
61
class itertools.dropwhile "dropwhileobject *" "clinic_state()->dropwhile_type"
61
62
class itertools.takewhile "takewhileobject *" "clinic_state()->takewhile_type"
62
63
class itertools.starmap "starmapobject *" "clinic_state()->starmap_type"
63
- class itertools.chain "chainobject *" "& chain_type"
64
+ class itertools.chain "chainobject *" "clinic_state()-> chain_type"
64
65
class itertools.combinations "combinationsobject *" "clinic_state()->combinations_type"
65
66
class itertools.combinations_with_replacement "cwr_object *" "clinic_state()->cwr_type"
66
67
class itertools.permutations "permutationsobject *" "clinic_state()->permutations_type"
@@ -70,7 +71,7 @@ class itertools.filterfalse "filterfalseobject *" "clinic_state()->filterfalse_t
70
71
class itertools.count "countobject *" "clinic_state()->count_type"
71
72
class itertools.pairwise "pairwiseobject *" "clinic_state()->pairwise_type"
72
73
[clinic start generated code]*/
73
- /*[clinic end generated code: output=da39a3ee5e6b4b0d input=28ffff5c0c93eed7 ]*/
74
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=102319065d3e090b ]*/
74
75
75
76
static PyTypeObject teedataobject_type ;
76
77
static PyTypeObject tee_type ;
@@ -2024,8 +2025,6 @@ typedef struct {
2024
2025
PyObject * active ; /* Currently running input iterator */
2025
2026
} chainobject ;
2026
2027
2027
- static PyTypeObject chain_type ;
2028
-
2029
2028
static PyObject *
2030
2029
chain_new_internal (PyTypeObject * type , PyObject * source )
2031
2030
{
@@ -2047,9 +2046,12 @@ chain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2047
2046
{
2048
2047
PyObject * source ;
2049
2048
2050
- if ((type == & chain_type || type -> tp_init == chain_type .tp_init ) &&
2051
- !_PyArg_NoKeywords ("chain" , kwds ))
2049
+ itertools_state * st = find_state_by_type (type );
2050
+ if ((type == st -> chain_type || type -> tp_init == st -> chain_type -> tp_init )
2051
+ && !_PyArg_NoKeywords ("chain" , kwds ))
2052
+ {
2052
2053
return NULL ;
2054
+ }
2053
2055
2054
2056
source = PyObject_GetIter (args );
2055
2057
if (source == NULL )
@@ -2082,15 +2084,18 @@ itertools_chain_from_iterable(PyTypeObject *type, PyObject *arg)
2082
2084
static void
2083
2085
chain_dealloc (chainobject * lz )
2084
2086
{
2087
+ PyTypeObject * tp = Py_TYPE (lz );
2085
2088
PyObject_GC_UnTrack (lz );
2086
2089
Py_XDECREF (lz -> active );
2087
2090
Py_XDECREF (lz -> source );
2088
- Py_TYPE (lz )-> tp_free (lz );
2091
+ tp -> tp_free (lz );
2092
+ Py_DECREF (tp );
2089
2093
}
2090
2094
2091
2095
static int
2092
2096
chain_traverse (chainobject * lz , visitproc visit , void * arg )
2093
2097
{
2098
+ Py_VISIT (Py_TYPE (lz ));
2094
2099
Py_VISIT (lz -> source );
2095
2100
Py_VISIT (lz -> active );
2096
2101
return 0 ;
@@ -2195,48 +2200,24 @@ static PyMethodDef chain_methods[] = {
2195
2200
{NULL , NULL } /* sentinel */
2196
2201
};
2197
2202
2198
- static PyTypeObject chain_type = {
2199
- PyVarObject_HEAD_INIT (NULL , 0 )
2200
- "itertools.chain" , /* tp_name */
2201
- sizeof (chainobject ), /* tp_basicsize */
2202
- 0 , /* tp_itemsize */
2203
- /* methods */
2204
- (destructor )chain_dealloc , /* tp_dealloc */
2205
- 0 , /* tp_vectorcall_offset */
2206
- 0 , /* tp_getattr */
2207
- 0 , /* tp_setattr */
2208
- 0 , /* tp_as_async */
2209
- 0 , /* tp_repr */
2210
- 0 , /* tp_as_number */
2211
- 0 , /* tp_as_sequence */
2212
- 0 , /* tp_as_mapping */
2213
- 0 , /* tp_hash */
2214
- 0 , /* tp_call */
2215
- 0 , /* tp_str */
2216
- PyObject_GenericGetAttr , /* tp_getattro */
2217
- 0 , /* tp_setattro */
2218
- 0 , /* tp_as_buffer */
2219
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
2220
- Py_TPFLAGS_BASETYPE , /* tp_flags */
2221
- chain_doc , /* tp_doc */
2222
- (traverseproc )chain_traverse , /* tp_traverse */
2223
- 0 , /* tp_clear */
2224
- 0 , /* tp_richcompare */
2225
- 0 , /* tp_weaklistoffset */
2226
- PyObject_SelfIter , /* tp_iter */
2227
- (iternextfunc )chain_next , /* tp_iternext */
2228
- chain_methods , /* tp_methods */
2229
- 0 , /* tp_members */
2230
- 0 , /* tp_getset */
2231
- 0 , /* tp_base */
2232
- 0 , /* tp_dict */
2233
- 0 , /* tp_descr_get */
2234
- 0 , /* tp_descr_set */
2235
- 0 , /* tp_dictoffset */
2236
- 0 , /* tp_init */
2237
- 0 , /* tp_alloc */
2238
- chain_new , /* tp_new */
2239
- PyObject_GC_Del , /* tp_free */
2203
+ static PyType_Slot chain_slots [] = {
2204
+ {Py_tp_dealloc , chain_dealloc },
2205
+ {Py_tp_getattro , PyObject_GenericGetAttr },
2206
+ {Py_tp_doc , (void * )chain_doc },
2207
+ {Py_tp_traverse , chain_traverse },
2208
+ {Py_tp_iter , PyObject_SelfIter },
2209
+ {Py_tp_iternext , chain_next },
2210
+ {Py_tp_methods , chain_methods },
2211
+ {Py_tp_new , chain_new },
2212
+ {Py_tp_free , PyObject_GC_Del },
2213
+ {0 , NULL },
2214
+ };
2215
+
2216
+ static PyType_Spec chain_spec = {
2217
+ .name = "itertools.chain" ,
2218
+ .basicsize = sizeof (chainobject ),
2219
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE ,
2220
+ .slots = chain_slots ,
2240
2221
};
2241
2222
2242
2223
@@ -3642,13 +3623,14 @@ accumulate_next(accumulateobject *lz)
3642
3623
static PyObject *
3643
3624
accumulate_reduce (accumulateobject * lz , PyObject * Py_UNUSED (ignored ))
3644
3625
{
3626
+ PyTypeObject * tp = Py_TYPE (lz );
3627
+ itertools_state * state = find_state_by_type (tp );
3628
+
3645
3629
if (lz -> initial != Py_None ) {
3646
3630
PyObject * it ;
3647
3631
3648
3632
assert (lz -> total == NULL );
3649
- if (PyType_Ready (& chain_type ) < 0 )
3650
- return NULL ;
3651
- it = PyObject_CallFunction ((PyObject * )& chain_type , "(O)O" ,
3633
+ it = PyObject_CallFunction ((PyObject * )(state -> chain_type ), "(O)O" ,
3652
3634
lz -> initial , lz -> it );
3653
3635
if (it == NULL )
3654
3636
return NULL ;
@@ -3658,9 +3640,7 @@ accumulate_reduce(accumulateobject *lz, PyObject *Py_UNUSED(ignored))
3658
3640
if (lz -> total == Py_None ) {
3659
3641
PyObject * it ;
3660
3642
3661
- if (PyType_Ready (& chain_type ) < 0 )
3662
- return NULL ;
3663
- it = PyObject_CallFunction ((PyObject * )& chain_type , "(O)O" ,
3643
+ it = PyObject_CallFunction ((PyObject * )(state -> chain_type ), "(O)O" ,
3664
3644
lz -> total , lz -> it );
3665
3645
if (it == NULL )
3666
3646
return NULL ;
@@ -3669,8 +3649,6 @@ accumulate_reduce(accumulateobject *lz, PyObject *Py_UNUSED(ignored))
3669
3649
if (it == NULL )
3670
3650
return NULL ;
3671
3651
3672
- PyTypeObject * tp = Py_TYPE (lz );
3673
- itertools_state * state = find_state_by_type (tp );
3674
3652
return Py_BuildValue ("O(NiO)" , state -> islice_type , it , 1 , Py_None );
3675
3653
}
3676
3654
return Py_BuildValue ("O(OO)O" , Py_TYPE (lz ),
@@ -4642,6 +4620,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4642
4620
{
4643
4621
itertools_state * state = get_module_state (mod );
4644
4622
Py_VISIT (state -> accumulate_type );
4623
+ Py_VISIT (state -> chain_type );
4645
4624
Py_VISIT (state -> combinations_type );
4646
4625
Py_VISIT (state -> compress_type );
4647
4626
Py_VISIT (state -> count_type );
@@ -4666,6 +4645,7 @@ itertoolsmodule_clear(PyObject *mod)
4666
4645
{
4667
4646
itertools_state * state = get_module_state (mod );
4668
4647
Py_CLEAR (state -> accumulate_type );
4648
+ Py_CLEAR (state -> chain_type );
4669
4649
Py_CLEAR (state -> combinations_type );
4670
4650
Py_CLEAR (state -> compress_type );
4671
4651
Py_CLEAR (state -> count_type );
@@ -4707,6 +4687,7 @@ itertoolsmodule_exec(PyObject *mod)
4707
4687
{
4708
4688
itertools_state * state = get_module_state (mod );
4709
4689
ADD_TYPE (mod , state -> accumulate_type , & accumulate_spec );
4690
+ ADD_TYPE (mod , state -> chain_type , & chain_spec );
4710
4691
ADD_TYPE (mod , state -> combinations_type , & combinations_spec );
4711
4692
ADD_TYPE (mod , state -> compress_type , & compress_spec );
4712
4693
ADD_TYPE (mod , state -> count_type , & count_spec );
@@ -4727,7 +4708,6 @@ itertoolsmodule_exec(PyObject *mod)
4727
4708
4728
4709
PyTypeObject * typelist [] = {
4729
4710
& batched_type ,
4730
- & chain_type ,
4731
4711
& tee_type ,
4732
4712
& teedataobject_type
4733
4713
};
0 commit comments