diff options
Diffstat (limited to 'Modules/xxmodule.c')
-rw-r--r-- | Modules/xxmodule.c | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/Modules/xxmodule.c b/Modules/xxmodule.c index 0feff66..85230d9 100644 --- a/Modules/xxmodule.c +++ b/Modules/xxmodule.c @@ -334,26 +334,10 @@ static PyMethodDef xx_methods[] = { PyDoc_STRVAR(module_doc, "This is a template module just for instruction."); -/* Initialization function for the module (*must* be called PyInit_xx) */ - -static struct PyModuleDef xxmodule = { - PyModuleDef_HEAD_INIT, - "xx", - module_doc, - -1, - xx_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit_xx(void) +static int +xx_exec(PyObject *m) { - PyObject *m = NULL; - /* Due to cross platform compiler issues the slots must be filled * here. It's required for portability to Windows without requiring * C++. */ @@ -366,11 +350,6 @@ PyInit_xx(void) if (PyType_Ready(&Xxo_Type) < 0) goto fail; - /* Create the module and add the functions */ - m = PyModule_Create(&xxmodule); - if (m == NULL) - goto fail; - /* Add some symbolic constants to the module */ if (ErrorObject == NULL) { ErrorObject = PyErr_NewException("xx.error", NULL, NULL); @@ -389,8 +368,33 @@ PyInit_xx(void) if (PyType_Ready(&Null_Type) < 0) goto fail; PyModule_AddObject(m, "Null", (PyObject *)&Null_Type); - return m; + return 0; fail: Py_XDECREF(m); - return NULL; + return -1; +} + +static struct PyModuleDef_Slot xx_slots[] = { + {Py_mod_exec, xx_exec}, + {0, NULL}, +}; + +static struct PyModuleDef xxmodule = { + PyModuleDef_HEAD_INIT, + "xx", + module_doc, + 0, + xx_methods, + xx_slots, + NULL, + NULL, + NULL +}; + +/* Export function for the module (*must* be called PyInit_xx) */ + +PyMODINIT_FUNC +PyInit_xx(void) +{ + return PyModuleDef_Init(&xxmodule); } |