mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Change the example code to prefer PyModule_Add*() instead of using the
module dictionary directly. Also, be more careful about not re-initializing globals in the event of re-initialization of a C extension.
This commit is contained in:
parent
193a3f6d37
commit
1de5a722d6
2 changed files with 12 additions and 12 deletions
|
@ -231,7 +231,11 @@ initxx(void)
|
|||
m = Py_InitModule("xx", xx_methods);
|
||||
|
||||
/* Add some symbolic constants to the module */
|
||||
d = PyModule_GetDict(m);
|
||||
ErrorObject = PyErr_NewException("xx.error", NULL, NULL);
|
||||
PyDict_SetItemString(d, "error", ErrorObject);
|
||||
if (ErrorObject == NULL) {
|
||||
ErrorObject = PyErr_NewException("xx.error", NULL, NULL);
|
||||
if (ErrorObject == NULL)
|
||||
return;
|
||||
}
|
||||
Py_INCREF(ErrorObject);
|
||||
PyModule_AddObject(d, "error", ErrorObject);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue