@@ -78,7 +78,7 @@ _testcext_exec(
7878 return 0 ;
7979}
8080
81- #define _FUNC_NAME (NAME ) PyInit_ ## NAME
81+ #define _FUNC_NAME (NAME ) PyModExport_ ## NAME
8282#define FUNC_NAME (NAME ) _FUNC_NAME(NAME)
8383
8484// Converting from function pointer to void* has undefined behavior, but
@@ -88,58 +88,26 @@ _testcext_exec(
8888_Py_COMP_DIAG_PUSH
8989#if defined(__GNUC__ )
9090#pragma GCC diagnostic ignored "-Wpedantic"
91+ #pragma GCC diagnostic ignored "-Wcast-qual"
9192#elif defined(__clang__ )
9293#pragma clang diagnostic ignored "-Wpedantic"
94+ #pragma clang diagnostic ignored "-Wcast-qual"
9395#endif
9496
97+ PyDoc_STRVAR (_testcext_doc , "C test extension." );
98+
9599static PyModuleDef_Slot _testcext_slots [] = {
100+ {Py_mod_name , STR (MODULE_NAME )},
101+ {Py_mod_doc , (void * )(char * )_testcext_doc },
96102 {Py_mod_exec , (void * )_testcext_exec },
103+ {Py_mod_methods , _testcext_methods },
97104 {0 , NULL }
98105};
99106
100107_Py_COMP_DIAG_POP
101108
102- PyDoc_STRVAR (_testcext_doc , "C test extension." );
103-
104- #ifndef _Py_OPAQUE_PYOBJECT
105-
106- static struct PyModuleDef _testcext_module = {
107- PyModuleDef_HEAD_INIT , // m_base
108- STR (MODULE_NAME ), // m_name
109- _testcext_doc , // m_doc
110- 0 , // m_size
111- _testcext_methods , // m_methods
112- _testcext_slots , // m_slots
113- NULL , // m_traverse
114- NULL , // m_clear
115- NULL , // m_free
116- };
117-
118-
119- PyMODINIT_FUNC
120- FUNC_NAME (MODULE_NAME )(void )
121- {
122- return PyModuleDef_Init (& _testcext_module );
123- }
124-
125- #else // _Py_OPAQUE_PYOBJECT
126-
127- // Opaque PyObject means that PyModuleDef is also opaque and cannot be
128- // declared statically. See PEP 793.
129- // So, this part of module creation is split into a separate source file
130- // which uses non-limited API.
131-
132- // (repeated definition to avoid creating a header)
133- extern PyObject * testcext_create_moduledef (
134- const char * name , const char * doc ,
135- PyMethodDef * methods , PyModuleDef_Slot * slots );
136-
137-
138- PyMODINIT_FUNC
109+ PyMODEXPORT_FUNC
139110FUNC_NAME (MODULE_NAME )(void )
140111{
141- return testcext_create_moduledef (
142- STR (MODULE_NAME ), _testcext_doc , _testcext_methods , _testcext_slots );
112+ return _testcext_slots ;
143113}
144-
145- #endif // _Py_OPAQUE_PYOBJECT
0 commit comments