diff options
author | Fred Drake <fdrake@acm.org> | 2002-03-12 21:49:44 +0000 |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2002-03-12 21:49:44 +0000 |
commit | fd0d6480e3796c7a56d7acdf65f19e32fe94f7d3 (patch) | |
tree | 96f3f6f0268f092f69b301c1b3a5128d259ac97d /Modules/xxmodule.c | |
parent | 49acfa7de64e270d8de0ad4dcf6e713600a4d582 (diff) | |
download | cpython-fd0d6480e3796c7a56d7acdf65f19e32fe94f7d3.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.c | 10 |
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); } |