@@ -208,8 +208,8 @@ value must be in a particular range or must satisfy other conditions,
208208:c:data: `PyExc_ValueError ` is appropriate.
209209
210210You can also define a new exception that is unique to your module. For this, you
211- usually declare an object variable in the per- module state and initialize it
212- in your module's :c:data: `Py_mod_exec ` function (:c:func: `!spam_module_exec `)
211+ usually declare an object variable in the module's state and initialize it
212+ in the module's :c:data: `Py_mod_exec ` function (:c:func: `!spam_module_exec `)
213213with an exception object::
214214
215215 typedef struct {
@@ -228,7 +228,7 @@ with an exception object::
228228 if (state->SpamError == NULL) {
229229 return -1;
230230 }
231- if (PyModule_AddObjectRef(module, "error ", state->SpamError) < 0) {
231+ if (PyModule_AddObjectRef(module, "SpamError ", state->SpamError) < 0) {
232232 return -1; // followed by spam_module_free() then Py_CLEAR()
233233 }
234234
@@ -268,7 +268,7 @@ with an exception object::
268268 {0, NULL}
269269 };
270270
271- static struct PyModuleDef spammodule = {
271+ static struct PyModuleDef spam_module = {
272272 .m_base = PyModuleDef_HEAD_INIT,
273273 .m_name = "spam",
274274 .m_size = sizeof(spam_state), // size of per-module state
@@ -281,7 +281,7 @@ with an exception object::
281281 PyMODINIT_FUNC
282282 PyInit_spam(void)
283283 {
284- return PyModuleDef_Init(&spammodule );
284+ return PyModuleDef_Init(&spam_module );
285285 }
286286
287287Note that the Python name for the exception object is :exc: `!spam.error `. The
@@ -402,7 +402,7 @@ The method table must be referenced in the module definition structure::
402402
403403 static struct PyModuleDef spammodule = {
404404 ...
405- .m_methods = SpamMethods ,
405+ .m_methods = spam_methods ,
406406 ...
407407 };
408408
@@ -414,7 +414,7 @@ only non-\ ``static`` item defined in the module file::
414414 PyMODINIT_FUNC
415415 PyInit_spam(void)
416416 {
417- return PyModuleDef_Init(&spammodule );
417+ return PyModuleDef_Init(&spam_module );
418418 }
419419
420420Note that :c:macro: `PyMODINIT_FUNC ` declares the function as ``PyObject * `` return type,
@@ -1328,7 +1328,7 @@ function must take care of initializing the C API pointer array::
13281328 {0, NULL}
13291329 };
13301330
1331- static struct PyModuleDef spammodule = {
1331+ static struct PyModuleDef spam_module = {
13321332 .m_base = PyModuleDef_HEAD_INIT,
13331333 .m_name = "spam",
13341334 .m_size = sizeof(spam_state),
@@ -1338,7 +1338,7 @@ function must take care of initializing the C API pointer array::
13381338 PyMODINIT_FUNC
13391339 PyInit_spam(void)
13401340 {
1341- return PyModuleDef_Init(&spammodule );
1341+ return PyModuleDef_Init(&spam_module );
13421342 }
13431343
13441344The bulk of the work is in the header file :file: `spammodule.h `, which looks
@@ -1407,7 +1407,7 @@ like this::
14071407 {0, NULL}
14081408 };
14091409
1410- static struct PyModuleDef clientmodule = {
1410+ static struct PyModuleDef client_module = {
14111411 .m_base = PyModuleDef_HEAD_INIT,
14121412 .m_name = "client",
14131413 .m_size = sizeof(client_state),
@@ -1417,7 +1417,7 @@ like this::
14171417 PyMODINIT_FUNC
14181418 PyInit_client(void)
14191419 {
1420- return PyModuleDef_Init(&clientmodule );
1420+ return PyModuleDef_Init(&client_module );
14211421 }
14221422
14231423The main disadvantage of this approach is that the file :file: `spammodule.h ` is
0 commit comments