@@ -2546,24 +2546,56 @@ static PyTypeObject tuplegetter_type = {
2546
2546
2547
2547
/* module level code ********************************************************/
2548
2548
2549
- PyDoc_STRVAR (module_doc ,
2549
+ PyDoc_STRVAR (collections_doc ,
2550
2550
"High performance data structures.\n\
2551
2551
- deque: ordered collection accessible from endpoints only\n\
2552
2552
- defaultdict: dict subclass with a default value factory\n\
2553
2553
" );
2554
2554
2555
- static struct PyMethodDef module_functions [] = {
2555
+ static struct PyMethodDef collections_methods [] = {
2556
2556
_COLLECTIONS__COUNT_ELEMENTS_METHODDEF
2557
2557
{NULL , NULL } /* sentinel */
2558
2558
};
2559
2559
2560
+ static int
2561
+ collections_exec (PyObject * m ) {
2562
+ PyTypeObject * typelist [] = {
2563
+ & deque_type ,
2564
+ & defdict_type ,
2565
+ & PyODict_Type ,
2566
+ & dequeiter_type ,
2567
+ & dequereviter_type ,
2568
+ & tuplegetter_type ,
2569
+ };
2570
+
2571
+ for (int i = 0 ; typelist [i ] != NULL ; i ++ ) {
2572
+ PyTypeObject * type = typelist [i ];
2573
+ if (PyType_Ready (type ) < 0 ) {
2574
+ return -1 ;
2575
+ }
2576
+ const char * name = _PyType_Name (type );
2577
+ Py_INCREF (type );
2578
+ if (PyModule_AddObject (m , name , (PyObject * )type ) < 0 ) {
2579
+ Py_DECREF (type );
2580
+ return -1 ;
2581
+ }
2582
+ }
2583
+
2584
+ return 0 ;
2585
+ }
2586
+
2587
+ static struct PyModuleDef_Slot collections_slots [] = {
2588
+ {Py_mod_exec , collections_exec },
2589
+ {0 , NULL }
2590
+ };
2591
+
2560
2592
static struct PyModuleDef _collectionsmodule = {
2561
2593
PyModuleDef_HEAD_INIT ,
2562
2594
"_collections" ,
2563
- module_doc ,
2564
- -1 ,
2565
- module_functions ,
2566
- NULL ,
2595
+ collections_doc ,
2596
+ 0 ,
2597
+ collections_methods ,
2598
+ collections_slots ,
2567
2599
NULL ,
2568
2600
NULL ,
2569
2601
NULL
@@ -2572,40 +2604,5 @@ static struct PyModuleDef _collectionsmodule = {
2572
2604
PyMODINIT_FUNC
2573
2605
PyInit__collections (void )
2574
2606
{
2575
- PyObject * m ;
2576
-
2577
- m = PyModule_Create (& _collectionsmodule );
2578
- if (m == NULL )
2579
- return NULL ;
2580
-
2581
- if (PyType_Ready (& deque_type ) < 0 )
2582
- return NULL ;
2583
- Py_INCREF (& deque_type );
2584
- PyModule_AddObject (m , "deque" , (PyObject * )& deque_type );
2585
-
2586
- defdict_type .tp_base = & PyDict_Type ;
2587
- if (PyType_Ready (& defdict_type ) < 0 )
2588
- return NULL ;
2589
- Py_INCREF (& defdict_type );
2590
- PyModule_AddObject (m , "defaultdict" , (PyObject * )& defdict_type );
2591
-
2592
- Py_INCREF (& PyODict_Type );
2593
- PyModule_AddObject (m , "OrderedDict" , (PyObject * )& PyODict_Type );
2594
-
2595
- if (PyType_Ready (& dequeiter_type ) < 0 )
2596
- return NULL ;
2597
- Py_INCREF (& dequeiter_type );
2598
- PyModule_AddObject (m , "_deque_iterator" , (PyObject * )& dequeiter_type );
2599
-
2600
- if (PyType_Ready (& dequereviter_type ) < 0 )
2601
- return NULL ;
2602
- Py_INCREF (& dequereviter_type );
2603
- PyModule_AddObject (m , "_deque_reverse_iterator" , (PyObject * )& dequereviter_type );
2604
-
2605
- if (PyType_Ready (& tuplegetter_type ) < 0 )
2606
- return NULL ;
2607
- Py_INCREF (& tuplegetter_type );
2608
- PyModule_AddObject (m , "_tuplegetter" , (PyObject * )& tuplegetter_type );
2609
-
2610
- return m ;
2607
+ return PyModuleDef_Init (& _collectionsmodule );
2611
2608
}
0 commit comments