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