@@ -23,6 +23,7 @@ typedef struct {
23
23
PyTypeObject * _grouper_type ;
24
24
PyTypeObject * pairwise_type ;
25
25
PyTypeObject * permutations_type ;
26
+ PyTypeObject * product_type ;
26
27
PyTypeObject * starmap_type ;
27
28
PyTypeObject * takewhile_type ;
28
29
PyTypeObject * ziplongest_type ;
@@ -2268,8 +2269,6 @@ typedef struct {
2268
2269
int stopped ; /* set to 1 when the iterator is exhausted */
2269
2270
} productobject ;
2270
2271
2271
- static PyTypeObject product_type ;
2272
-
2273
2272
static PyObject *
2274
2273
product_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
2275
2274
{
@@ -2356,12 +2355,14 @@ product_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2356
2355
static void
2357
2356
product_dealloc (productobject * lz )
2358
2357
{
2358
+ PyTypeObject * tp = Py_TYPE (lz );
2359
2359
PyObject_GC_UnTrack (lz );
2360
2360
Py_XDECREF (lz -> pools );
2361
2361
Py_XDECREF (lz -> result );
2362
2362
if (lz -> indices != NULL )
2363
2363
PyMem_Free (lz -> indices );
2364
- Py_TYPE (lz )-> tp_free (lz );
2364
+ tp -> tp_free (lz );
2365
+ Py_DECREF (tp );
2365
2366
}
2366
2367
2367
2368
static PyObject *
@@ -2377,6 +2378,7 @@ PyDoc_STRVAR(sizeof_doc, "Returns size in memory, in bytes.");
2377
2378
static int
2378
2379
product_traverse (productobject * lz , visitproc visit , void * arg )
2379
2380
{
2381
+ Py_VISIT (Py_TYPE (lz ));
2380
2382
Py_VISIT (lz -> pools );
2381
2383
Py_VISIT (lz -> result );
2382
2384
return 0 ;
@@ -2568,48 +2570,25 @@ product(A, repeat=4) means the same as product(A, A, A, A).\n\n\
2568
2570
product('ab', range(3)) --> ('a',0) ('a',1) ('a',2) ('b',0) ('b',1) ('b',2)\n\
2569
2571
product((0,1), (0,1), (0,1)) --> (0,0,0) (0,0,1) (0,1,0) (0,1,1) (1,0,0) ..." );
2570
2572
2571
- static PyTypeObject product_type = {
2572
- PyVarObject_HEAD_INIT (NULL , 0 )
2573
- "itertools.product" , /* tp_name */
2574
- sizeof (productobject ), /* tp_basicsize */
2575
- 0 , /* tp_itemsize */
2576
- /* methods */
2577
- (destructor )product_dealloc , /* tp_dealloc */
2578
- 0 , /* tp_vectorcall_offset */
2579
- 0 , /* tp_getattr */
2580
- 0 , /* tp_setattr */
2581
- 0 , /* tp_as_async */
2582
- 0 , /* tp_repr */
2583
- 0 , /* tp_as_number */
2584
- 0 , /* tp_as_sequence */
2585
- 0 , /* tp_as_mapping */
2586
- 0 , /* tp_hash */
2587
- 0 , /* tp_call */
2588
- 0 , /* tp_str */
2589
- PyObject_GenericGetAttr , /* tp_getattro */
2590
- 0 , /* tp_setattro */
2591
- 0 , /* tp_as_buffer */
2592
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
2593
- Py_TPFLAGS_BASETYPE , /* tp_flags */
2594
- product_doc , /* tp_doc */
2595
- (traverseproc )product_traverse , /* tp_traverse */
2596
- 0 , /* tp_clear */
2597
- 0 , /* tp_richcompare */
2598
- 0 , /* tp_weaklistoffset */
2599
- PyObject_SelfIter , /* tp_iter */
2600
- (iternextfunc )product_next , /* tp_iternext */
2601
- product_methods , /* tp_methods */
2602
- 0 , /* tp_members */
2603
- 0 , /* tp_getset */
2604
- 0 , /* tp_base */
2605
- 0 , /* tp_dict */
2606
- 0 , /* tp_descr_get */
2607
- 0 , /* tp_descr_set */
2608
- 0 , /* tp_dictoffset */
2609
- 0 , /* tp_init */
2610
- 0 , /* tp_alloc */
2611
- product_new , /* tp_new */
2612
- PyObject_GC_Del , /* tp_free */
2573
+ static PyType_Slot product_slots [] = {
2574
+ {Py_tp_dealloc , product_dealloc },
2575
+ {Py_tp_getattro , PyObject_GenericGetAttr },
2576
+ {Py_tp_doc , (void * )product_doc },
2577
+ {Py_tp_traverse , product_traverse },
2578
+ {Py_tp_iter , PyObject_SelfIter },
2579
+ {Py_tp_iternext , product_next },
2580
+ {Py_tp_methods , product_methods },
2581
+ {Py_tp_new , product_new },
2582
+ {Py_tp_free , PyObject_GC_Del },
2583
+ {0 , NULL },
2584
+ };
2585
+
2586
+ static PyType_Spec product_spec = {
2587
+ .name = "itertools.product" ,
2588
+ .basicsize = sizeof (productobject ),
2589
+ .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
2590
+ Py_TPFLAGS_IMMUTABLETYPE ),
2591
+ .slots = product_slots ,
2613
2592
};
2614
2593
2615
2594
@@ -4714,6 +4693,7 @@ itertoolsmodule_traverse(PyObject *mod, visitproc visit, void *arg)
4714
4693
Py_VISIT (state -> _grouper_type );
4715
4694
Py_VISIT (state -> pairwise_type );
4716
4695
Py_VISIT (state -> permutations_type );
4696
+ Py_VISIT (state -> product_type );
4717
4697
Py_VISIT (state -> starmap_type );
4718
4698
Py_VISIT (state -> takewhile_type );
4719
4699
Py_VISIT (state -> ziplongest_type );
@@ -4736,6 +4716,7 @@ itertoolsmodule_clear(PyObject *mod)
4736
4716
Py_CLEAR (state -> _grouper_type );
4737
4717
Py_CLEAR (state -> pairwise_type );
4738
4718
Py_CLEAR (state -> permutations_type );
4719
+ Py_CLEAR (state -> product_type );
4739
4720
Py_CLEAR (state -> starmap_type );
4740
4721
Py_CLEAR (state -> takewhile_type );
4741
4722
Py_CLEAR (state -> ziplongest_type );
@@ -4775,6 +4756,7 @@ itertoolsmodule_exec(PyObject *mod)
4775
4756
ADD_TYPE (mod , state -> _grouper_type , & _grouper_spec );
4776
4757
ADD_TYPE (mod , state -> pairwise_type , & pairwise_spec );
4777
4758
ADD_TYPE (mod , state -> permutations_type , & permutations_spec );
4759
+ ADD_TYPE (mod , state -> product_type , & product_spec );
4778
4760
ADD_TYPE (mod , state -> starmap_type , & starmap_spec );
4779
4761
ADD_TYPE (mod , state -> takewhile_type , & takewhile_spec );
4780
4762
ADD_TYPE (mod , state -> ziplongest_type , & ziplongest_spec );
@@ -4783,7 +4765,6 @@ itertoolsmodule_exec(PyObject *mod)
4783
4765
& batched_type ,
4784
4766
& islice_type ,
4785
4767
& chain_type ,
4786
- & product_type ,
4787
4768
& repeat_type ,
4788
4769
& tee_type ,
4789
4770
& teedataobject_type
0 commit comments