@@ -24,6 +24,7 @@ typedef struct {
24
24
PyTypeObject * _grouper_type ;
25
25
PyTypeObject * pairwise_type ;
26
26
PyTypeObject * permutations_type ;
27
+ PyTypeObject * product_type ;
27
28
PyTypeObject * starmap_type ;
28
29
PyTypeObject * takewhile_type ;
29
30
PyTypeObject * ziplongest_type ;
@@ -2281,8 +2282,6 @@ typedef struct {
2281
2282
int stopped ; /* set to 1 when the iterator is exhausted */
2282
2283
} productobject ;
2283
2284
2284
- static PyTypeObject product_type ;
2285
-
2286
2285
static PyObject *
2287
2286
product_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
2288
2287
{
@@ -2369,12 +2368,14 @@ product_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2369
2368
static void
2370
2369
product_dealloc (productobject * lz )
2371
2370
{
2371
+ PyTypeObject * tp = Py_TYPE (lz );
2372
2372
PyObject_GC_UnTrack (lz );
2373
2373
Py_XDECREF (lz -> pools );
2374
2374
Py_XDECREF (lz -> result );
2375
2375
if (lz -> indices != NULL )
2376
2376
PyMem_Free (lz -> indices );
2377
- Py_TYPE (lz )-> tp_free (lz );
2377
+ tp -> tp_free (lz );
2378
+ Py_DECREF (tp );
2378
2379
}
2379
2380
2380
2381
static PyObject *
@@ -2390,6 +2391,7 @@ PyDoc_STRVAR(sizeof_doc, "Returns size in memory, in bytes.");
2390
2391
static int
2391
2392
product_traverse (productobject * lz , visitproc visit , void * arg )
2392
2393
{
2394
+ Py_VISIT (Py_TYPE (lz ));
2393
2395
Py_VISIT (lz -> pools );
2394
2396
Py_VISIT (lz -> result );
2395
2397
return 0 ;
@@ -2581,48 +2583,25 @@ product(A, repeat=4) means the same as product(A, A, A, A).\n\n\
2581
2583
product('ab', range(3)) --> ('a',0) ('a',1) ('a',2) ('b',0) ('b',1) ('b',2)\n\
2582
2584
product((0,1), (0,1), (0,1)) --> (0,0,0) (0,0,1) (0,1,0) (0,1,1) (1,0,0) ..." );
2583
2585
2584
- static PyTypeObject product_type = {
2585
- PyVarObject_HEAD_INIT (NULL , 0 )
2586
- "itertools.product" , /* tp_name */
2587
- sizeof (productobject ), /* tp_basicsize */
2588
- 0 , /* tp_itemsize */
2589
- /* methods */
2590
- (destructor )product_dealloc , /* tp_dealloc */
2591
- 0 , /* tp_vectorcall_offset */
2592
- 0 , /* tp_getattr */
2593
- 0 , /* tp_setattr */
2594
- 0 , /* tp_as_async */
2595
- 0 , /* tp_repr */
2596
- 0 , /* tp_as_number */
2597
- 0 , /* tp_as_sequence */
2598
- 0 , /* tp_as_mapping */
2599
- 0 , /* tp_hash */
2600
- 0 , /* tp_call */
2601
- 0 , /* tp_str */
2602
- PyObject_GenericGetAttr , /* tp_getattro */
2603
- 0 , /* tp_setattro */
2604
- 0 , /* tp_as_buffer */
2605
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
2606
- Py_TPFLAGS_BASETYPE , /* tp_flags */
2607
- product_doc , /* tp_doc */
2608
- (traverseproc )product_traverse , /* tp_traverse */
2609
- 0 , /* tp_clear */
2610
- 0 , /* tp_richcompare */
2611
- 0 , /* tp_weaklistoffset */
2612
- PyObject_SelfIter , /* tp_iter */
2613
- (iternextfunc )product_next , /* tp_iternext */
2614
- product_methods , /* tp_methods */
2615
- 0 , /* tp_members */
2616
- 0 , /* tp_getset */
2617
- 0 , /* tp_base */
2618
- 0 , /* tp_dict */
2619
- 0 , /* tp_descr_get */
2620
- 0 , /* tp_descr_set */
2621
- 0 , /* tp_dictoffset */
2622
- 0 , /* tp_init */
2623
- 0 , /* tp_alloc */
2624
- product_new , /* tp_new */
2625
- PyObject_GC_Del , /* tp_free */
2586
+ static PyType_Slot product_slots [] = {
2587
+ {Py_tp_dealloc , product_dealloc },
2588
+ {Py_tp_getattro , PyObject_GenericGetAttr },
2589
+ {Py_tp_doc , (void * )product_doc },
2590
+ {Py_tp_traverse , product_traverse },
2591
+ {Py_tp_iter , PyObject_SelfIter },
2592
+ {Py_tp_iternext , product_next },
2593
+ {Py_tp_methods , product_methods },
2594
+ {Py_tp_new , product_new },
2595
+ {Py_tp_free , PyObject_GC_Del },
2596
+ {0 , NULL },
2597
+ };
2598
+
2599
+ static PyType_Spec product_spec = {
2600
+ .name = "itertools.product" ,
2601
+ .basicsize = sizeof (productobject ),
2602
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
2603
+ Py_TPFLAGS_IMMUTABLETYPE ),
2604
+ .slots = product_slots ,
2626
2605
};
2627
2606
2628
2607
@@ -4727,6 +4706,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4727
4706
Py_VISIT (state -> _grouper_type );
4728
4707
Py_VISIT (state -> pairwise_type );
4729
4708
Py_VISIT (state -> permutations_type );
4709
+ Py_VISIT (state -> product_type );
4730
4710
Py_VISIT (state -> starmap_type );
4731
4711
Py_VISIT (state -> takewhile_type );
4732
4712
Py_VISIT (state -> ziplongest_type );
@@ -4749,6 +4729,7 @@ itertoolsmodule_clear(PyObject *mod)
4749
4729
Py_CLEAR (state -> _grouper_type );
4750
4730
Py_CLEAR (state -> pairwise_type );
4751
4731
Py_CLEAR (state -> permutations_type );
4732
+ Py_CLEAR (state -> product_type );
4752
4733
Py_CLEAR (state -> starmap_type );
4753
4734
Py_CLEAR (state -> takewhile_type );
4754
4735
Py_CLEAR (state -> ziplongest_type );
@@ -4788,6 +4769,7 @@ itertoolsmodule_exec(PyObject *mod)
4788
4769
ADD_TYPE (mod , state -> _grouper_type , & _grouper_spec );
4789
4770
ADD_TYPE (mod , state -> pairwise_type , & pairwise_spec );
4790
4771
ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
4772
+ ADD_TYPE (mod , state -> product_type , & product_spec );
4791
4773
ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
4792
4774
ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4793
4775
ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
@@ -4796,7 +4778,6 @@ itertoolsmodule_exec(PyObject *mod)
4796
4778
& batched_type ,
4797
4779
& islice_type ,
4798
4780
& chain_type ,
4799
- & product_type ,
4800
4781
& repeat_type ,
4801
4782
& tee_type ,
4802
4783
& teedataobject_type
0 commit comments