@@ -2813,48 +2813,29 @@ static struct PyMethodDef _testbuffer_functions[] = {
2813
2813
{NULL , NULL }
2814
2814
};
2815
2815
2816
- static struct PyModuleDef _testbuffermodule = {
2817
- PyModuleDef_HEAD_INIT ,
2818
- "_testbuffer" ,
2819
- NULL ,
2820
- -1 ,
2821
- _testbuffer_functions ,
2822
- NULL ,
2823
- NULL ,
2824
- NULL ,
2825
- NULL
2826
- };
2827
-
2828
-
2829
- PyMODINIT_FUNC
2830
- PyInit__testbuffer (void )
2816
+ static int
2817
+ _testbuffer_exec (PyObject * m )
2831
2818
{
2832
- PyObject * m ;
2833
-
2834
- m = PyModule_Create (& _testbuffermodule );
2835
- if (m == NULL )
2836
- return NULL ;
2837
-
2838
- Py_SET_TYPE (& NDArray_Type , & PyType_Type );
2839
- Py_INCREF (& NDArray_Type );
2840
- PyModule_AddObject (m , "ndarray" , (PyObject * )& NDArray_Type );
2819
+ if (PyModule_AddType (m , & NDArray_Type ) < 0 ) {
2820
+ return -1 ;
2821
+ }
2841
2822
2842
- Py_SET_TYPE ( & StaticArray_Type , & PyType_Type );
2843
- Py_INCREF ( & StaticArray_Type ) ;
2844
- PyModule_AddObject ( m , "staticarray" , ( PyObject * ) & StaticArray_Type );
2823
+ if ( PyModule_AddType ( m , & StaticArray_Type ) < 0 ) {
2824
+ return -1 ;
2825
+ }
2845
2826
2846
2827
structmodule = PyImport_ImportModule ("struct" );
2847
2828
if (structmodule == NULL )
2848
- return NULL ;
2829
+ return -1 ;
2849
2830
2850
2831
Struct = PyObject_GetAttrString (structmodule , "Struct" );
2851
2832
calcsize = PyObject_GetAttrString (structmodule , "calcsize" );
2852
2833
if (Struct == NULL || calcsize == NULL )
2853
- return NULL ;
2834
+ return -1 ;
2854
2835
2855
2836
simple_format = PyUnicode_FromString (simple_fmt );
2856
2837
if (simple_format == NULL )
2857
- return NULL ;
2838
+ return -1 ;
2858
2839
2859
2840
PyModule_AddIntMacro (m , ND_MAX_NDIM );
2860
2841
PyModule_AddIntMacro (m , ND_VAREXPORT );
@@ -2887,8 +2868,24 @@ PyInit__testbuffer(void)
2887
2868
PyModule_AddIntMacro (m , PyBUF_READ );
2888
2869
PyModule_AddIntMacro (m , PyBUF_WRITE );
2889
2870
2890
- return m ;
2871
+ return 0 ;
2891
2872
}
2892
2873
2874
+ static PyModuleDef_Slot _testbuffer_slots [] = {
2875
+ {Py_mod_exec , _testbuffer_exec },
2876
+ {0 , NULL }
2877
+ };
2893
2878
2879
+ static struct PyModuleDef _testbuffermodule = {
2880
+ PyModuleDef_HEAD_INIT ,
2881
+ .m_name = "_testbuffer" ,
2882
+ .m_size = 0 ,
2883
+ .m_methods = _testbuffer_functions ,
2884
+ .m_slots = _testbuffer_slots
2885
+ };
2894
2886
2887
+ PyMODINIT_FUNC
2888
+ PyInit__testbuffer (void )
2889
+ {
2890
+ return PyModuleDef_Init (& _testbuffermodule );
2891
+ }
0 commit comments