summaryrefslogtreecommitdiff
path: root/Modules/xxmodule.c
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2002-03-12 21:49:44 +0000
committerFred Drake <fdrake@acm.org>2002-03-12 21:49:44 +0000
commit1de5a722d67558d975082789f36156bd5ad5bb88 (patch)
tree8484f416f8ec6ecbcd4ddd969c1f4c0de077439f /Modules/xxmodule.c
parent193a3f6d37c1440b049f7b1c62ff30c1d8cae38a (diff)
downloadcpython-git-1de5a722d67558d975082789f36156bd5ad5bb88.tar.gz
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.
Diffstat (limited to 'Modules/xxmodule.c')
-rw-r--r--Modules/xxmodule.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Modules/xxmodule.c b/Modules/xxmodule.c
index 0ee9f7a8ba..3587c91eeb 100644
--- a/Modules/xxmodule.c
+++ b/Modules/xxmodule.c
@@ -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);
}